/************************************************************************ * * CppSharp * Licensed under the simplified BSD license. All rights reserved. * ************************************************************************/ #using #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "CXXABI.h" #include "Options.h" #include #include typedef std::string String; namespace clang { class TargetCodeGenInfo; namespace CodeGen { class CodeGenTypes; } } #define Debug printf struct Parser { Parser(ParserOptions^ Opts); void SetupHeader(); ParserResult^ ParseHeader(const std::string& File); ParserResult^ ParseLibrary(const std::string& File); ParserResultKind ParseArchive(llvm::StringRef File, llvm::MemoryBuffer *Buffer); ParserResultKind ParseSharedLib(llvm::StringRef File, llvm::MemoryBuffer *Buffer); protected: // AST traversers void WalkAST(); void WalkMacros(clang::PreprocessingRecord* PR); CppSharp::AST::Declaration^ WalkDeclaration(clang::Decl* D, bool IgnoreSystemDecls = true, bool CanBeDefinition = false); CppSharp::AST::Declaration^ WalkDeclarationDef(clang::Decl* D); CppSharp::AST::Enumeration^ WalkEnum(clang::EnumDecl*); CppSharp::AST::Function^ WalkFunction(clang::FunctionDecl*, bool IsDependent = false, bool AddToNamespace = true); CppSharp::AST::Class^ WalkRecordCXX(clang::CXXRecordDecl*); CppSharp::AST::Method^ WalkMethodCXX(clang::CXXMethodDecl*); CppSharp::AST::Field^ WalkFieldCXX(clang::FieldDecl*, CppSharp::AST::Class^); CppSharp::AST::ClassTemplate^ Parser::WalkClassTemplate(clang::ClassTemplateDecl*); CppSharp::AST::FunctionTemplate^ Parser::WalkFunctionTemplate( clang::FunctionTemplateDecl*); CppSharp::AST::Variable^ WalkVariable(clang::VarDecl*); CppSharp::AST::RawComment^ WalkRawComment(const clang::RawComment*); CppSharp::AST::Type^ WalkType(clang::QualType, clang::TypeLoc* = 0, bool DesugarType = false); void WalkVTable(clang::CXXRecordDecl*, CppSharp::AST::Class^); CppSharp::AST::VTableLayout^ WalkVTableLayout(const clang::VTableLayout&); CppSharp::AST::VTableComponent WalkVTableComponent(const clang::VTableComponent&); // Clang helpers SourceLocationKind GetLocationKind(const clang::SourceLocation& Loc); bool IsValidDeclaration(const clang::SourceLocation& Loc); std::string GetDeclMangledName(clang::Decl*, clang::TargetCXXABI, bool IsDependent = false); std::string GetTypeName(const clang::Type*); void WalkFunction(clang::FunctionDecl* FD, CppSharp::AST::Function^ F, bool IsDependent = false); void HandlePreprocessedEntities(CppSharp::AST::Declaration^ Decl, clang::SourceRange sourceRange, CppSharp::AST::MacroLocation macroLocation = CppSharp::AST::MacroLocation::Unknown); bool GetDeclText(clang::SourceRange, std::string& Text); CppSharp::AST::TranslationUnit^ GetTranslationUnit(clang::SourceLocation Loc, SourceLocationKind *Kind = 0); CppSharp::AST::TranslationUnit^ GetTranslationUnit(const clang::Decl*); CppSharp::AST::DeclarationContext^ GetNamespace(clang::Decl*, clang::DeclContext*); CppSharp::AST::DeclarationContext^ GetNamespace(clang::Decl*); void HandleDeclaration(clang::Decl* D, CppSharp::AST::Declaration^); void HandleOriginalText(clang::Decl* D, CppSharp::AST::Declaration^); void HandleComments(clang::Decl* D, CppSharp::AST::Declaration^); void HandleDiagnostics(ParserResult^ res); int Index; gcroot Lib; gcroot Symbols; gcroot Opts; llvm::OwningPtr C; clang::ASTContext* AST; clang::TargetCXXABI::Kind TargetABI; clang::TargetCodeGenInfo* CodeGenInfo; clang::CodeGen::CodeGenTypes* CodeGenTypes; };