/************************************************************************ * * Cxxi * Licensed under the simplified BSD license. All rights reserved. * ************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "CXXABI.h" #include #include #using #include #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) #define Debug printf using namespace System::Collections::Generic; public ref struct ParserOptions { ParserOptions() { IncludeDirs = gcnew List(); Defines = gcnew List(); } // Include directories List^ IncludeDirs; List^ Defines; // C/C++ header file name. System::String^ FileName; Cxxi::Library^ Library; // Toolset version - 2005 - 8, 2008 - 9, 2010 - 10, 0 - autoprobe for any. int ToolSetToUse; bool Verbose; }; public value struct ParserDiagnostic { System::String^ FileName; System::String^ Message; }; public enum struct ParserResultKind { Success, Error, FileNotFound }; public ref struct ParserResult { ParserResult() { Diagnostics = gcnew List(); } ParserResultKind Kind; Cxxi::Library^ Library; List^ Diagnostics; }; struct Parser { Parser(ParserOptions^ Opts); void Setup(ParserOptions^ Opts); ParserResult^ Parse(const std::string& File); protected: // AST traversers void WalkAST(); void WalkMacros(clang::PreprocessingRecord* PR); Cxxi::Declaration^ WalkDeclaration(clang::Decl* D, clang::TypeLoc* = 0, bool IgnoreSystemDecls = true, bool CanBeDefinition = false); Cxxi::Declaration^ WalkDeclarationDef(clang::Decl* D); Cxxi::Enumeration^ WalkEnum(clang::EnumDecl*); Cxxi::Function^ WalkFunction(clang::FunctionDecl*, bool IsDependent = false); Cxxi::Class^ WalkRecordCXX(clang::CXXRecordDecl*, bool IsDependent = false); Cxxi::Method^ WalkMethodCXX(clang::CXXMethodDecl*); Cxxi::Field^ WalkFieldCXX(clang::FieldDecl*, Cxxi::Class^); Cxxi::ClassTemplate^ Parser::WalkClassTemplate(clang::ClassTemplateDecl*); Cxxi::FunctionTemplate^ Parser::WalkFunctionTemplate( clang::FunctionTemplateDecl*); Cxxi::Variable^ WalkVariable(clang::VarDecl*); Cxxi::Type^ WalkType(clang::QualType, clang::TypeLoc* = 0, bool DesugarType = false); // Clang helpers bool IsValidDeclaration(const clang::SourceLocation& Loc); std::string GetDeclMangledName(clang::Decl*, clang::TargetCXXABI, bool IsDependent = false); std::string GetTypeName(const clang::Type*); void HandleComments(clang::Decl* D, Cxxi::Declaration^); void WalkFunction(clang::FunctionDecl* FD, Cxxi::Function^ F, bool IsDependent = false); Cxxi::TranslationUnit^ GetModule(clang::SourceLocation Loc); Cxxi::Namespace^ GetNamespace(const clang::NamedDecl*); int Index; gcroot Lib; llvm::OwningPtr C; clang::ASTContext* AST; }; //-----------------------------------// typedef std::string String; String StringFormatArgs(const char* str, va_list args); String StringFormat(const char* str, ...);