Browse Source

Reworked the C++ parser structures to use some helper macros to ease the bindings.

pull/146/merge
triton 12 years ago
parent
commit
64e75fb0a6
  1. 34
      src/CppParser/AST.h
  2. 33
      src/CppParser/CppParser.h

34
src/CppParser/AST.h

@ -25,6 +25,11 @@
type get##name (unsigned i) { return name[i]; } \ type get##name (unsigned i) { return name[i]; } \
unsigned get##name##Count () { return name.size(); } 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 { namespace CppSharp { namespace CppParser { namespace AST {
// Types // Types
@ -163,7 +168,7 @@ struct CS_API TemplateParameter
return Name == param.Name; return Name == param.Name;
} }
std::string Name; STRING(Name)
}; };
struct CS_API TemplateParameterType : public Type struct CS_API TemplateParameterType : public Type
@ -215,6 +220,7 @@ struct CS_API BuiltinType : public Type
PrimitiveType Type; PrimitiveType Type;
}; };
#if 1
// Comments // Comments
enum struct RawCommentKind enum struct RawCommentKind
@ -234,8 +240,8 @@ struct FullComment;
struct CS_API RawComment struct CS_API RawComment
{ {
RawCommentKind Kind; RawCommentKind Kind;
std::string Text; STRING(Text)
std::string BriefText; STRING(BriefText)
CppSharp::CppParser::AST::FullComment* FullComment; CppSharp::CppParser::AST::FullComment* FullComment;
}; };
@ -320,9 +326,9 @@ struct CS_API Declaration
AccessSpecifier Access; AccessSpecifier Access;
DeclarationContext* _Namespace; DeclarationContext* _Namespace;
std::string Name; STRING(Name)
RawComment* Comment; RawComment* Comment;
std::string DebugText; STRING(DebugText)
bool IsIncomplete; bool IsIncomplete;
bool IsDependent; bool IsDependent;
Declaration* CompleteDeclaration; Declaration* CompleteDeclaration;
@ -457,8 +463,8 @@ struct CS_API Function : public Declaration
bool IsPure; bool IsPure;
bool IsDeleted; bool IsDeleted;
CXXOperatorKind OperatorKind; CXXOperatorKind OperatorKind;
std::string Mangled; STRING(Mangled)
std::string Signature; STRING(Signature)
CppSharp::CppParser::AST::CallingConvention CallingConvention; CppSharp::CppParser::AST::CallingConvention CallingConvention;
VECTOR(Parameter*, Parameters) VECTOR(Parameter*, Parameters)
}; };
@ -488,7 +494,7 @@ struct CS_API Enumeration : public Declaration
{ {
struct CS_API Item : public Declaration struct CS_API Item : public Declaration
{ {
std::string Expression; STRING(Expression)
uint64_t Value; uint64_t Value;
}; };
@ -507,7 +513,7 @@ struct CS_API Enumeration : public Declaration
struct CS_API Variable : public Declaration struct CS_API Variable : public Declaration
{ {
std::string Mangled; STRING(Mangled)
CppSharp::CppParser::AST::QualifiedType QualifiedType; CppSharp::CppParser::AST::QualifiedType QualifiedType;
}; };
@ -588,27 +594,26 @@ struct CS_API PreprocessedEntity : public Declaration
struct CS_API MacroDefinition : public PreprocessedEntity struct CS_API MacroDefinition : public PreprocessedEntity
{ {
std::string Expression; STRING(Expression)
}; };
struct CS_API MacroExpansion : public PreprocessedEntity struct CS_API MacroExpansion : public PreprocessedEntity
{ {
std::string Text; STRING(Text)
MacroDefinition* Definition; MacroDefinition* Definition;
}; };
struct CS_API TranslationUnit : public Namespace struct CS_API TranslationUnit : public Namespace
{ {
std::string FileName; STRING(FileName)
bool IsSystemHeader; bool IsSystemHeader;
VECTOR(Namespace*, Namespaces)
VECTOR(MacroDefinition*, Macros) VECTOR(MacroDefinition*, Macros)
}; };
struct CS_API NativeLibrary struct CS_API NativeLibrary
{ {
std::string FileName; STRING(FileName)
VECTOR(std::string, Symbols) VECTOR(std::string, Symbols)
}; };
@ -617,5 +622,6 @@ struct CS_API ASTContext
TranslationUnit* FindOrCreateModule(const std::string& File); TranslationUnit* FindOrCreateModule(const std::string& File);
VECTOR(TranslationUnit*, TranslationUnits) VECTOR(TranslationUnit*, TranslationUnits)
}; };
#endif
} } } } } }

33
src/CppParser/CppParser.h

@ -11,7 +11,20 @@
#define VECTOR_OPTIONS(type, name) \ #define VECTOR_OPTIONS(type, name) \
std::vector<type> name; \ std::vector<type> 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<std::string> 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 { namespace CppSharp { namespace CppParser {
@ -31,18 +44,18 @@ struct CS_API ParserOptions
} }
// C/C++ header file name. // C/C++ header file name.
std::string FileName; STRING_OPTIONS(FileName)
// Include directories // Include directories
VECTOR_OPTIONS(std::string, IncludeDirs) VECTOR_STRING_OPTIONS(IncludeDirs)
VECTOR_OPTIONS(std::string, SystemIncludeDirs) VECTOR_STRING_OPTIONS(SystemIncludeDirs)
VECTOR_OPTIONS(std::string, Defines) VECTOR_STRING_OPTIONS(Defines)
VECTOR_OPTIONS(std::string, LibraryDirs) VECTOR_STRING_OPTIONS(LibraryDirs)
CppSharp::CppParser::AST::ASTContext* ASTContext; CppSharp::CppParser::AST::ASTContext* ASTContext;
int ToolSetToUse; int ToolSetToUse;
std::string TargetTriple; STRING(TargetTriple)
CppAbi Abi; CppAbi Abi;
bool NoStandardIncludes; bool NoStandardIncludes;
@ -62,8 +75,8 @@ enum struct ParserDiagnosticLevel
struct CS_API ParserDiagnostic struct CS_API ParserDiagnostic
{ {
std::string FileName; STRING(FileName)
std::string Message; STRING(Message)
ParserDiagnosticLevel Level; ParserDiagnosticLevel Level;
int LineNumber; int LineNumber;
int ColumnNumber; int ColumnNumber;
@ -79,7 +92,7 @@ enum struct ParserResultKind
struct CS_API ParserResult struct CS_API ParserResult
{ {
ParserResultKind Kind; ParserResultKind Kind;
std::vector<ParserDiagnostic> Diagnostics; VECTOR_OPTIONS(ParserDiagnostic, Diagnostics)
CppSharp::CppParser::AST::ASTContext* ASTContext; CppSharp::CppParser::AST::ASTContext* ASTContext;
CppSharp::CppParser::AST::NativeLibrary* Library; CppSharp::CppParser::AST::NativeLibrary* Library;

Loading…
Cancel
Save