Browse Source

Changed CppParser to use macros to define the containers.

This way we can also define some helper methods to consume these from C#.
pull/123/head
triton 12 years ago
parent
commit
b3bc8706a0
  1. 52
      src/CppParser/AST.h
  2. 12
      src/CppParser/CppParser.h

52
src/CppParser/AST.h

@ -20,6 +20,11 @@
#define CS_API #define CS_API
#endif #endif
#define VECTOR(type, name) \
std::vector<type> name; \
type get##name(unsigned i) { return name[i]; } \
unsigned get##name##Count() { return name.size(); }
namespace CppSharp { namespace CppParser { namespace AST { namespace CppSharp { namespace CppParser { namespace AST {
// Types // Types
@ -79,8 +84,8 @@ enum class CallingConvention
struct CS_API FunctionType : public Type struct CS_API FunctionType : public Type
{ {
QualifiedType ReturnType; QualifiedType ReturnType;
std::vector<Parameter*> Parameters;
CppSharp::CppParser::AST::CallingConvention CallingConvention; CppSharp::CppParser::AST::CallingConvention CallingConvention;
VECTOR(Parameter*, Parameters)
}; };
struct CS_API PointerType : public Type struct CS_API PointerType : public Type
@ -140,7 +145,7 @@ struct Template;
struct CS_API TemplateSpecializationType : public Type struct CS_API TemplateSpecializationType : public Type
{ {
std::vector<TemplateArgument> Arguments; VECTOR(TemplateArgument, Arguments)
CppSharp::CppParser::AST::Template* Template; CppSharp::CppParser::AST::Template* Template;
Type* Desugared; Type* Desugared;
}; };
@ -246,7 +251,7 @@ struct CS_API VTableComponent
struct CS_API VTableLayout struct CS_API VTableLayout
{ {
std::vector<VTableComponent> Components; VECTOR(VTableComponent, Components)
}; };
struct CS_API VFTableInfo struct CS_API VFTableInfo
@ -267,7 +272,7 @@ enum struct CppAbi
struct CS_API ClassLayout struct CS_API ClassLayout
{ {
CppAbi ABI; CppAbi ABI;
std::vector<VFTableInfo> VFTables; VECTOR(VFTableInfo, VFTables)
VTableLayout Layout; VTableLayout Layout;
bool HasOwnVFPtr; bool HasOwnVFPtr;
long VBPtrOffset; long VBPtrOffset;
@ -311,7 +316,7 @@ struct CS_API Declaration
bool IsDependent; bool IsDependent;
Declaration* CompleteDeclaration; Declaration* CompleteDeclaration;
unsigned DefinitionOrder; unsigned DefinitionOrder;
std::vector<PreprocessedEntity*> PreprocessedEntities; VECTOR(PreprocessedEntity*, PreprocessedEntities)
void* OriginalPtr; void* OriginalPtr;
}; };
@ -342,13 +347,13 @@ struct CS_API DeclarationContext : public Declaration
TypedefDecl* FindTypedef(const std::string& Name, bool Create = false); TypedefDecl* FindTypedef(const std::string& Name, bool Create = false);
std::vector<CppSharp::CppParser::AST::Namespace*> Namespaces; VECTOR(Namespace*, Namespaces)
std::vector<Enumeration*> Enums; VECTOR(Enumeration*, Enums)
std::vector<Function*> Functions; VECTOR(Function*, Functions)
std::vector<Class*> Classes; VECTOR(Class*, Classes)
std::vector<Template*> Templates; VECTOR(Template*, Templates)
std::vector<TypedefDecl*> Typedefs; VECTOR(TypedefDecl*, Typedefs)
std::vector<Variable*> Variables; VECTOR(Variable*, Variables)
std::map<uint64_t, Declaration*> Anonymous; std::map<uint64_t, Declaration*> Anonymous;
}; };
@ -439,7 +444,7 @@ struct CS_API Function : public Declaration
std::string Mangled; std::string Mangled;
std::string Signature; std::string Signature;
CppSharp::CppParser::AST::CallingConvention CallingConvention; CppSharp::CppParser::AST::CallingConvention CallingConvention;
std::vector<Parameter*> Parameters; VECTOR(Parameter*, Parameters)
}; };
struct AccessSpecifierDecl; struct AccessSpecifierDecl;
@ -467,7 +472,6 @@ struct CS_API Enumeration : public Declaration
{ {
struct CS_API Item : public Declaration struct CS_API Item : public Declaration
{ {
std::string Name;
std::string Expression; std::string Expression;
std::string Comment; std::string Comment;
uint64_t Value; uint64_t Value;
@ -483,7 +487,7 @@ struct CS_API Enumeration : public Declaration
EnumModifiers Modifiers; EnumModifiers Modifiers;
CppSharp::CppParser::AST::Type* Type; CppSharp::CppParser::AST::Type* Type;
CppSharp::CppParser::AST::BuiltinType* BuiltinType; CppSharp::CppParser::AST::BuiltinType* BuiltinType;
std::vector<Item> Items; VECTOR(Item, Items)
}; };
struct CS_API Variable : public Declaration struct CS_API Variable : public Declaration
@ -517,10 +521,10 @@ struct CS_API AccessSpecifierDecl : public Declaration
struct CS_API Class : public DeclarationContext struct CS_API Class : public DeclarationContext
{ {
std::vector<BaseClassSpecifier*> Bases; VECTOR(BaseClassSpecifier*, Bases)
std::vector<Field*> Fields; VECTOR(Field*, Fields)
std::vector<Method*> Methods; VECTOR(Method*, Methods)
std::vector<AccessSpecifierDecl*> Specifiers; VECTOR(AccessSpecifierDecl*, Specifiers)
bool IsPOD; bool IsPOD;
bool IsAbstract; bool IsAbstract;
@ -536,7 +540,7 @@ struct CS_API Class : public DeclarationContext
struct CS_API Template : public Declaration struct CS_API Template : public Declaration
{ {
Declaration* TemplatedDecl; Declaration* TemplatedDecl;
std::vector<TemplateParameter> Parameters; VECTOR(TemplateParameter, Parameters)
}; };
struct CS_API ClassTemplate : public Template struct CS_API ClassTemplate : public Template
@ -583,20 +587,20 @@ struct CS_API TranslationUnit : public Namespace
{ {
std::string FileName; std::string FileName;
bool IsSystemHeader; bool IsSystemHeader;
std::vector<Namespace*> Namespaces; VECTOR(Namespace*, Namespaces)
std::vector<MacroDefinition*> Macros; VECTOR(MacroDefinition*, Macros)
}; };
struct CS_API NativeLibrary struct CS_API NativeLibrary
{ {
std::string FileName; std::string FileName;
std::vector<std::string> Symbols; VECTOR(std::string, Symbols)
}; };
struct CS_API ASTContext struct CS_API ASTContext
{ {
TranslationUnit* FindOrCreateModule(const std::string& File); TranslationUnit* FindOrCreateModule(const std::string& File);
std::vector<TranslationUnit*> TranslationUnits; VECTOR(TranslationUnit*, TranslationUnits)
}; };
} } } } } }

12
src/CppParser/CppParser.h

@ -9,6 +9,10 @@
#include "AST.h" #include "AST.h"
#define VECTOR_OPTIONS(type, name) \
std::vector<type> name; \
void push##name##(const type& elem) { name.push_back(elem); }
namespace CppSharp { namespace CppParser { namespace CppSharp { namespace CppParser {
using namespace CppSharp::CppParser::AST; using namespace CppSharp::CppParser::AST;
@ -30,10 +34,10 @@ struct CS_API ParserOptions
std::string FileName; std::string FileName;
// Include directories // Include directories
std::vector<std::string> IncludeDirs; VECTOR_OPTIONS(std::string, IncludeDirs)
std::vector<std::string> SystemIncludeDirs; VECTOR_OPTIONS(std::string, SystemIncludeDirs)
std::vector<std::string> Defines; VECTOR_OPTIONS(std::string, Defines)
std::vector<std::string> LibraryDirs; VECTOR_OPTIONS(std::string, LibraryDirs)
CppSharp::CppParser::AST::ASTContext* ASTContext; CppSharp::CppParser::AST::ASTContext* ASTContext;

Loading…
Cancel
Save