16 #include "cableClass.h"
17 #include "cableClassType.h"
18 #include "cableConstructor.h"
19 #include "cableFunctionType.h"
20 #include "cableNamed.h"
21 #include "cablePointerType.h"
22 #include "cableReferenceType.h"
23 #include "cableType.h"
24 #include "cableTypedef.h"
26 #include "cxxFundamentalType.h"
28 #include "gxsys/RegularExpression.hxx"
29 #include "gxsys/SystemTools.hxx"
30 #include "gxsys/ios/fstream"
31 #include "gxsys/ios/sstream"
32 #include "gxsys/stl/map"
53 void Emit(gxsys_ios::ostream &os,
const char *s)
61 void EmitInt(gxsys_ios::ostream &os,
const int i)
68 void EmitUint(gxsys_ios::ostream &os,
const unsigned int i)
75 void EmitIndent(gxsys_ios::ostream &os,
const unsigned int n)
89 void EmitFile(gxsys_ios::ostream &os,
const char *filename)
91 gxsys_ios::ifstream file(filename);
98 file.getline(line, 4099);
99 os << line << gxsys_ios::endl;
108 gxsys_ios::ofstream file;
109 file.open(filename, gxsys_ios::ios_base::out | gxsys_ios::ios_base::trunc);
129 if (cable::Type::FundamentalTypeId == t->GetTypeId())
131 const cxx::FundamentalType *cxxft = cxx::FundamentalType::SafeDownCast(
132 t->GetCxxType().GetType());
136 return tid == cxxft->GetId();
147 return cable::Type::ClassTypeId == t->GetTypeId();
163 return HasAttribute(cable::ClassType::SafeDownCast(t)->GetClass(),
164 "gccxml(iwhMapToType");
167 if ((cable::Type::ReferenceTypeId == t->GetTypeId()) &&
168 IsObject(cable::ReferenceType::SafeDownCast(t)->GetTarget()))
171 cable::ReferenceType::SafeDownCast(t)->GetTarget())->GetClass(),
172 "gccxml(iwhMapToType");
188 else if ((cable::Type::ReferenceTypeId == t->GetTypeId()) &&
189 IsObject(cable::ReferenceType::SafeDownCast(t)->GetTarget()))
192 cable::ReferenceType::SafeDownCast(t)->GetTarget())->GetClass());
208 else if ((cable::Type::ReferenceTypeId == t->GetTypeId()) &&
209 IsObject(cable::ReferenceType::SafeDownCast(t)->GetTarget()))
212 cable::ReferenceType::SafeDownCast(t)->GetTarget())->GetClass());
236 if (cable::Type::PointerTypeId == t->GetTypeId())
238 return IsFundamental(cable::PointerType::SafeDownCast(t)->GetTarget(), tid);
248 if (cable::Type::PointerTypeId == t->GetTypeId())
260 if (cable::Type::PointerTypeId == t->GetTypeId())
262 return IsObject(cable::PointerType::SafeDownCast(t)->GetTarget());
272 if (cable::Type::ReferenceTypeId == t->GetTypeId())
274 return IsObjectPointer(cable::ReferenceType::SafeDownCast(t)->GetTarget());
291 if (cable::Context::Public == access)
294 if (cable::Context::Protected == access)
297 if (cable::Context::Private == access)
301 return "ERROR_invalid_input_to_GetAccessString";
308 const cable::Class *parent = 0;
312 gxsys_stl::vector<cable::Class *> bases;
313 size_t basecount = 0;
314 gxsys_stl::vector<cable::Class *>::iterator it;
316 c->GetBaseClasses(bases);
317 basecount = bases.size();
322 else if (1 == basecount)
324 parent = *bases.begin();
330 <<
"GetParentClass returning 0 because there is more than one base for class '"
331 << c->GetName() <<
"'"
341 bool ClassIsA(
const cable::Class *c,
const gxsys_stl::string& parent)
344 const cable::Class *cIt = c;
346 while (!isa && cIt != NULL)
365 bool validated =
false;
366 gxsys_stl::vector<cable::Class *> bases;
367 size_t basecount = 0;
368 gxsys_stl::vector<cable::Class *>::iterator it;
370 c->GetBaseClasses(bases);
371 basecount = bases.size();
377 else if (1 == basecount)
386 <<
"ValidateBaseClasses returning false because there is more than one base for class '"
387 << c->GetName() <<
"'"
406 s =
"ERROR_invalid_input_to_GetSimpleName";
419 if (n && sep && n->GetContext())
442 s =
"ERROR_invalid_input_to_GetFullyQualifiedName";
455 if (n && sep && n->GetContext())
470 gxsys_ios::ostringstream oss;
471 oss << strlen(n->GetName());
482 s =
"ERROR_invalid_input_to_GetFullyQualifiedLengthPrefixedName";
507 gxsys_stl::string s(
"ERROR_unknown_compiler_in_GetFullyQualifiedCPlusPlusTypeIdName");
509 #if defined(_MSC_VER)
512 #elif defined(__GNUC__)
528 for (cable::Context::Iterator it = c->Begin(); it != c->End() && s ==
""; ++it)
530 cable::Typedef *td = cable::Typedef::SafeDownCast(*it);
532 if (td && (cable::Context::Public == it.GetAccess()))
534 gxsys_stl::string tname(td->GetName());
536 cable::PointerType *pt = cable::PointerType::SafeDownCast(td->GetType());
537 cable::FunctionType *ft = 0;
540 ft = cable::FunctionType::SafeDownCast(pt->GetTarget());
543 if (ft && ft == target)
557 gxsys_stl::string atts(o->GetAttributes());
560 if (gxsys_stl::string::npos != atts.find(attr))
578 gxsys_stl::string
ExtractAttribute(
const gxsys_stl::string& atts,
const gxsys_stl::string& attBase)
580 gxsys_stl::string extracted;
583 if (gxsys_stl::string::npos != atts.find(gxsys_stl::string(
"gccxml(") + attBase))
590 gxsys::RegularExpression re;
591 re.compile((gxsys_stl::string(
"(gccxml\\(")+attBase+
")([^\\)]*)(\\))").c_str());
592 if (re.find(atts.c_str()))
594 extracted = re.match(2);
603 gxsys_stl::string
ExtractAttribute(
const cable::SourceObject *o,
const gxsys_stl::string& attBase)
605 gxsys_stl::string atts(o->GetAttributes());
643 if (typeName ==
"string")
701 void LogMsg(
const gxsys_stl::string&,
const unsigned long,
const gxsys_stl::string& label,
const int n)
703 if (label ==
"error")
711 gxsys_ios::cerr <<
"error: 'error' LogMsg n value should be non-zero...";
754 const cable::Constructor* ctor = 0;
756 if (!c->GetAbstract())
758 for (cable::Context::Iterator it = c->Begin(); 0 == ctor && it != c->End(); ++it)
760 cable::Constructor *ctorCandidate = cable::Constructor::SafeDownCast(*it);
763 cable::Context::Public == it.GetAccess() &&
764 0 == ctorCandidate->GetFunctionType()->GetNumberOfRequiredArguments())
766 ctor = ctorCandidate;
781 switch (t->GetTypeId())
783 case cable::Type::ClassTypeId:
787 case cable::Type::EnumerationTypeId:
791 case cable::Type::FundamentalTypeId:
792 case cable::Type::PointerTypeId:
797 s =
"error: unhandled cable::Type in GetCPlusPlusZeroInitializerExpression";
811 switch (t->GetTypeId())
813 case cable::Type::ClassTypeId:
817 case cable::Type::EnumerationTypeId:
821 case cable::Type::FundamentalTypeId:
822 case cable::Type::PointerTypeId:
827 s =
"error: unhandled cable::Type in GetCsharpZeroInitializerExpression";
837 bool BlockContains(
const gxsys_stl::vector<gxsys_stl::string>& block,
const char *value)
839 gxsys_stl::vector<gxsys_stl::string>::const_iterator blockIt;
841 for (blockIt = block.begin(); blockIt!=block.end(); ++blockIt)
843 if (strstr(blockIt->c_str(), value))
856 gxsys::RegularExpression re;
857 re.compile(
"//[\\t ]*Description:[\\t ]*");
858 if (re.find(comment))
870 gxsys_stl::string encoded;
875 size_t n = strlen(s);
881 case '&' : encoded.append(
"&");
break;
882 case '\'' : encoded.append(
"'");
break;
883 case '>' : encoded.append(
">");
break;
884 case '<' : encoded.append(
"<");
break;
885 case '"' : encoded.append(
""");
break;
887 default : encoded += s[i];
break;
923 void EmitDocumentationBlock(gxsys_ios::ostream &os,
const gxsys_stl::vector<gxsys_stl::string>& block,
const unsigned int indent,
bool isClassDoc)
928 gxsys::String indentString =
"";
929 for (
unsigned int i= 0; i<indent; ++i)
934 gxsys::String xmlTag =
"summary";
936 gxsys_stl::map<gxsys_stl::string, gxsys_stl::string> tagBody;
938 gxsys_stl::vector<gxsys_stl::string>::const_iterator blockIt;
939 gxsys_stl::string line;
945 gxsys::RegularExpression descRE;
946 descRE.compile(gxsys_stl::string(
"Description:").c_str());
947 gxsys::RegularExpression nameRE;
948 nameRE.compile(gxsys_stl::string(
"\\.NAME").c_str());
949 gxsys::RegularExpression seeRE;
950 seeRE.compile(gxsys_stl::string(
"\\.SECTION[\\t ]+[Ss][Ee][Ee][\\t ]+[Aa][Ll][Ss][Oo]").c_str());
951 gxsys::RegularExpression secRE;
952 secRE.compile(gxsys_stl::string(
"\\.SECTION").c_str());
953 gxsys::RegularExpression noSpaceRE;
954 noSpaceRE.compile(gxsys_stl::string(
"[^ ]+").c_str());
956 for (blockIt = block.begin(); blockIt!=block.end(); ++blockIt)
960 if (isClassDoc && !isXmlBlock)
963 if (nameRE.find(line))
965 gxsys::SystemTools::ReplaceString(line,nameRE.match(0).c_str(),
"");
969 else if (seeRE.find(line))
971 gxsys::SystemTools::ReplaceString(line,seeRE.match(0).c_str(),
"");
975 else if (secRE.find(line))
977 gxsys::SystemTools::ReplaceString(line,secRE.match(0).c_str(),
"");
981 else if (descRE.find(line))
983 gxsys::SystemTools::ReplaceString(line,descRE.match(0).c_str(),
"");
994 if (gxsys::SystemTools::StringStartsWith(line.c_str(),
"///"))
996 Emit(os, line.c_str());
998 else if (gxsys::SystemTools::StringStartsWith(line.c_str(),
"//"))
1001 Emit(os, line.c_str());
1006 Emit(os, line.c_str());
1015 gxsys::SystemTools::ReplaceString(line,
"\\code",
"<code>");
1016 gxsys::SystemTools::ReplaceString(line,
"\\endcode",
"</code>");
1018 if (gxsys::SystemTools::StringStartsWith(line.c_str(),
"///"))
1020 tagBody[xmlTag]+=indentString+line+
"\n";
1022 else if (gxsys::SystemTools::StringStartsWith(line.c_str(),
"//"))
1024 tagBody[xmlTag]+=indentString+
"/"+line+
"\n";
1028 tagBody[xmlTag]+=indentString+
"///"+line+
"\n";
1034 if(tagBody[
"summary"] !=
"")
1036 gxsys::String beginTag = indentString+
"/// <summary>\n";
1037 gxsys::String endTag = indentString+
"/// </summary>\n";
1038 Emit(os,beginTag.c_str());
1039 Emit(os,(tagBody[
"summary"]).c_str());
1040 Emit(os,endTag.c_str());
1043 if(tagBody[
"remarks"] !=
"")
1045 gxsys::String beginTag = indentString+
"/// <remarks>\n";
1046 gxsys::String endTag = indentString+
"/// </remarks>\n";
1047 Emit(os,beginTag.c_str());
1048 Emit(os,(tagBody[
"remarks"]).c_str());
1049 Emit(os,endTag.c_str());
1052 if(tagBody[
"seealso"] !=
"")
1054 gxsys::String beginTag = indentString+
"/// <seealso>\n";
1055 gxsys::String endTag = indentString+
"/// </seealso>\n";
1056 Emit(os, beginTag.c_str());
1057 Emit(os, tagBody[
"seealso"].c_str());
1058 Emit(os, endTag.c_str());
1066 gxsys_stl::string name;
1067 gxsys_stl::string derivedName;
1068 gxsys_stl::string c1to2;
1069 gxsys_stl::string c1to3;
1076 if (s && strlen(s)>2)
1078 c1to2 = name.substr(0, 2);
1081 if (s && strlen(s)>3)
1083 c1to3 = name.substr(0, 3);
1086 if ((c1to3 ==
"Get") || (c1to3 ==
"get"))
1088 derivedName = name.substr(3);
1090 else if ((c1to3 ==
"Set") || (c1to3 ==
"set"))
1092 derivedName = name.substr(3);
1094 else if (c1to2 ==
"m_")
1096 derivedName = name.substr(2);
1105 "ExtractDerivedName could not extract derivedName from name: "
1106 << name <<
". Using name as-is...");
bool IsChar(const cable::Type *t)
bool ShouldEmitComment(const char *comment)
bool ShouldLogMsg(const int n)
bool IsCharPointerPointer(const cable::Type *t)
void Emit(gxsys_ios::ostream &os, const char *s)
bool IsCharPointer(const cable::Type *t)
gxsys_stl::string GetFullyQualifiedLengthPrefixedName(const cable::Named *n, const char *sep)
void EmitIndent(gxsys_ios::ostream &os, const unsigned int n)
gxsys_stl::string GetMapToType(const cable::Type *t)
const cable::Class * GetParentClass(const cable::Class *c)
void EmitUint(gxsys_ios::ostream &os, const unsigned int i)
gxsys_stl::string GetMappedTypeName(const cable::Class *c, bool fullyQualified)
void SuppressMsg(const int n)
bool ClassIsA(const cable::Class *c, const gxsys_stl::string &parent)
gxsys_stl::string GetCsharpZeroInitializerExpression(const cable::Type *t)
bool IsObject(const cable::Type *t)
bool EquivalentTypedefNameExists(const cable::Class *c, const cable::FunctionType *target, gxsys_stl::string &s)
bool IsFundamentalPointerPointer(const cable::Type *t, cxx::FundamentalType::Id tid)
bool HasAttribute(const cable::SourceObject *o, const char *attr)
bool HasMapToType(const cable::Type *t)
gxsys_stl::string GetStringMethod(const cable::Type *t)
bool IsObjectPointerReference(const cable::Type *t)
gxsys_stl::string GetFullyQualifiedNameForCPlusPlus(const cable::Named *n)
gxsys_stl::string GetCPlusPlusZeroInitializerExpression(const cable::Type *t)
gxsys_stl::string GetFullyQualifiedNameForCSharp(const cable::Named *n)
int GetMostRecentErrorValue()
bool BlockContains(const gxsys_stl::vector< gxsys_stl::string > &block, const char *value)
bool IsUtilityClass(const cable::Class *c)
bool IsVoid(const cable::Type *t)
gxsys_stl::string GetFullyQualifiedName(const cable::Named *n, const char *sep)
bool IsObjectPointer(const cable::Type *t)
const char * GetAccessString(cable::Context::Access access)
void LogMsg(const gxsys_stl::string &, const unsigned long, const gxsys_stl::string &label, const int n)
gxsys_stl::string ExtractMapToType(const cable::SourceObject *o)
static gxsys_stl::map< int, int > suppressed_msg_values
gxsys_stl::string ExtractArraySize(const gxsys_stl::string &atts)
gxsys_stl::string ExtractAttribute(const gxsys_stl::string &atts, const gxsys_stl::string &attBase)
gxsys_stl::string ExtractStringMethod(const cable::SourceObject *o)
gxsys_stl::string GetSimpleName(const cable::Named *n)
int GetNthErrorValue(int n)
gxsys_stl::string GetFullyQualifiedCPlusPlusTypeIdName(const cable::Named *n)
gxsys_stl::string GetWrappedClassName(const cable::Class *c)
gxsys_stl::string ExtractDerivedName(const char *s, const cable::Named *n, bool verbose)
#define LogFileLineInfoMsg(file, line, n, m)
void EmitFile(gxsys_ios::ostream &os, const char *filename)
const cable::Constructor * FindNonAbstractPublicDefaultConstructor(const cable::Class *c)
gxsys_stl::string ExtractImplementsInterface(const gxsys_stl::string &atts)
gxsys_stl::string EncodeStringForXml(const char *s)
void EmitDocumentationBlock(gxsys_ios::ostream &os, const gxsys_stl::vector< gxsys_stl::string > &block, const unsigned int indent, bool isClassDoc)
void WriteToFile(const char *filename, const char *s)
bool IsFundamental(const cable::Type *t, cxx::FundamentalType::Id tid)
bool ValidateBaseClasses(const cable::Class *c)
bool IsFundamentalPointer(const cable::Type *t, cxx::FundamentalType::Id tid)
bool IsVoidPointer(const cable::Type *t)
gxsys_stl::string GetWrappedClassNameFullyQualified(const cable::Class *c)
void Trace(const char *s)
static gxsys_stl::vector< int > error_values
void EmitInt(gxsys_ios::ostream &os, const int i)