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 @@ @@ -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 @@ -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 @@ -215,6 +220,7 @@ struct CS_API BuiltinType : public Type
PrimitiveType Type;
};
#if 1
// Comments
enum struct RawCommentKind
@ -234,8 +240,8 @@ struct FullComment; @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -617,5 +622,6 @@ struct CS_API ASTContext
TranslationUnit* FindOrCreateModule(const std::string& File);
VECTOR(TranslationUnit*, TranslationUnits)
};
#endif
} } }

33
src/CppParser/CppParser.h

@ -11,7 +11,20 @@ @@ -11,7 +11,20 @@
#define VECTOR_OPTIONS(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 {
@ -31,18 +44,18 @@ struct CS_API ParserOptions @@ -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 @@ -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 @@ -79,7 +92,7 @@ enum struct ParserResultKind
struct CS_API ParserResult
{
ParserResultKind Kind;
std::vector<ParserDiagnostic> Diagnostics;
VECTOR_OPTIONS(ParserDiagnostic, Diagnostics)
CppSharp::CppParser::AST::ASTContext* ASTContext;
CppSharp::CppParser::AST::NativeLibrary* Library;

Loading…
Cancel
Save