From 64e75fb0a62347af18f52b49de9251458d7b5b59 Mon Sep 17 00:00:00 2001 From: triton Date: Tue, 31 Dec 2013 18:35:45 +0000 Subject: [PATCH] Reworked the C++ parser structures to use some helper macros to ease the bindings. --- src/CppParser/AST.h | 34 ++++++++++++++++++++-------------- src/CppParser/CppParser.h | 33 +++++++++++++++++++++++---------- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/src/CppParser/AST.h b/src/CppParser/AST.h index f4272f95..f0ed4d07 100644 --- a/src/CppParser/AST.h +++ b/src/CppParser/AST.h @@ -25,6 +25,11 @@ type get##name (unsigned i) { return name[i]; } \ unsigned get##name##Count () { return name.size(); } +#define STRING(name) \ + std::string name; \ + const char* get##name() { return name.c_str(); } \ + void set##name(const char* s) { name = s; } + namespace CppSharp { namespace CppParser { namespace AST { // Types @@ -163,7 +168,7 @@ struct CS_API TemplateParameter return Name == param.Name; } - std::string Name; + STRING(Name) }; struct CS_API TemplateParameterType : public Type @@ -215,6 +220,7 @@ struct CS_API BuiltinType : public Type PrimitiveType Type; }; +#if 1 // Comments enum struct RawCommentKind @@ -234,8 +240,8 @@ struct FullComment; struct CS_API RawComment { RawCommentKind Kind; - std::string Text; - std::string BriefText; + STRING(Text) + STRING(BriefText) CppSharp::CppParser::AST::FullComment* FullComment; }; @@ -320,9 +326,9 @@ struct CS_API Declaration AccessSpecifier Access; DeclarationContext* _Namespace; - std::string Name; + STRING(Name) RawComment* Comment; - std::string DebugText; + STRING(DebugText) bool IsIncomplete; bool IsDependent; Declaration* CompleteDeclaration; @@ -457,8 +463,8 @@ struct CS_API Function : public Declaration bool IsPure; bool IsDeleted; CXXOperatorKind OperatorKind; - std::string Mangled; - std::string Signature; + STRING(Mangled) + STRING(Signature) CppSharp::CppParser::AST::CallingConvention CallingConvention; VECTOR(Parameter*, Parameters) }; @@ -488,7 +494,7 @@ struct CS_API Enumeration : public Declaration { struct CS_API Item : public Declaration { - std::string Expression; + STRING(Expression) uint64_t Value; }; @@ -507,7 +513,7 @@ struct CS_API Enumeration : public Declaration struct CS_API Variable : public Declaration { - std::string Mangled; + STRING(Mangled) CppSharp::CppParser::AST::QualifiedType QualifiedType; }; @@ -588,27 +594,26 @@ struct CS_API PreprocessedEntity : public Declaration struct CS_API MacroDefinition : public PreprocessedEntity { - std::string Expression; + STRING(Expression) }; struct CS_API MacroExpansion : public PreprocessedEntity { - std::string Text; + STRING(Text) MacroDefinition* Definition; }; struct CS_API TranslationUnit : public Namespace { - std::string FileName; + STRING(FileName) bool IsSystemHeader; - VECTOR(Namespace*, Namespaces) VECTOR(MacroDefinition*, Macros) }; struct CS_API NativeLibrary { - std::string FileName; + STRING(FileName) VECTOR(std::string, Symbols) }; @@ -617,5 +622,6 @@ struct CS_API ASTContext TranslationUnit* FindOrCreateModule(const std::string& File); VECTOR(TranslationUnit*, TranslationUnits) }; +#endif } } } \ No newline at end of file diff --git a/src/CppParser/CppParser.h b/src/CppParser/CppParser.h index ee4d9ccc..45d79a32 100644 --- a/src/CppParser/CppParser.h +++ b/src/CppParser/CppParser.h @@ -11,7 +11,20 @@ #define VECTOR_OPTIONS(type, name) \ std::vector name; \ - void push##name(const type& elem) { name.push_back(elem); } + type get##name (unsigned i) { return name[i]; } \ + void add##name (const type& s) { return name.push_back(s); } \ + unsigned get##name##Count () { return name.size(); } + +#define VECTOR_STRING_OPTIONS(name) \ + std::vector name; \ + const char* get##name (unsigned i) { return name[i].c_str(); } \ + void add##name (const char* s) { return name.push_back(std::string(s)); } \ + unsigned get##name##Count () { return name.size(); } + +#define STRING_OPTIONS(name) \ + std::string name; \ + const char* get##name() { return name.c_str(); } \ + void set##name(const char* s) { name = s; } namespace CppSharp { namespace CppParser { @@ -31,18 +44,18 @@ struct CS_API ParserOptions } // C/C++ header file name. - std::string FileName; + STRING_OPTIONS(FileName) // Include directories - VECTOR_OPTIONS(std::string, IncludeDirs) - VECTOR_OPTIONS(std::string, SystemIncludeDirs) - VECTOR_OPTIONS(std::string, Defines) - VECTOR_OPTIONS(std::string, LibraryDirs) + VECTOR_STRING_OPTIONS(IncludeDirs) + VECTOR_STRING_OPTIONS(SystemIncludeDirs) + VECTOR_STRING_OPTIONS(Defines) + VECTOR_STRING_OPTIONS(LibraryDirs) CppSharp::CppParser::AST::ASTContext* ASTContext; int ToolSetToUse; - std::string TargetTriple; + STRING(TargetTriple) CppAbi Abi; bool NoStandardIncludes; @@ -62,8 +75,8 @@ enum struct ParserDiagnosticLevel struct CS_API ParserDiagnostic { - std::string FileName; - std::string Message; + STRING(FileName) + STRING(Message) ParserDiagnosticLevel Level; int LineNumber; int ColumnNumber; @@ -79,7 +92,7 @@ enum struct ParserResultKind struct CS_API ParserResult { ParserResultKind Kind; - std::vector Diagnostics; + VECTOR_OPTIONS(ParserDiagnostic, Diagnostics) CppSharp::CppParser::AST::ASTContext* ASTContext; CppSharp::CppParser::AST::NativeLibrary* Library;