From be63ae35e36635f2c7d07eb77cbb5de763225790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Fri, 17 Feb 2023 11:56:43 +0000 Subject: [PATCH 01/68] Adds deps package for llvm14 --- deps/Findllvm14.cmake | 207 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 deps/Findllvm14.cmake diff --git a/deps/Findllvm14.cmake b/deps/Findllvm14.cmake new file mode 100644 index 000000000..0213aad29 --- /dev/null +++ b/deps/Findllvm14.cmake @@ -0,0 +1,207 @@ +cmake_minimum_required(VERSION 3.2) + +# Download library +deps_resolve("llvm14" LIB_DIR) + +# Expose LLVM library +set("llvm14_DIR" ${LIB_DIR}) + +# LLVM requires C++11 +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + +if(UNIX) + # Unix version uses pre-build clang binaries, which disable rtti + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -fno-rtti") +endif() + + +#LLVM and Clang includes +list(APPEND llvm14_INCLUDES + "${LIB_DIR}/src/include" + "${LIB_DIR}/build/include" +) + + +# LLVM + Clang libs +# Using link_directories because of circular dependencies in Clang libraries. +# Ideally we would use 'find_libraries' +LINK_DIRECTORIES("${LIB_DIR}/build/lib") + +set(LINKER_GROUP_START "-Wl,--start-group") +set(LINKER_GROUP_END "-Wl,--end-group") + +if(APPLE) + # Apple Clang linker does not understand groups + unset(LINKER_GROUP_START) + unset(LINKER_GROUP_END) +endif() + +#message("SYSTEM PROCESSOR: '${CMAKE_SYSTEM_PROCESSOR}'") +if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm") + set(PROCESSOR_PREFIX "ARM") +else() + set(PROCESSOR_PREFIX "X86") +endif() + + + +#find_libraries(llvm14_LIBRARIES "${LIB_DIR}/build/lib" +list(APPEND llvm14_LIBRARIES + + # Clang libraries, they have circular dependencies, so they are inside a group + ${LINKER_GROUP_START} + clangAnalysis + clangAPINotes + clangARCMigrate + clangAST + clangASTMatchers + clangBasic + #clangChangeNamespace + clangCodeGen + clangCrossTU + clangDependencyScanning + clangDirectoryWatcher + #clangDoc + clangDriver + clangDynamicASTMatchers + clangEdit + clangFormat + clangFrontend + clangFrontendTool + clangHandleCXX + clangHandleLLVM + clangIndex + clangIndexSerialization + clangLex + #clangMove + clangParse + #clangReorderFields + clangRewrite + clangRewriteFrontend + clangSema + clangSerialization + clangStaticAnalyzerCheckers + clangStaticAnalyzerCore + clangStaticAnalyzerFrontend + clangTooling + clangToolingASTDiff + clangToolingCore + clangToolingInclusions + clangToolingRefactoring + clangToolingSyntax + clangTransformer + #DynamicLibraryLib + ${LINKER_GROUP_END} + + # LLVM libraries, as given by 'llvm-config --libs' + LLVMWindowsManifest + LLVMXRay + LLVMLibDriver + LLVMDlltoolDriver + LLVMCoverage + LLVMLineEditor + LLVMXCoreDisassembler + LLVMXCoreCodeGen + LLVMXCoreDesc + LLVMXCoreInfo + LLVM${PROCESSOR_PREFIX}Disassembler + LLVM${PROCESSOR_PREFIX}AsmParser + LLVM${PROCESSOR_PREFIX}CodeGen + LLVM${PROCESSOR_PREFIX}Desc + LLVM${PROCESSOR_PREFIX}Info + LLVMARMUtils + LLVMAArch64Utils + LLVMOrcJIT + LLVMMCJIT + LLVMJITLink + LLVMOrcTargetProcess + LLVMOrcShared + LLVMInterpreter + LLVMExecutionEngine + LLVMRuntimeDyld + LLVMSymbolize + LLVMDebugInfoPDB + LLVMDebugInfoGSYM + LLVMOption + LLVMObjectYAML + LLVMMCA + LLVMMCDisassembler + LLVMLTO + LLVMPasses + LLVMCFGuard + LLVMCoroutines + LLVMObjCARCOpts + LLVMHelloNew + LLVMipo + LLVMVectorize + LLVMLinker + LLVMInstrumentation + LLVMFrontendOpenMP + LLVMFrontendOpenACC + LLVMExtensions + LLVMDWARFLinker + LLVMGlobalISel + LLVMMIRParser + LLVMAsmPrinter + LLVMDebugInfoDWARF + LLVMSelectionDAG + LLVMCodeGen + LLVMIRReader + LLVMAsmParser + LLVMInterfaceStub + LLVMFileCheck + LLVMFuzzMutate + LLVMTarget + LLVMScalarOpts + LLVMInstCombine + LLVMAggressiveInstCombine + LLVMTransformUtils + LLVMBitWriter + LLVMAnalysis + LLVMProfileData + LLVMObject + LLVMTextAPI + LLVMMCParser + LLVMMC + LLVMDebugInfoCodeView + LLVMDebugInfoMSF + LLVMBitReader + LLVMCore + LLVMRemarks + LLVMBitstreamReader + LLVMBinaryFormat + LLVMTableGen + LLVMSupport + LLVMDemangle +) + + + + +if(UNIX AND NOT APPLE) + # Generic UNIX dependencies + list(APPEND llvm14_LIBRARIES + rt + tinfo + z + m + dl + ) +elseif(APPLE) + # macOS dependencies + list(APPEND llvm14_LIBRARIES + c++abi + #stdc++ + z + m + dl + ncurses + ) +elseif(WIN32) + # Windows dependencies + list(APPEND llvm14_LIBRARIES + version + z + ) +endif() + From ce33270d1f8cffa9d8217768d77a6fda1878cae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Fri, 17 Feb 2023 12:00:02 +0000 Subject: [PATCH 02/68] [ClangAstDumper] Updates LLVM library from 12 to 14 --- ClangAstDumper/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ClangAstDumper/CMakeLists.txt b/ClangAstDumper/CMakeLists.txt index ac536c46e..fabae8656 100644 --- a/ClangAstDumper/CMakeLists.txt +++ b/ClangAstDumper/CMakeLists.txt @@ -14,7 +14,8 @@ include("../deps.cmake") # Add Modules #deps_find_package(llvm3.8 REQUIRED) # LLVM #deps_find_package(llvm7 REQUIRED) # LLVM -deps_find_package(llvm12 REQUIRED) # LLVM +#deps_find_package(llvm12 REQUIRED) # LLVM +deps_find_package(llvm14 REQUIRED) # LLVM set(COMMON_CXX_FLAGS "-std=c++14 -O3 -Wall -Wno-unused-function") #set(COMMON_CXX_FLAGS "-std=c++14 -O3 -Wall -Wno-unused-function -fuse-ld=\"C:/Program Files/LLVM/bin/ld.lld.exe\"") From 8cbef06b809bda1540ba648efba972a7742d3fec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sat, 18 Feb 2023 18:50:23 +0000 Subject: [PATCH 03/68] [deps] Updates LLVM libraries in llvm14 package --- deps/Findllvm14.cmake | 152 ++++++++++++++++++++---------------------- 1 file changed, 73 insertions(+), 79 deletions(-) diff --git a/deps/Findllvm14.cmake b/deps/Findllvm14.cmake index 0213aad29..df2d26680 100644 --- a/deps/Findllvm14.cmake +++ b/deps/Findllvm14.cmake @@ -94,85 +94,79 @@ list(APPEND llvm14_LIBRARIES ${LINKER_GROUP_END} # LLVM libraries, as given by 'llvm-config --libs' - LLVMWindowsManifest - LLVMXRay - LLVMLibDriver - LLVMDlltoolDriver - LLVMCoverage - LLVMLineEditor - LLVMXCoreDisassembler - LLVMXCoreCodeGen - LLVMXCoreDesc - LLVMXCoreInfo - LLVM${PROCESSOR_PREFIX}Disassembler - LLVM${PROCESSOR_PREFIX}AsmParser - LLVM${PROCESSOR_PREFIX}CodeGen - LLVM${PROCESSOR_PREFIX}Desc - LLVM${PROCESSOR_PREFIX}Info - LLVMARMUtils - LLVMAArch64Utils - LLVMOrcJIT - LLVMMCJIT - LLVMJITLink - LLVMOrcTargetProcess - LLVMOrcShared - LLVMInterpreter - LLVMExecutionEngine - LLVMRuntimeDyld - LLVMSymbolize - LLVMDebugInfoPDB - LLVMDebugInfoGSYM - LLVMOption - LLVMObjectYAML - LLVMMCA - LLVMMCDisassembler - LLVMLTO - LLVMPasses - LLVMCFGuard - LLVMCoroutines - LLVMObjCARCOpts - LLVMHelloNew - LLVMipo - LLVMVectorize - LLVMLinker - LLVMInstrumentation - LLVMFrontendOpenMP - LLVMFrontendOpenACC - LLVMExtensions - LLVMDWARFLinker - LLVMGlobalISel - LLVMMIRParser - LLVMAsmPrinter - LLVMDebugInfoDWARF - LLVMSelectionDAG - LLVMCodeGen - LLVMIRReader - LLVMAsmParser - LLVMInterfaceStub - LLVMFileCheck - LLVMFuzzMutate - LLVMTarget - LLVMScalarOpts - LLVMInstCombine - LLVMAggressiveInstCombine - LLVMTransformUtils - LLVMBitWriter - LLVMAnalysis - LLVMProfileData - LLVMObject - LLVMTextAPI - LLVMMCParser - LLVMMC - LLVMDebugInfoCodeView - LLVMDebugInfoMSF - LLVMBitReader - LLVMCore - LLVMRemarks - LLVMBitstreamReader - LLVMBinaryFormat - LLVMTableGen - LLVMSupport - LLVMDemangle + LLVMWindowsManifest + LLVMXRay + LLVMLibDriver + LLVMDlltoolDriver + LLVMCoverage + LLVMLineEditor + LLVM${PROCESSOR_PREFIX}Disassembler + LLVM${PROCESSOR_PREFIX}AsmParser + LLVM${PROCESSOR_PREFIX}CodeGen + LLVM${PROCESSOR_PREFIX}Desc + LLVM${PROCESSOR_PREFIX}Info + LLVMOrcJIT + LLVMMCJIT + LLVMJITLink + LLVMInterpreter + LLVMExecutionEngine + LLVMRuntimeDyld + LLVMOrcTargetProcess + LLVMOrcShared + LLVMDWP + LLVMSymbolize + LLVMDebugInfoPDB + LLVMDebugInfoGSYM + LLVMOption + LLVMObjectYAML + LLVMMCA + LLVMMCDisassembler + LLVMLTO + LLVMPasses + LLVMCFGuard + LLVMCoroutines + LLVMObjCARCOpts + LLVMipo + LLVMVectorize + LLVMLinker + LLVMInstrumentation + LLVMFrontendOpenMP + LLVMFrontendOpenACC + LLVMExtensions + LLVMDWARFLinker + LLVMGlobalISel + LLVMMIRParser + LLVMAsmPrinter + LLVMDebugInfoMSF + LLVMSelectionDAG + LLVMCodeGen + LLVMIRReader + LLVMAsmParser + LLVMInterfaceStub + LLVMFileCheck + LLVMFuzzMutate + LLVMTarget + LLVMScalarOpts + LLVMInstCombine + LLVMAggressiveInstCombine + LLVMTransformUtils + LLVMBitWriter + LLVMAnalysis + LLVMProfileData + LLVMDebugInfoDWARF + LLVMObject + LLVMTextAPI + LLVMMCParser + LLVMMC + LLVMDebugInfoCodeView + LLVMBitReader + LLVMCore + LLVMRemarks + LLVMBitstreamReader + LLVMBinaryFormat + LLVMTableGen + LLVMSupport + LLVMDemangle ) From 24d29ad014ee5f0756ac5e93919a325a8e1f4063 Mon Sep 17 00:00:00 2001 From: "L. Sousa" Date: Fri, 17 Feb 2023 17:45:11 +0000 Subject: [PATCH 04/68] [ClangASTDumper] Fix breaking changes caused by llvm version bump --- ClangAstDumper/ClangNodes.cpp | 9 +++++---- ClangAstDumper/ClavaDataDumperStmts.cpp | 10 +++------- ClangAstDumper/ClavaDataDumperTypes.cpp | 5 +++-- ClangAstDumper/main.cpp | 2 +- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/ClangAstDumper/ClangNodes.cpp b/ClangAstDumper/ClangNodes.cpp index 1101bcf11..d440e706a 100644 --- a/ClangAstDumper/ClangNodes.cpp +++ b/ClangAstDumper/ClangNodes.cpp @@ -459,7 +459,10 @@ void clava::dump(NestedNameSpecifier* qualifier, int id) { void clava::dump(const TemplateArgument &templateArg, int id, ASTContext* Context) { + SmallString<0> str; + clava::dump(clava::TEMPLATE_ARG_KIND[templateArg.getKind()]); + switch (templateArg.getKind()) { case TemplateArgument::ArgKind::Type: clava::dump(clava::getId(templateArg.getAsType(), id)); @@ -475,10 +478,8 @@ void clava::dump(const TemplateArgument &templateArg, int id, ASTContext* Contex } break; case TemplateArgument::ArgKind::Integral: - //bool isSigned = templateArg.getAsIntegral().isSigned(); - clava::dump(templateArg.getAsIntegral().toString(10)); -// const std::string source = getSource(E); -// clava::dump(source); + templateArg.getAsIntegral().toString(str, 10); + clava::dump(str); break; case TemplateArgument::ArgKind::Template: clava::dump(templateArg.getAsTemplate(), id, Context); diff --git a/ClangAstDumper/ClavaDataDumperStmts.cpp b/ClangAstDumper/ClavaDataDumperStmts.cpp index 8371ffe6e..a9201e425 100644 --- a/ClangAstDumper/ClavaDataDumperStmts.cpp +++ b/ClangAstDumper/ClavaDataDumperStmts.cpp @@ -386,15 +386,11 @@ void clava::ClavaDataDumper::DumpCharacterLiteralData(const CharacterLiteral *E) void clava::ClavaDataDumper::DumpIntegerLiteralData(const IntegerLiteral *E) { DumpLiteralData(E); -// DumpExprData(E); - -// clava::dump(clava::getSource(Context, E->getSourceRange())); - bool isSigned = E->getType()->isSignedIntegerType(); -// const std::string source = getSource(E); -// clava::dump(source); - clava::dump(E->getValue().toString(10, isSigned)); + SmallString<0> str; + E->getValue().toString(str, 10, isSigned); + clava::dump(str); /* const SourceManager &sm = Context->getSourceManager(); diff --git a/ClangAstDumper/ClavaDataDumperTypes.cpp b/ClangAstDumper/ClavaDataDumperTypes.cpp index 55cba566b..d974c9344 100644 --- a/ClangAstDumper/ClavaDataDumperTypes.cpp +++ b/ClangAstDumper/ClavaDataDumperTypes.cpp @@ -457,8 +457,9 @@ void clava::ClavaDataDumper::DumpConstantArrayTypeData(const ConstantArrayType * DumpArrayTypeData(T); //clava::dump(T->getSize().VAL); - clava::dump(T->getSize().toString(10, false)); - + SmallString<0> str; + T->getSize().toString(str, 10, false); + clava::dump(str); } void clava::ClavaDataDumper::DumpVariableArrayTypeData(const VariableArrayType *T) { diff --git a/ClangAstDumper/main.cpp b/ClangAstDumper/main.cpp index a7095fd44..e95602077 100644 --- a/ClangAstDumper/main.cpp +++ b/ClangAstDumper/main.cpp @@ -24,7 +24,7 @@ int main(int argc, const char *argv[]) // but could not detect a significant difference //llvm::errs().SetBuffered(); - CommonOptionsParser OptionsParser(argc, argv, MyToolCategory); + CommonOptionsParser& OptionsParser = CommonOptionsParser::create(argc, argv, MyToolCategory).get(); ClangTool Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathList()); From dfbdf9d57baf11a822da73303e466cb4fb9b7198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sat, 18 Feb 2023 21:54:24 +0000 Subject: [PATCH 05/68] [ClangAstDumper] Fixes use of Expected in main.cpp --- ClangAstDumper/main.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ClangAstDumper/main.cpp b/ClangAstDumper/main.cpp index e95602077..bffb85f91 100644 --- a/ClangAstDumper/main.cpp +++ b/ClangAstDumper/main.cpp @@ -23,10 +23,21 @@ int main(int argc, const char *argv[]) // Errs is the main way we dump information, we tested if making it buffered improved performance // but could not detect a significant difference //llvm::errs().SetBuffered(); + auto OptionsParser = CommonOptionsParser::create(argc, argv, MyToolCategory); + if (auto E = OptionsParser.takeError()) { + // We must consume the error. Typically one of: + // - return the error to our caller + // - toString(), when logging + // - consumeError(), to silently swallow the error + // - handleErrors(), to distinguish error types + llvm::errs() << "Problem while creating options parser: " << toString(std::move(E)) << "\n"; + return -1; + } + + //CommonOptionsParser OptionsParser = *parserResult; + ClangTool Tool((*OptionsParser).getCompilations(), + (*OptionsParser).getSourcePathList()); - CommonOptionsParser& OptionsParser = CommonOptionsParser::create(argc, argv, MyToolCategory).get(); - ClangTool Tool(OptionsParser.getCompilations(), - OptionsParser.getSourcePathList()); /* for(auto source : OptionsParser.getSourcePathList()) { From 965f848db49c702f439a8f0720ea17c1ffb5b796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sat, 18 Feb 2023 23:02:54 +0000 Subject: [PATCH 06/68] [ClangAstDumper] Updates method for generating enums --- ClangAstDumper/clang_enums/CMakeLists.txt | 15 +- ClangAstDumper/clang_enums/ClangEnum.js | 121 ++++++ ClangAstDumper/clang_enums/ClangEnum.lara | 95 ----- ClangAstDumper/clang_enums/ClangEnums.js | 378 ++++++++++++++++++ ClangAstDumper/clang_enums/ClangEnums.lara | 235 ----------- .../clang_enums/ClangEnumsGenerator.lara | 43 -- ClangAstDumper/clang_enums/ExtractEnums.cmake | 29 -- ClangAstDumper/clang_enums/Extractors.js | 102 +++++ ClangAstDumper/clang_enums/HeaderEnums.js | 169 ++++++++ ClangAstDumper/clang_enums/HeaderEnums.lara | 86 ---- ClangAstDumper/clang_enums/Main.js | 124 ++++++ ClangAstDumper/clang_enums/config.clava | 236 +++++++++++ 12 files changed, 1141 insertions(+), 492 deletions(-) create mode 100644 ClangAstDumper/clang_enums/ClangEnum.js delete mode 100644 ClangAstDumper/clang_enums/ClangEnum.lara create mode 100644 ClangAstDumper/clang_enums/ClangEnums.js delete mode 100644 ClangAstDumper/clang_enums/ClangEnums.lara delete mode 100644 ClangAstDumper/clang_enums/ClangEnumsGenerator.lara delete mode 100644 ClangAstDumper/clang_enums/ExtractEnums.cmake create mode 100644 ClangAstDumper/clang_enums/Extractors.js create mode 100644 ClangAstDumper/clang_enums/HeaderEnums.js delete mode 100644 ClangAstDumper/clang_enums/HeaderEnums.lara create mode 100644 ClangAstDumper/clang_enums/Main.js create mode 100644 ClangAstDumper/clang_enums/config.clava diff --git a/ClangAstDumper/clang_enums/CMakeLists.txt b/ClangAstDumper/clang_enums/CMakeLists.txt index 488c06f3e..b1238cb14 100644 --- a/ClangAstDumper/clang_enums/CMakeLists.txt +++ b/ClangAstDumper/clang_enums/CMakeLists.txt @@ -7,10 +7,11 @@ include("../../deps.cmake") # Add Modules #deps_find_package(llvm3.8 REQUIRED) # LLVM #deps_find_package(llvm7 REQUIRED) # LLVM -deps_find_package(llvm12 REQUIRED) # LLVM +#deps_find_package(llvm12 REQUIRED) # LLVM +deps_find_package(llvm14 REQUIRED) # LLVM # Set base llvm dir -set(LLVM_DIR ${llvm12_DIR}) +set(LLVM_DIR ${llvm14_DIR}) set(COMMON_CXX_FLAGS "-O3 -Wall -Wno-unused-function") @@ -19,13 +20,19 @@ find_package(Clava REQUIRED) message(STATUS "LLVM DIR: ${LLVM_DIR}") +# Create target for clang/AST/Type.h +add_library(EnumGen) + +clava_weave(EnumGen "Main.js" ARGS "llvmFolder:'${LLVM_DIR}', outputFolder:'${CMAKE_CURRENT_LIST_DIR}/..'" JAVA_FLAGS -Xmx8000m) + + # Make enum extractor available -include(${CMAKE_CURRENT_LIST_DIR}/ExtractEnums.cmake) +#include(${CMAKE_CURRENT_LIST_DIR}/ExtractEnums.cmake) #extract_enums("${LLVM_DIR}/src/include/clang/AST" "Type.h") #extract_enums("${LLVM_DIR}/src/include/clang/AST" "OperationKinds.h") #extract_enums("${LLVM_DIR}/src/include/clang/Basic" "AttrKinds.h") -extract_enums("${LLVM_DIR}/src/include/clang/Basic" "Specifiers.h") +#extract_enums("${LLVM_DIR}/src/include/clang/Basic" "Specifiers.h") #extract_enums("${LLVM_DIR}/src/include/clang/Basic" "ExceptionSpecificationType.h") #extract_enums("${LLVM_DIR}/src/include/clang/Basic" "Linkage.h") #extract_enums("${LLVM_DIR}/src/include/clang/Basic" "Visibility.h") diff --git a/ClangAstDumper/clang_enums/ClangEnum.js b/ClangAstDumper/clang_enums/ClangEnum.js new file mode 100644 index 000000000..e641c7cd6 --- /dev/null +++ b/ClangAstDumper/clang_enums/ClangEnum.js @@ -0,0 +1,121 @@ +laraImport("weaver.Query"); +laraImport("Extractors"); + +/** + * @class + */ +class ClangEnum { + constructor(name, cppVarName, mapper, excludeArray, className) { + this.name = name; + this.cppVarName = cppVarName; + + if (mapper === undefined) { + mapper = (element) => element; + } + this.mapper = mapper; + + if (excludeArray === undefined) { + excludeArray = []; + } + this.excludeSet = new StringSet(excludeArray); + //println("Exclude set: " + this.excludeSet.values()); + + this.className = className; + + this.enumValues = undefined; + + /* + if (extractor == undefined) { + extractor = Extractors.simpleExtractor; + } + this.extractor = extractor; + */ + this.extractor = Extractors.simpleExtractor; + this.occurence = 1; + } + + setOccurence(occurence) { + this.occurence = occurence; + return this; + } + + getEnumName() { + return this.name; + } + + getCompleteEnumName() { + if (this.className === undefined) { + return this.name; + } + + return this.className + "_" + this.name; + } + + getClassName() { + return this.className; + } + + /* +ClangEnum.prototype.getStartingNode = function() { + if(this.className === undefined) { + return Query.root(); + } + + var startingClass = Query.search("class", this.className).first(); + + if(startingClass === undefined) { + throw new Error("Clang enum specifies class '"+this.className+"', but it could not be found"); + } + + return startingClass; +} +*/ + + setEnumValues(headerLines) { + this.enumValues = this.extractor(this.name, headerLines, this.occurence); + } + + /* + setEnumValues(enumValues) { + if (this.enumValues !== undefined) { + println("Setting enum values again for enum " + this.name); + } + + this.enumValues = enumValues; + } + */ + + getCode() { + if (this.enumValues === undefined) { + println("No enum values set for enum '" + this.name + "'"); + return undefined; + } + + var code = ""; + + code += "extern const std::string clava::" + this.cppVarName + "[] = {\n"; + + for (var enumValue of this.enumValues) { + //println("Enum: " + enumValue); + if (this.excludeSet.has(enumValue.toString())) { + println("Excluded enum '" + enumValue + "'"); + continue; + } + + // Map enum value + enumValue = this.mapper(enumValue); + + code += ' "' + enumValue + '",\n'; + } + + code += "};\n"; + + return code; + } + + getEnumValues() { + return this.enumValues + .filter((e) => !this.excludeSet.has(e.toString())) + .map(this.mapper); + } +} diff --git a/ClangAstDumper/clang_enums/ClangEnum.lara b/ClangAstDumper/clang_enums/ClangEnum.lara deleted file mode 100644 index 0bcdd8e01..000000000 --- a/ClangAstDumper/clang_enums/ClangEnum.lara +++ /dev/null @@ -1,95 +0,0 @@ -import weaver.Query; - -/** - * @class - */ -var ClangEnum = function(name, cppVarName, mapper, excludeArray, className) { - this.name = name; - this.cppVarName = cppVarName; - - if(mapper === undefined) { - mapper = element => element; - } - this.mapper = mapper; - - - if(excludeArray === undefined) { - excludeArray = []; - } - this.excludeSet = new StringSet(excludeArray); - //console.log("Exclude set: " + this.excludeSet.values()); - - this.className = className; - - this.enumValues = undefined; -}; - -ClangEnum.prototype.getEnumName = function() { - return this.name; -} - -ClangEnum.prototype.getCompleteEnumName = function() { - if(this.className === undefined) { - return this.name; - } - - return this.className + "_" + this.name; -} - -ClangEnum.prototype.getClassName = function() { - return this.className; -} - -/* -ClangEnum.prototype.getStartingNode = function() { - if(this.className === undefined) { - return Query.root(); - } - - var startingClass = Query.search("class", this.className).first(); - - if(startingClass === undefined) { - throw new Error("Clang enum specifies class '"+this.className+"', but it could not be found"); - } - - return startingClass; -} -*/ - -ClangEnum.prototype.setEnumValues = function(enumValues) { - if(this.enumValues !== undefined) { - console.log("Setting enum values again for enum " + this.name); - } - - this.enumValues = enumValues; -} - - -ClangEnum.prototype.getCode = function() { - if(this.enumValues === undefined) { - console.log("No enum values set for enum '"+this.name+"'"); - return undefined; - } - - - var code = ""; - - code += "extern const std::string clava::"+this.cppVarName+"[] = {\n"; - - for(var enumValue of this.enumValues) { - //console.log("Enum: " + enumValue); - if(this.excludeSet.has(enumValue.toString())) { - console.log("Excluded enum '"+enumValue+"'"); - continue; - } - - // Map enum value - enumValue = this.mapper(enumValue); - - code += ' "' + enumValue + '",\n'; - } - - code += "};\n"; - - return code; -} \ No newline at end of file diff --git a/ClangAstDumper/clang_enums/ClangEnums.js b/ClangAstDumper/clang_enums/ClangEnums.js new file mode 100644 index 000000000..b8304e86a --- /dev/null +++ b/ClangAstDumper/clang_enums/ClangEnums.js @@ -0,0 +1,378 @@ +laraImport("HeaderEnums"); +laraImport("ClangEnum"); +laraImport("weaver.Query"); + +/** + * @class + */ +class ClangEnums { + static _TYPE_H = new HeaderEnums("src/include/clang/AST/Type.h", [ + new ClangEnum("Kind", "BUILTIN_KIND", undefined, ["LastKind"]).setOccurence( + 3 + ), + new ClangEnum( + "RefQualifierKind", + "REFERENCE_QUALIFIER", + (value) => ClangEnums._removePrefix(value, "RQ_"), + undefined + ), + new ClangEnum( + "ArraySizeModifier", + "ARRAY_SIZE_MODIFIER", + undefined, + undefined + ), + new ClangEnum("UTTKind", "UTT_KIND", undefined, undefined), + new ClangEnum( + "ElaboratedTypeKeyword", + "ELABORATED_TYPE_KEYWORD", + (value) => ClangEnums._removePrefix(value, "ETK_"), + undefined + ), + new ClangEnum( + "TagTypeKind", + "TAG_KIND", + (value) => ClangEnums._removePrefix(value, "TTK_"), + undefined + ), + ]); + + static _OPERATIONS_KINDS_H = new HeaderEnums( + "src/include/clang/AST/OperationKinds.h", + [ + new ClangEnum( + "CastKind", + "CAST_KIND", + (value) => ClangEnums._removePrefix(value, "CK_"), + undefined + ), + new ClangEnum( + "BinaryOperatorKind", + "BINARY_OPERATOR_KIND", + (value) => ClangEnums._removePrefix(value, "BO_"), + undefined + ), + new ClangEnum( + "UnaryOperatorKind", + "UNARY_OPERATOR_KIND", + (value) => ClangEnums._removePrefix(value, "UO_"), + undefined + ), + ] + ); + + static _ATTR_KINDS_H = new HeaderEnums( + "src/include/clang/Basic/AttrKinds.h", + [new ClangEnum("Kind", "ATTRIBUTES", undefined, undefined)] + ); + + static _SPECIFIERS_H = new HeaderEnums( + "src/include/clang/Basic/Specifiers.h", + [ + new ClangEnum( + "CallingConv", + "CALLING_CONVENTION", + (value) => ClangEnums._removePrefix(value, "CC_"), + undefined + ), + new ClangEnum( + "AccessSpecifier", + "ACCESS_SPECIFIER", + (value) => ClangEnums._removePrefix(value, "AS_").toUpperCase(), + undefined + ), + new ClangEnum( + "StorageClass", + "STORAGE_CLASS", + (value) => ClangEnums._removePrefix(value, "SC_"), + undefined + ), + new ClangEnum( + "ExplicitSpecKind", + "EXPLICIT_SPEC_KIND", + undefined, + undefined + ), + new ClangEnum( + "TemplateSpecializationKind", + "TEMPLATE_SPECIALIZATION_KIND", + (value) => ClangEnums._removePrefix(value, "TSK_"), + undefined + ), + ] + ); + + static _EXCEPTION_SPECIFICATION_TYPE_H = new HeaderEnums( + "src/include/clang/Basic/ExceptionSpecificationType.h", + [ + new ClangEnum( + "ExceptionSpecificationType", + "EXCEPTION_SPECIFICATION_TYPE", + (value) => ClangEnums._removePrefix(value, "EST_"), + undefined + ), + ] + ); + + static _LINKAGE_H = new HeaderEnums("src/include/clang/Basic/Linkage.h", [ + new ClangEnum( + "Linkage", + "LINKAGE", + (value) => ClangEnums._removePrefix(value, "EST_"), + undefined + ), + ]); + + static _VISIBILITY_H = new HeaderEnums( + "src/include/clang/Basic/Visibility.h", + [ + new ClangEnum( + "Visibility", + "VISIBILITY", + (value) => ClangEnums._removeSuffix(value, "Visibility"), + undefined + ), + ] + ); + + static _TEMPLATE_BASE_H = new HeaderEnums( + "src/include/clang/AST/TemplateBase.h", + [new ClangEnum("ArgKind", "TEMPLATE_ARG_KIND", undefined, undefined)] + ); + + static _DECL_H = new HeaderEnums("src/include/clang/AST/Decl.h", [ + new ClangEnum( + "InitializationStyle", + "INIT_STYLE", + (value) => ClangEnums._INIT_STYLE_ENUMS[value], + undefined + ), + new ClangEnum( + "TLSKind", + "TLS_KIND", + (value) => ClangEnums._removePrefix(value, "TLS_").toUpperCase(), + undefined + ), + ]); + + static _INIT_STYLE_ENUMS = { + CInit: "CINIT", + CallInit: "CALL_INIT", + ListInit: "LIST_INIT", + }; + + static _EXPR_CXX_H = new HeaderEnums("src/include/clang/AST/ExprCXX.h", [ + new ClangEnum( + "InitializationStyle", + "NEW_INIT_STYLE", + (value) => ClangEnums._NEW_INIT_STYLE_ENUMS[value], + undefined + ).setOccurence(2), + new ClangEnum( + "ConstructionKind", + "CONSTRUCTION_KIND", + (value) => ClangEnums._removePrefix(value, "CK_"), + undefined + ), + ]); + + static _NEW_INIT_STYLE_ENUMS = { + NoInit: "NO_INIT", + CallInit: "CALL_INIT", + ListInit: "LIST_INIT", + }; + + static _TYPE_TRAITS_H = new HeaderEnums( + "src/include/clang/Basic/TypeTraits.h", + [ + new ClangEnum( + "UnaryExprOrTypeTrait", + "UETT_KIND", + (value) => ClangEnums._removePrefix(value, "UETT_"), + ["UETT_Last"] + ), + ] + ); + + static _NESTED_NAME_SPECIFIER_H = new HeaderEnums( + "src/include/clang/AST/NestedNameSpecifier.h", + [ + new ClangEnum( + "SpecifierKind", + "NESTED_NAMED_SPECIFIER", + undefined, + undefined + ), + ] + ); + + static _DECL_CXX_H = new HeaderEnums("src/include/clang/AST/DeclCxx.h", [ + new ClangEnum( + "LanguageIDs", + "LINKAGE_LANGUAGE", + (value) => ClangEnums._removePrefix(value, "lang_").toUpperCase(), + undefined + ), + ]); + + static _LAMBDA_H = new HeaderEnums("src/include/clang/Basic/Lambda.h", [ + new ClangEnum( + "LambdaCaptureDefault", + "LAMBDA_CAPTURE_DEFAULT", + (value) => ClangEnums._removePrefix(value, "LCD_"), + undefined + ), + new ClangEnum( + "LambdaCaptureKind", + "LAMBDA_CAPTURE_KIND", + (value) => ClangEnums._removePrefix(value, "LCK_"), + undefined + ), + ]); + + static _TEMPLATE_NAME_H = new HeaderEnums( + "src/include/clang/AST/TemplateName.h", + [new ClangEnum("NameKind", "TEMPLATE_NAME_KIND", undefined, undefined)] + ); + + static _ATTR_H = new HeaderEnums("src/include/clang/AST/Attr.h", [ + new ClangEnum( + "VisibilityType", + "VISIBILITY_ATTR_TYPE", + undefined, + undefined + ), + ]); + + static _EXPR_H = new HeaderEnums("src/include/clang/AST/Expr.h", [ + new ClangEnum( + "Kind", + "OFFSET_OF_NODE_KIND", + (value) => value.toUpperCase(), + undefined, + "OffsetOfNode" + ).setOccurence(10), + new ClangEnum( + "IdentKind", + "PREDEFINED_ID_TYPE", + undefined, + undefined, + "PredefinedExpr" + ), + new ClangEnum( + "StringKind", + "STRING_KIND", + (value) => value.toUpperCase(), + undefined + ), + //new ClangEnum('Kind', 'DESIGNATOR_KIND', undefined, undefined, 'Designator') + ]); + + /** + + + + +- clang/Ast/Expr.h +Kind, OFFSET_OF_NODE_KIND (class OffsetOfNode) +IdentKind, PREDEFINED_ID_TYPE +StringKind, STRING_KIND +Kind, DESIGNATOR_KIND (class Designator) + + + */ + + static _HEADERS = [ + ClangEnums._TYPE_H, + ClangEnums._OPERATIONS_KINDS_H, + ClangEnums._ATTR_KINDS_H, + ClangEnums._SPECIFIERS_H, + ClangEnums._EXCEPTION_SPECIFICATION_TYPE_H, + ClangEnums._LINKAGE_H, + ClangEnums._VISIBILITY_H, + ClangEnums._TEMPLATE_BASE_H, + ClangEnums._DECL_H, + ClangEnums._EXPR_CXX_H, + ClangEnums._TYPE_TRAITS_H, + ClangEnums._NESTED_NAME_SPECIFIER_H, + ClangEnums._DECL_CXX_H, + ClangEnums._LAMBDA_H, + ClangEnums._TEMPLATE_NAME_H, + ClangEnums._ATTR_H, + ClangEnums._EXPR_H, + ]; + + static getHeader = function (headerFilename) { + if (ClangEnums._HEADER_MAP === undefined) { + ClangEnums._HEADER_MAP = ClangEnums.buildHeaderMap(); + } + + return ClangEnums._HEADER_MAP[headerFilename]; + }; + + static buildHeaderMap = function () { + var map = {}; + + for (var header of ClangEnums._HEADERS) { + map[header.getName()] = header; + } + //println("Header map"); + //printlnObject(map); + return map; + }; + + /** + * Mappers + */ + static _removePrefix = function (enumValue, prefix) { + if (enumValue.startsWith(prefix)) { + enumValue = enumValue.substring(prefix.length); + } + + return enumValue; + }; + + static _removeSuffix = function (enumValue, suffix) { + if (enumValue.endsWith(suffix)) { + enumValue = enumValue.substring(0, enumValue.length - suffix.length); + } + + return enumValue; + }; + + /* +ClangEnums._refQualMapper = function(enumValue) { +//println("MAPPER FOR " + enumValue); + if(enumValue.startsWith("RQ_")) { +// println("Starts with RQ_"); + enumValue = enumValue.substring(3); + } +// println("RETURNING: " + enumValue); + return enumValue; +} +*/ + /* +ClangEnums._elaboratedTypeKeyworkMapper = function(enumValue) { + + if(enumValue.startsWith("ETK_")) { + enumValue = enumValue.substring(4); + } + + enumValue = enumValue.toUpperCase(); + + return enumValue; +} +*/ + /* +ClangEnums._tagKindMapperMapper = function(enumValue) { + + if(enumValue.startsWith("TTK_")) { + enumValue = enumValue.substring(4); + } + + enumValue = enumValue.toUpperCase(); + + return enumValue; +} +*/ +} diff --git a/ClangAstDumper/clang_enums/ClangEnums.lara b/ClangAstDumper/clang_enums/ClangEnums.lara deleted file mode 100644 index 88913d796..000000000 --- a/ClangAstDumper/clang_enums/ClangEnums.lara +++ /dev/null @@ -1,235 +0,0 @@ -import HeaderEnums; -import ClangEnum; - -/** - * @class - */ -var ClangEnums = {}; - - - - -ClangEnums._TYPE_H = new HeaderEnums('Type.h', [ - new ClangEnum('Kind', 'BUILTIN_KIND', undefined, ["LastKind"]), - new ClangEnum('RefQualifierKind', 'REFERENCE_QUALIFIER', value => ClangEnums._removePrefix(value, "RQ_"), undefined), - new ClangEnum('ArraySizeModifier', 'ARRAY_SIZE_MODIFIER', undefined, undefined), - new ClangEnum('UTTKind', 'UTT_KIND', undefined, undefined), - new ClangEnum('ElaboratedTypeKeyword', 'ELABORATED_TYPE_KEYWORD', value => ClangEnums._removePrefix(value, "ETK_"), undefined), - new ClangEnum('TagTypeKind', 'TAG_KIND', value => ClangEnums._removePrefix(value, "TTK_"), undefined) -]); - - -ClangEnums._OPERATIONS_KINDS_H = new HeaderEnums('OperationKinds.h', [ - new ClangEnum('CastKind', 'CAST_KIND', value => ClangEnums._removePrefix(value, "CK_"), undefined), - new ClangEnum('BinaryOperatorKind', 'BINARY_OPERATOR_KIND', value => ClangEnums._removePrefix(value, "BO_"), undefined), - new ClangEnum('UnaryOperatorKind', 'UNARY_OPERATOR_KIND', value => ClangEnums._removePrefix(value, "UO_"), undefined) -]); - - -ClangEnums._ATTR_KINDS_H = new HeaderEnums('AttrKinds.h', [ - new ClangEnum('Kind', 'ATTRIBUTES', undefined, undefined) -]); - - -ClangEnums._SPECIFIERS_H = new HeaderEnums('Specifiers.h', [ - new ClangEnum('CallingConv', 'CALLING_CONVENTION', value => ClangEnums._removePrefix(value, "CC_"), undefined), - new ClangEnum('AccessSpecifier', 'ACCESS_SPECIFIER', (value => ClangEnums._removePrefix(value, "AS_").toUpperCase()), undefined), - new ClangEnum('StorageClass', 'STORAGE_CLASS', value => ClangEnums._removePrefix(value, "SC_"), undefined), - new ClangEnum('ExplicitSpecKind', 'EXPLICIT_SPEC_KIND', undefined, undefined), - new ClangEnum('TemplateSpecializationKind', 'TEMPLATE_SPECIALIZATION_KIND', value => ClangEnums._removePrefix(value, "TSK_"), undefined), -]); - - - -ClangEnums._EXCEPTION_SPECIFICATION_TYPE_H = new HeaderEnums('ExceptionSpecificationType.h', [ - new ClangEnum('ExceptionSpecificationType', 'EXCEPTION_SPECIFICATION_TYPE', (value => ClangEnums._removePrefix(value, "EST_")), undefined) -]); - -ClangEnums._LINKAGE_H = new HeaderEnums('Linkage.h', [ - new ClangEnum('Linkage', 'LINKAGE', (value => ClangEnums._removePrefix(value, "EST_")), undefined) -]); - -ClangEnums._VISIBILITY_H = new HeaderEnums('Visibility.h', [ - new ClangEnum('Visibility', 'VISIBILITY', (value => ClangEnums._removeSuffix(value, "Visibility")), undefined) -]); - -ClangEnums._TEMPLATE_BASE_H = new HeaderEnums('TemplateBase.h', [ - new ClangEnum('ArgKind', 'TEMPLATE_ARG_KIND', undefined, undefined) -]); - -ClangEnums._DECL_H = new HeaderEnums('Decl.h', [ - new ClangEnum('InitializationStyle', 'INIT_STYLE', (value => ClangEnums._INIT_STYLE_ENUMS[value]), undefined), - new ClangEnum('TLSKind', 'TLS_KIND', (value => ClangEnums._removePrefix(value, "TLS_").toUpperCase()), undefined) -]); - -ClangEnums._INIT_STYLE_ENUMS = { - CInit: "CINIT", - CallInit: "CALL_INIT", - ListInit: "LIST_INIT" -}; - - -ClangEnums._EXPR_CXX_H = new HeaderEnums('ExprCXX.h', [ - new ClangEnum('InitializationStyle', 'NEW_INIT_STYLE', (value => ClangEnums._NEW_INIT_STYLE_ENUMS[value]), undefined), - new ClangEnum('ConstructionKind', 'CONSTRUCTION_KIND', (value => ClangEnums._removePrefix(value, "CK_")), undefined) -]); - - -ClangEnums._NEW_INIT_STYLE_ENUMS = { - NoInit: "NO_INIT", - CallInit: "CALL_INIT", - ListInit: "LIST_INIT" -}; - - -ClangEnums._TYPE_TRAITS_H = new HeaderEnums('TypeTraits.h', [ - new ClangEnum('UnaryExprOrTypeTrait', 'UETT_KIND', (value => ClangEnums._removePrefix(value, "UETT_")), ["UETT_Last"]) -]); - - -ClangEnums._NESTED_NAME_SPECIFIER_H = new HeaderEnums('NestedNameSpecifier.h', [ - new ClangEnum('SpecifierKind', 'NESTED_NAMED_SPECIFIER', undefined, undefined) -]); - - -ClangEnums._DECL_CXX_H = new HeaderEnums('DeclCxx.h', [ - new ClangEnum('LanguageIDs', 'LINKAGE_LANGUAGE', (value => ClangEnums._removePrefix(value, "lang_").toUpperCase()), undefined) -]); - - -ClangEnums._LAMBDA_H = new HeaderEnums('Lambda.h', [ - new ClangEnum('LambdaCaptureDefault', 'LAMBDA_CAPTURE_DEFAULT', (value => ClangEnums._removePrefix(value, "LCD_")), undefined), - new ClangEnum('LambdaCaptureKind', 'LAMBDA_CAPTURE_KIND', (value => ClangEnums._removePrefix(value, "LCK_")), undefined) -]); - - -ClangEnums._TEMPLATE_NAME_H = new HeaderEnums('TemplateName.h', [ - new ClangEnum('NameKind', 'TEMPLATE_NAME_KIND', undefined, undefined) -]); - - -ClangEnums._ATTR_H = new HeaderEnums('Attr.h', [ - new ClangEnum('VisibilityType', 'VISIBILITY_ATTR_TYPE', undefined, undefined) -]); - - -ClangEnums._EXPR_H = new HeaderEnums('Expr.h', [ - new ClangEnum('Kind', 'OFFSET_OF_NODE_KIND', (value => value.toUpperCase()), undefined, 'OffsetOfNode'), - new ClangEnum('IdentKind', 'PREDEFINED_ID_TYPE', undefined, undefined, 'PredefinedExpr'), - new ClangEnum('StringKind', 'STRING_KIND', (value => value.toUpperCase()), undefined) - //new ClangEnum('Kind', 'DESIGNATOR_KIND', undefined, undefined, 'Designator') -]); - - - -/** - - - - -- clang/Ast/Expr.h -Kind, OFFSET_OF_NODE_KIND (class OffsetOfNode) -IdentKind, PREDEFINED_ID_TYPE -StringKind, STRING_KIND -Kind, DESIGNATOR_KIND (class Designator) - - - */ - - - -ClangEnums._HEADERS = [ClangEnums._TYPE_H, - ClangEnums._OPERATIONS_KINDS_H, - ClangEnums._ATTR_KINDS_H, - ClangEnums._SPECIFIERS_H, - ClangEnums._EXCEPTION_SPECIFICATION_TYPE_H, - ClangEnums._LINKAGE_H, - ClangEnums._VISIBILITY_H, - ClangEnums._TEMPLATE_BASE_H, - ClangEnums._DECL_H, - ClangEnums._EXPR_CXX_H, - ClangEnums._TYPE_TRAITS_H, - ClangEnums._NESTED_NAME_SPECIFIER_H, - ClangEnums._DECL_CXX_H, - ClangEnums._LAMBDA_H, - ClangEnums._TEMPLATE_NAME_H, - ClangEnums._ATTR_H, - ClangEnums._EXPR_H -]; - -ClangEnums.getHeader = function(headerFilename) { - if(ClangEnums._HEADER_MAP === undefined) { - ClangEnums._HEADER_MAP = ClangEnums.buildHeaderMap(); - } - - return ClangEnums._HEADER_MAP[headerFilename]; -} - -ClangEnums.buildHeaderMap = function() { - var map = {}; - - for(var header of ClangEnums._HEADERS) { - map[header.getName()] = header; - } - //console.log("Header map"); - //printlnObject(map); - return map; -} - -/** - * Mappers - */ -ClangEnums._removePrefix = function(enumValue, prefix) { - - if(enumValue.startsWith(prefix)) { - enumValue = enumValue.substring(prefix.length); - } - - return enumValue; -} - - -ClangEnums._removeSuffix = function(enumValue, suffix) { - - if(enumValue.endsWith(suffix)) { - enumValue = enumValue.substring(0, enumValue.length - suffix.length); - } - - return enumValue; -} - -/* -ClangEnums._refQualMapper = function(enumValue) { -//console.log("MAPPER FOR " + enumValue); - if(enumValue.startsWith("RQ_")) { -// console.log("Starts with RQ_"); - enumValue = enumValue.substring(3); - } -// console.log("RETURNING: " + enumValue); - return enumValue; -} -*/ -/* -ClangEnums._elaboratedTypeKeyworkMapper = function(enumValue) { - - if(enumValue.startsWith("ETK_")) { - enumValue = enumValue.substring(4); - } - - enumValue = enumValue.toUpperCase(); - - return enumValue; -} -*/ -/* -ClangEnums._tagKindMapperMapper = function(enumValue) { - - if(enumValue.startsWith("TTK_")) { - enumValue = enumValue.substring(4); - } - - enumValue = enumValue.toUpperCase(); - - return enumValue; -} -*/ \ No newline at end of file diff --git a/ClangAstDumper/clang_enums/ClangEnumsGenerator.lara b/ClangAstDumper/clang_enums/ClangEnumsGenerator.lara deleted file mode 100644 index 1ee7c0788..000000000 --- a/ClangAstDumper/clang_enums/ClangEnumsGenerator.lara +++ /dev/null @@ -1,43 +0,0 @@ -import ClangEnums; -import weaver.Query; -import lara.Io; - - -aspectdef ClangEnumsGenerator - input header="Type.h", outputFolder="./" end - - console.log("Calling generator for header '"+header+"', generating files in folder " + Io.getPath(outputFolder).getAbsolutePath()); - - // Get corresponding ClangEnum - var headerEnums = ClangEnums.getHeader(header); - - if(headerEnums === undefined) { - console.log("Could not find ClangEnum for header file '"+header+"'"); - return; - } - - - console.log("Searching for enums in header '"+header+"'..."); - - for(var $enum of Query.search("enumDecl")) { - headerEnums.process($enum); - /* - if(typeEnums.has($enum.name)) { - console.log("Saving Enum: " + $enum.name); - // Save enum values - var enumFile = Io.getPath($enum.name + "_type.h.txt"); - var enumValues = $enum.enumerators.map($enumValue => $enumValue.name).join("\n"); - Io.writeFile(enumFile, enumValues); - } -*/ - } - - console.log("Finished searching, generating code"); - - headerEnums.generateCode(outputFolder); - -// console.log($app.ast); - - -// console.log("hello"); -end \ No newline at end of file diff --git a/ClangAstDumper/clang_enums/ExtractEnums.cmake b/ClangAstDumper/clang_enums/ExtractEnums.cmake deleted file mode 100644 index 2fd813fdb..000000000 --- a/ClangAstDumper/clang_enums/ExtractEnums.cmake +++ /dev/null @@ -1,29 +0,0 @@ -# extract_enums function -# Extracts the enum values from a given header file. -# -# Parameters: -# CURRENT_TARGET - A CMake target -# INCLUDE_DIRECTORIES_FOUND - Output list where the include directories will be stored -# -function(extract_enums BASE_FOLDER HEADER_FILENAME) -#CURRENT_TARGET -# Create target for clang/AST/Type.h -set(TARGET_NAME "enums_${HEADER_FILENAME}") - -#add_library(${TARGET_NAME} "${LLVM_DIR}/src/include/clang/AST/Type.h") -add_library(${TARGET_NAME} "${BASE_FOLDER}/${HEADER_FILENAME}") - -set_property(TARGET ${TARGET_NAME} PROPERTY CXX_STANDARD 14) - -# Because it is a header file, it cannot figure it out alone -set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX) - -# Add includes -target_include_directories(${TARGET_NAME} - SYSTEM PUBLIC ${DEPS_INCLUDES} -) - -# Add enums helper -clava_weave(${TARGET_NAME} "ClangEnumsGenerator.lara" ARGS "header:'${HEADER_FILENAME}', outputFolder:'${CMAKE_CURRENT_LIST_DIR}/..'" JAVA_FLAGS -Xmx8000m) - -endfunction(extract_enums) diff --git a/ClangAstDumper/clang_enums/Extractors.js b/ClangAstDumper/clang_enums/Extractors.js new file mode 100644 index 000000000..8ce7daa83 --- /dev/null +++ b/ClangAstDumper/clang_enums/Extractors.js @@ -0,0 +1,102 @@ +class Extractors { + static simpleExtractor(enumName, lines, occurence) { + const regex = "enum\\s+(class\\s+)?" + enumName + "\\s.*{"; + const enumNameRegex = new RegExp(regex); + //const enumNameRegex = new RegExp("\\s"+enumName+"\\s"); + + const enums = []; + let searching = true; + let completed = false; + let currentOccurence = 0; + + for (var line of lines) { + if (searching) { + // Find enum + const matchResult = line.match(enumNameRegex); + if (matchResult == null) { + continue; + } + + // Found enum, increment occurence + currentOccurence++; + + // If not correct occurent, continue + if (currentOccurence !== occurence) { + continue; + } + + // Found occurence, finish search and fallthrough, updating line + searching = false; + + const indexOfBracket = line.indexOf("{"); + line = line.substring(indexOfBracket + 1); + + //continue; + } + + // Collect enums until } is found + line = line.trim(); + + if (line.startsWith("}")) { + // Finished, set flag + completed = true; + break; + } + + // Continue if empty or comment + if (line == "" || line.startsWith("#") || line.startsWith("+")) { + continue; + } + + // Split by , + const enumNames = line + .split(",") + // Trim string + .map((s) => s.trim()) + // Remove empty strings + .filter((s) => s.length > 0) + // Remove =, } if present + .map((s) => Extractors._processEnum(s)); + /* + // Remove , if present + if (line.endsWith(",")) { + line = line.substring(0, line.length - 1); + } +*/ + // Get enum + + //println("Enum: " + line) + for (const enumName of enumNames) { + enums.push(enumName); + } + + if (line.includes("}")) { + // Finished, set flag + completed = true; + break; + } + } + + if (!completed) { + throw new Error("Could not find } for enum " + enumName); + } + + return enums; + } + + static _processEnum(enumName) { + // Check for = + const indexOfEquals = enumName.indexOf("="); + if (indexOfEquals !== -1) { + enumName = enumName.substring(0, indexOfEquals).trim(); + } + + // Check for } + const indexOfBraket = enumName.indexOf("}"); + if (indexOfBraket !== -1) { + enumName = enumName.substring(0, indexOfBraket).trim(); + } + + return enumName; + } +} diff --git a/ClangAstDumper/clang_enums/HeaderEnums.js b/ClangAstDumper/clang_enums/HeaderEnums.js new file mode 100644 index 000000000..805e01468 --- /dev/null +++ b/ClangAstDumper/clang_enums/HeaderEnums.js @@ -0,0 +1,169 @@ +laraImport("lara.util.StringSet"); +laraImport("lara.Io"); +laraImport("lara.Strings"); +laraImport("lara.util.ProcessExecutor"); +laraImport("weaver.Query"); + +/** + * @class + */ +class HeaderEnums { + constructor(headerFilename, clangEnums) { + this.headerFilename = headerFilename; + this.enumMap = {}; + this.currentEnumSet = new StringSet(); + this.enumsInsideClass = new StringSet(); + + for (var clangEnum of clangEnums) { + this.enumMap[clangEnum.getCompleteEnumName()] = clangEnum; + this.currentEnumSet.add(clangEnum.getCompleteEnumName()); + + var className = clangEnum.getClassName(); + if (className !== undefined) { + this.enumsInsideClass.add(clangEnum.getEnumName()); + } + } + } + + getName() { + return this.headerFilename; + } + + _getEnumName($enum) { + // Check if enum needs to be prefixed by class + if (!this.enumsInsideClass.has($enum.name)) { + return $enum.name; + } + + // Get class + var $class = $enum.ancestor("class"); + + return $class.name + "_" + $enum.name; + } + + process(llvmFolder) { + const compilerCmd = "clang"; + const headerFile = Io.getPath(llvmFolder, this.headerFilename); + + // Preprocess header + const exec = new ProcessExecutor(); + // Clean folder and set working directory + + exec.setPrintToConsole(false); + const preprocessedFile = exec.execute( + compilerCmd, + "-E", + headerFile.getAbsolutePath() + ); + + debug( + "Processed header '" + + headerFile.getAbsolutePath() + + "':\n" + + preprocessedFile + ); + + const headerLines = Strings.asLines(preprocessedFile); + + //println("Header: " + headerLines); + + for (const enumName in this.enumMap) { + const clangEnum = this.enumMap[enumName]; + //println("Enum name: " + enumName); + //printlnObject(clangEnum); + + // Extract enums + //const enumValues = clangEnum.extractor(enumName, headerLines); + //println("Values: " + enumValues); + clangEnum.setEnumValues(headerLines); + /* + var filename = + this.headerFilename.replace(".", "_") + "_" + enumName + ".txt"; + var file = Io.getPath(filename); + println("Saving enum values to file '" + file.getAbsolutePath() + "'"); + Io.writeFile(filename, enumValues.join("\n")); + */ + } + //println("Enums:"); + //printlnObject(this.enumMap); + /* + // Get enum name + var enumName = this._getEnumName($enum); + + // Check if valid enum + //if(!this.currentEnumSet.has($enum.name)) { + if (!this.currentEnumSet.has(enumName)) { + return; + } + + //println("Adding enum '"+$enum.name+"'"); + println("Adding enum '" + enumName + "'"); + + // Set enums + var enumValues = $enum.enumerators.map(($enumValue) => $enumValue.name); + //this.enumMap[$enum.name].setEnumValues(enumValues); + this.enumMap[enumName].setEnumValues(enumValues); + + // Save enums, for referece + //var filename = this.headerFilename.replace(".", "_") + "_" + $enum.name + ".txt"; + var filename = + this.headerFilename.replace(".", "_") + "_" + enumName + ".txt"; + var file = Io.getPath(filename); + println("Saving enum values to file '" + file.getAbsolutePath() + "'"); + Io.writeFile(filename, enumValues.join("\n")); + */ + } + + generateCode(outputFolder) { + const headerFile = Io.getPath(this.headerFilename); + + //var filename = "enums_" + this.headerFilename.replace(".", "_") + ".cpp"; + var filename = "enums_" + headerFile.getName().replace(".", "_") + ".cpp"; + + var code = '#include "ClangEnums.h"\n\n'; + + // Generate code for each of the enums + for (var enumName in this.enumMap) { + var enumCode = this.enumMap[enumName].getCode(); + + if (enumCode === undefined) { + println( + "Skipped code generation for " + this.headerFilename + "::" + enumName + ); + continue; + } + + code += enumCode + "\n"; + } + + const outputFile = Io.getPath(outputFolder, filename); + println("Generating header file '" + outputFile.getAbsolutePath() + "'"); + Io.writeFile(Io.getPath(outputFolder, filename), code); + } + + generateJavaEnums(outputFolder) { + const headerFile = Io.getPath(this.headerFilename); + + // Dump the names of each enum + for (var enumName in this.enumMap) { + var enumValues = this.enumMap[enumName].getEnumValues(); + + var filename = + "enums_" + + headerFile.getName().replace(".", "_") + + "_" + + enumName + + ".txt"; + + var code = enumValues.join(",\n") + ";"; + + const outputFile = Io.getPath(outputFolder, filename); + println( + "Generating Java enum values file '" + + outputFile.getAbsolutePath() + + "'" + ); + Io.writeFile(Io.getPath(outputFolder, filename), code); + } + } +} diff --git a/ClangAstDumper/clang_enums/HeaderEnums.lara b/ClangAstDumper/clang_enums/HeaderEnums.lara deleted file mode 100644 index d220c2c46..000000000 --- a/ClangAstDumper/clang_enums/HeaderEnums.lara +++ /dev/null @@ -1,86 +0,0 @@ -import lara.util.StringSet; -import lara.Io; - -/** - * @class - */ -var HeaderEnums = function(headerFilename, clangEnums) { - this.headerFilename = headerFilename; - this.enumMap = {}; - this.currentEnumSet = new StringSet(); - this.enumsInsideClass = new StringSet(); - - for(var clangEnum of clangEnums) { - this.enumMap[clangEnum.getCompleteEnumName()] = clangEnum; - this.currentEnumSet.add(clangEnum.getCompleteEnumName()); - - var className = clangEnum.getClassName(); - if(className !== undefined) { - this.enumsInsideClass.add(clangEnum.getEnumName()); - } - } -}; - -HeaderEnums.prototype.getName = function() { - return this.headerFilename; -} - -HeaderEnums.prototype._getEnumName = function($enum) { - // Check if enum needs to be prefixed by class - if(!this.enumsInsideClass.has($enum.name)) { - return $enum.name; - } - - // Get class - var $class = $enum.getAncestor("class"); - - return $class.name + "_" + $enum.name; -} - -HeaderEnums.prototype.process = function($enum) { - - // Get enum name - var enumName = this._getEnumName($enum); - - // Check if valid enum - //if(!this.currentEnumSet.has($enum.name)) { - if(!this.currentEnumSet.has(enumName)) { - return; - } - - //console.log("Adding enum '"+$enum.name+"'"); - console.log("Adding enum '"+enumName+"'"); - - // Set enums - var enumValues = $enum.enumerators.map($enumValue => $enumValue.name); - //this.enumMap[$enum.name].setEnumValues(enumValues); - this.enumMap[enumName].setEnumValues(enumValues); - - // Save enums, for referece - //var filename = this.headerFilename.replace(".", "_") + "_" + $enum.name + ".txt"; - var filename = this.headerFilename.replace(".", "_") + "_" + enumName + ".txt"; - var file = Io.getPath(filename); - console.log("Saving enum values to file '"+file.getAbsolutePath()+"'"); - Io.writeFile(filename, enumValues.join("\n")); -} - -HeaderEnums.prototype.generateCode = function(outputFolder) { - - var filename = "enums_" + this.headerFilename.replace(".", "_") + ".cpp"; - - var code = '#include "ClangEnums.h"\n\n'; - - // Generate code for each of the enums - for(var enumName in this.enumMap) { - var enumCode = this.enumMap[enumName].getCode(); - - if(enumCode === undefined) { - console.log("Skipped code generation for " + this.headerFilename + "::" + enumName); - continue; - } - - code += enumCode + "\n"; - } - - Io.writeFile(Io.getPath(outputFolder, filename), code); -} diff --git a/ClangAstDumper/clang_enums/Main.js b/ClangAstDumper/clang_enums/Main.js new file mode 100644 index 000000000..7cba6978a --- /dev/null +++ b/ClangAstDumper/clang_enums/Main.js @@ -0,0 +1,124 @@ +laraImport("clava.Clava"); +laraImport("lara.Io"); +laraImport("lara.Strings"); +laraImport("lara.util.ProcessExecutor"); +laraImport("ClangEnums"); +laraImport("HeaderEnums"); + +const llvmFolder = laraArgs.llvmFolder; +const outputFolder = laraArgs.outputFolder; + +println("Using LLVM folder '" + llvmFolder + "'"); +println("Generating enums to folder '" + outputFolder + "'"); + +for (const header of ClangEnums._HEADERS) { + header.process(llvmFolder); + header.generateCode(outputFolder); + header.generateJavaEnums(Io.mkdir(outputFolder, "java_enums")); + /* + try { + header.process(llvmFolder); + header.generateCode("C:\\Users\\JBispo\\Work\\Repos\\Lab\\clava\\ClangAstDumper"); + } catch(e) { + println("Skipping header " + header.getName() + ": " + e); + } +*/ +} + +/* + const header = ClangEnums._DECL_CXX_H; + header.process(llvmFolder); + header.generateCode("C:\\Users\\JBispo\\Work\\Repos\\Lab\\clava\\ClangAstDumper"); + header.generateJavaEnums("C:\\Users\\JBispo\\Work\\Repos\\Lab\\clava\\ClangAstDumper\\clang_enums_v2\\JavaEnums"); +*/ +/* +const testHeaderEnum = ClangEnums._OPERATIONS_KINDS_H; + +testHeaderEnum.process(llvmFolder) + +testHeaderEnum.generateCode("C:\\Users\\JBispo\\Work\\Repos\\Lab\\clava\\ClangAstDumper"); +*/ +/* +const compilerCmd = "clang" +const baseFolder = Clava.getData().getContextFolder(); + + + +const headerFile = Io.getPath(llvmFolder, "/src/include/clang/AST/OperationKinds.h"); + +//const preprocessorFolder = Io.mkdir(baseFolder, "preprocessorOutput") + +// Preprocess header +const exec = new ProcessExecutor(); +// Clean folder and set working directory +//Io.deleteFolderContents(preprocessorFolder); +//exec.setWorkingDir(preprocessorFolder); +exec.setPrintToConsole(false); +const preprocessedFile = exec.execute(compilerCmd, "-E", headerFile.getAbsolutePath()); +//println(headerFile.getAbsolutePath()) + +println(preprocessedFile) + +const headerLines = Strings.asLines(preprocessedFile); + +// Extract enum from header +const enums = extractEnum("CastKind", headerLines); +println("enums:\n"+enums); +*/ +/* +function extractEnum(enumName, lines) { + const regex = "enum\\s+"+enumName+"\\s+{"; + const enumNameRegex = new RegExp(regex); + //const enumNameRegex = new RegExp("\\s"+enumName+"\\s"); + + const enums = []; + let searching = true; + let completed = false; + + + for(var line of lines) { + if(searching) { + // Find enum + const matchResult = line.match(enumNameRegex) + if(matchResult == null) { + continue; + } + + // Found enum, finish search + searching = false; + continue; + } + + // Collect enums until } is found + line = line.trim(); + + if(line.startsWith("}")){ + // Finished, set flag + completed = true; + break; + } + + // Continue if empty or comment + if(line == "" || line.startsWith("#")) { + continue; + } + + // Remove , if present + if(line.endsWith(",")) { + line = line.substring(0, line.length-1); + } + + // Get enum + + //println("Enum: " + line) + enums.push(line); + + } + + if(!completed) { + throw new Error("Could not find } for enum " + enumName); + } + + return enums; +} +*/ diff --git a/ClangAstDumper/clang_enums/config.clava b/ClangAstDumper/clang_enums/config.clava new file mode 100644 index 000000000..0aab5c824 --- /dev/null +++ b/ClangAstDumper/clang_enums/config.clava @@ -0,0 +1,236 @@ + + LaraI Options + + + workspace + + + + + + library includes + + + + + + main + + + + output + + + + parsingNumThreads + 0 + + + libcCxxMode + AUTO + + + cudaGpuArch + + + + parseIncludes + true + + + javascript + false + + + Disable Remote Dependencies + false + + + joptions_current_folder_path + + + + Generate Modified Code Only + false + + + parallelParsing + true + + + api_autoload + true + + + continueOnParsingErrors + false + + + Weaved code foldername + woven_code + + + external_dependencies + + + + + + Disable Weaving + false + + + metrics + + + false + + + + C/C++ Standard + GNUXX11 + + + workspace_extra + + + + Clava Custom Resources + false + + + restrict mode + false + + + loc + false + + + Disable Code Generation + false + + + log + + + false + + + + autoimportjs + false + + + Clean intermediate files + true + + + systemIncludesThreshold + 1 + + + argv + {"llvmFolder":"C:/Users/JBispo/Work/Repos/Lab/clava/deps/deps-lib/../artifacts/llvm14-Windows-gcc5"} + + + tools + + + false + + + + jsEngine + GRAALVM_COMPAT + + + flatOutputFolder + false + + + bundle_tags + + + + customClangAstDumperExe + + + + Compiler Flags + + + + Compiler Flags in list format + + + -Wno-narrowing + -Wno-deprecated-register + -Wno-unused-value + + + + + Check C/CXX Syntax + false + + + aspect + Main.js + + + ignoreHeaderIncludes + + + + + + cudaPath + + + + stack trace + true + + + include + + + + + + debug + false + + + Disable Clava Info + false + + + Copy files in sources + false + + + Generate CMake Integration Helper Files + false + + + verbose + warnings + + + header includes + + + + + + report + + + false + + + + false + \ No newline at end of file From bf3a881f3c5e069a4ce0790d7037a57ad3f49c8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sat, 18 Feb 2023 23:03:42 +0000 Subject: [PATCH 07/68] [ClangAstDumper] Updates (auto-generated) enums --- ClangAstDumper/enums_AttrKinds_h.cpp | 33 +++++++- ClangAstDumper/enums_OperationKinds_h.cpp | 1 + ClangAstDumper/enums_Specifiers_h.cpp | 1 + ClangAstDumper/enums_Type_h.cpp | 91 ++++++++++++++++++++--- 4 files changed, 111 insertions(+), 15 deletions(-) diff --git a/ClangAstDumper/enums_AttrKinds_h.cpp b/ClangAstDumper/enums_AttrKinds_h.cpp index 6824c2f33..85cff79b1 100644 --- a/ClangAstDumper/enums_AttrKinds_h.cpp +++ b/ClangAstDumper/enums_AttrKinds_h.cpp @@ -2,7 +2,9 @@ extern const std::string clava::ATTRIBUTES[] = { "AddressSpace", + "AnnotateType", "ArmMveStrictPolymorphism", + "BTFTypeTag", "CmseNSCall", "NoDeref", "ObjCGC", @@ -25,10 +27,16 @@ extern const std::string clava::ATTRIBUTES[] = { "UPtr", "FallThrough", "Likely", + "MustTail", + "OpenCLUnrollHint", "Suppress", "Unlikely", + "AlwaysInline", + "NoInline", "NoMerge", + "AArch64SVEPcs", "AArch64VectorPcs", + "AMDGPUKernelCall", "AcquireHandle", "AnyX86NoCfCheck", "CDecl", @@ -44,10 +52,12 @@ extern const std::string clava::ATTRIBUTES[] = { "PreserveMost", "RegCall", "StdCall", + "SwiftAsyncCall", "SwiftCall", "SysVABI", "ThisCall", "VectorCall", + "SwiftAsyncContext", "SwiftContext", "SwiftErrorResult", "SwiftIndirectResult", @@ -76,7 +86,6 @@ extern const std::string clava::ATTRIBUTES[] = { "AllocAlign", "AllocSize", "AlwaysDestroy", - "AlwaysInline", "AnalyzerNoReturn", "AnyX86Interrupt", "AnyX86NoCallerSavedRegisters", @@ -92,6 +101,7 @@ extern const std::string clava::ATTRIBUTES[] = { "Assumption", "Availability", "BPFPreserveAccessIndex", + "BTFDeclTag", "Blocks", "Builtin", "C11NoReturn", @@ -135,13 +145,16 @@ extern const std::string clava::ATTRIBUTES[] = { "DLLImportStaticLocal", "Deprecated", "Destructor", + "DiagnoseAsBuiltin", "DiagnoseIf", + "DisableSanitizerInstrumentation", "DisableTailCalls", "EmptyBases", "EnableIf", "EnforceTCB", "EnforceTCBLeaf", "EnumExtensibility", + "Error", "ExcludeFromExplicitInstantiation", "ExclusiveTrylockFunction", "ExternalSourceSymbol", @@ -150,10 +163,14 @@ extern const std::string clava::ATTRIBUTES[] = { "Flatten", "Format", "FormatArg", + "FunctionReturnThunks", "GNUInline", "GuardedBy", "GuardedVar", "HIPManaged", + "HLSLNumThreads", + "HLSLSV_GroupIndex", + "HLSLShader", "Hot", "IBAction", "IBOutlet", @@ -165,6 +182,7 @@ extern const std::string clava::ATTRIBUTES[] = { "Leaf", "LockReturned", "LocksExcluded", + "M68kInterrupt", "MIGServerRoutine", "MSAllocator", "MSInheritance", @@ -191,10 +209,11 @@ extern const std::string clava::ATTRIBUTES[] = { "NoDebug", "NoDestroy", "NoDuplicate", - "NoInline", "NoInstrumentFunction", "NoMicroMips", "NoMips16", + "NoProfileFunction", + "NoRandomizeLayout", "NoReturn", "NoSanitize", "NoSpeculativeLoadHardening", @@ -231,7 +250,6 @@ extern const std::string clava::ATTRIBUTES[] = { "ObjCSubclassingRestricted", "OpenCLIntelReqdSubGroupSize", "OpenCLKernel", - "OpenCLUnrollHint", "OptimizeNone", "Override", "Owner", @@ -250,15 +268,18 @@ extern const std::string clava::ATTRIBUTES[] = { "PtGuardedVar", "Pure", "RISCVInterrupt", + "RandomizeLayout", "Reinitializes", "ReleaseCapability", "ReqdWorkGroupSize", "RequiresCapability", "Restrict", + "Retain", "ReturnTypestate", "ReturnsNonNull", "ReturnsTwice", "SYCLKernel", + "SYCLSpecialClass", "ScopedLockable", "Section", "SelectAny", @@ -266,8 +287,10 @@ extern const std::string clava::ATTRIBUTES[] = { "SetTypestate", "SharedTrylockFunction", "SpeculativeLoadHardening", + "StandaloneDebug", "StrictFP", "SwiftAsync", + "SwiftAsyncError", "SwiftAsyncName", "SwiftAttr", "SwiftBridge", @@ -278,6 +301,7 @@ extern const std::string clava::ATTRIBUTES[] = { "SwiftPrivate", "TLSModel", "Target", + "TargetClones", "TestTypestate", "TransparentUnion", "TrivialABI", @@ -288,6 +312,7 @@ extern const std::string clava::ATTRIBUTES[] = { "Uninitialized", "Unused", "Used", + "UsingIfExists", "Uuid", "VecReturn", "VecTypeHint", @@ -304,9 +329,11 @@ extern const std::string clava::ATTRIBUTES[] = { "X86ForceAlignArgPointer", "XRayInstrument", "XRayLogArgs", + "ZeroCallUsedRegs", "AbiTag", "Alias", "AlignValue", + "BuiltinAlias", "CalledOnce", "IFunc", "InitSeg", diff --git a/ClangAstDumper/enums_OperationKinds_h.cpp b/ClangAstDumper/enums_OperationKinds_h.cpp index 1f44b781c..bd50d2f85 100644 --- a/ClangAstDumper/enums_OperationKinds_h.cpp +++ b/ClangAstDumper/enums_OperationKinds_h.cpp @@ -26,6 +26,7 @@ extern const std::string clava::CAST_KIND[] = { "PointerToIntegral", "PointerToBoolean", "ToVoid", + "MatrixCast", "VectorSplat", "IntegralCast", "IntegralToBoolean", diff --git a/ClangAstDumper/enums_Specifiers_h.cpp b/ClangAstDumper/enums_Specifiers_h.cpp index 474936fb0..9fa228124 100644 --- a/ClangAstDumper/enums_Specifiers_h.cpp +++ b/ClangAstDumper/enums_Specifiers_h.cpp @@ -16,6 +16,7 @@ extern const std::string clava::CALLING_CONVENTION[] = { "SpirFunction", "OpenCLKernel", "Swift", + "SwiftAsync", "PreserveMost", "PreserveAll", "AArch64VectorCall", diff --git a/ClangAstDumper/enums_Type_h.cpp b/ClangAstDumper/enums_Type_h.cpp index f92cf2d06..b00e7d182 100644 --- a/ClangAstDumper/enums_Type_h.cpp +++ b/ClangAstDumper/enums_Type_h.cpp @@ -100,6 +100,72 @@ extern const std::string clava::BUILTIN_KIND[] = { "SveBool", "VectorQuad", "VectorPair", + "RvvInt8mf8", + "RvvInt8mf4", + "RvvInt8mf2", + "RvvInt8m1", + "RvvInt8m2", + "RvvInt8m4", + "RvvInt8m8", + "RvvUint8mf8", + "RvvUint8mf4", + "RvvUint8mf2", + "RvvUint8m1", + "RvvUint8m2", + "RvvUint8m4", + "RvvUint8m8", + "RvvInt16mf4", + "RvvInt16mf2", + "RvvInt16m1", + "RvvInt16m2", + "RvvInt16m4", + "RvvInt16m8", + "RvvUint16mf4", + "RvvUint16mf2", + "RvvUint16m1", + "RvvUint16m2", + "RvvUint16m4", + "RvvUint16m8", + "RvvInt32mf2", + "RvvInt32m1", + "RvvInt32m2", + "RvvInt32m4", + "RvvInt32m8", + "RvvUint32mf2", + "RvvUint32m1", + "RvvUint32m2", + "RvvUint32m4", + "RvvUint32m8", + "RvvInt64m1", + "RvvInt64m2", + "RvvInt64m4", + "RvvInt64m8", + "RvvUint64m1", + "RvvUint64m2", + "RvvUint64m4", + "RvvUint64m8", + "RvvFloat16mf4", + "RvvFloat16mf2", + "RvvFloat16m1", + "RvvFloat16m2", + "RvvFloat16m4", + "RvvFloat16m8", + "RvvFloat32mf2", + "RvvFloat32m1", + "RvvFloat32m2", + "RvvFloat32m4", + "RvvFloat32m8", + "RvvFloat64m1", + "RvvFloat64m2", + "RvvFloat64m4", + "RvvFloat64m8", + "RvvBool1", + "RvvBool2", + "RvvBool4", + "RvvBool8", + "RvvBool16", + "RvvBool32", + "RvvBool64", "Void", "Bool", "Char_U", @@ -152,6 +218,7 @@ extern const std::string clava::BUILTIN_KIND[] = { "Float16", "BFloat16", "Float128", + "Ibm128", "NullPtr", "ObjCId", "ObjCClass", @@ -191,20 +258,20 @@ extern const std::string clava::UTT_KIND[] = { }; extern const std::string clava::ELABORATED_TYPE_KEYWORD[] = { - "STRUCT", - "INTERFACE", - "UNION", - "CLASS", - "ENUM", - "TYPENAME", - "NONE", + "Struct", + "Interface", + "Union", + "Class", + "Enum", + "Typename", + "None", }; extern const std::string clava::TAG_KIND[] = { - "STRUCT", - "INTERFACE", - "UNION", - "CLASS", - "ENUM", + "Struct", + "Interface", + "Union", + "Class", + "Enum", }; From 8aa55978e328b0989d06908d2a58472c5c2b3b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sat, 18 Feb 2023 23:04:15 +0000 Subject: [PATCH 08/68] [ClangAstDumper] Adds support for attribute TypeVisibilityAttr --- ClangAstDumper/ClavaConstants.cpp | 1 + ClangAstDumper/ClavaConstants.h | 1 + ClangAstDumper/ClavaDataDumper.h | 1 + ClangAstDumper/ClavaDataDumperAttrs.cpp | 13 ++++++++++++- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ClangAstDumper/ClavaConstants.cpp b/ClangAstDumper/ClavaConstants.cpp index eb39c9d70..426d4327f 100644 --- a/ClangAstDumper/ClavaConstants.cpp +++ b/ClangAstDumper/ClavaConstants.cpp @@ -145,6 +145,7 @@ const std::string clava::getName(const AttrNode attrNode) { case clava::AttrNode::FORMAT: return "FormatAttr"; case clava::AttrNode::NON_NULL: return "NonNullAttr"; case clava::AttrNode::VISIBILITY: return "VisibilityAttr"; + case clava::AttrNode::TYPE_VISIBILITY: return "TypeVisibilityAttr"; default: { std::string enumValue = std::to_string(static_cast::type>(attrNode)); diff --git a/ClangAstDumper/ClavaConstants.h b/ClangAstDumper/ClavaConstants.h index 60ad11260..4a363b0e8 100644 --- a/ClangAstDumper/ClavaConstants.h +++ b/ClangAstDumper/ClavaConstants.h @@ -155,6 +155,7 @@ namespace clava { FORMAT, NON_NULL, VISIBILITY, + TYPE_VISIBILITY, }; diff --git a/ClangAstDumper/ClavaDataDumper.h b/ClangAstDumper/ClavaDataDumper.h index c1f3db1e5..c5730461b 100644 --- a/ClangAstDumper/ClavaDataDumper.h +++ b/ClangAstDumper/ClavaDataDumper.h @@ -239,6 +239,7 @@ namespace clava { void DumpFormatAttrData(const FormatAttr *A); void DumpNonNullAttrData(const NonNullAttr *A); void DumpVisibilityAttrData(const VisibilityAttr *A); + void DumpTypeVisibilityAttrData(const TypeVisibilityAttr *A); const std::string getDataName(DeclNode node); const std::string getDataName(StmtNode node); const std::string getDataName(TypeNode node); diff --git a/ClangAstDumper/ClavaDataDumperAttrs.cpp b/ClangAstDumper/ClavaDataDumperAttrs.cpp index dd3ab6c0c..ffcd0f4b0 100644 --- a/ClangAstDumper/ClavaDataDumperAttrs.cpp +++ b/ClangAstDumper/ClavaDataDumperAttrs.cpp @@ -15,6 +15,8 @@ const std::map clava::ATTR_DATA_MAP = { {"FormatAttr", clava::AttrNode::FORMAT}, {"NonNullAttr", clava::AttrNode::NON_NULL}, {"VisibilityAttr", clava::AttrNode::VISIBILITY}, + {"TypeVisibilityAttr", clava::AttrNode::TYPE_VISIBILITY}, + }; @@ -52,6 +54,8 @@ void clava::ClavaDataDumper::dump(clava::AttrNode attrNode, const Attr* A) { DumpNonNullAttrData(static_cast(A)); break; case clava::AttrNode::VISIBILITY: DumpVisibilityAttrData(static_cast(A)); break; + case clava::AttrNode::TYPE_VISIBILITY: + DumpTypeVisibilityAttrData(static_cast(A)); break; default: throw std::invalid_argument("ClangDataDumper::dump(DeclNode):: Case not implemented, '" + getName(attrNode) + "'"); } @@ -121,4 +125,11 @@ void clava::ClavaDataDumper::DumpVisibilityAttrData(const VisibilityAttr *A) { DumpAttrData(A); clava::dump(clava::VISIBILITY_ATTR_TYPE[A->getVisibility()]); -} \ No newline at end of file +} + +void clava::ClavaDataDumper::DumpTypeVisibilityAttrData(const TypeVisibilityAttr *A) { + // Common + DumpAttrData(A); + + clava::dump(clava::VISIBILITY_ATTR_TYPE[A->getVisibility()]); +} From fb1da668a6453054defdd93df2008121d0846665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sun, 19 Feb 2023 01:46:34 +0000 Subject: [PATCH 09/68] [ClavaAst] Updates several enums --- .../clava/ast/type/enums/BuiltinKind.java | 67 +++++++++++++++++++ .../ast/type/enums/CallingConvention.java | 1 + .../ast/type/enums/ElaboratedTypeKeyword.java | 5 +- .../up/fe/specs/clava/language/CastKind.java | 1 + .../up/fe/specs/clava/language/TagKind.java | 4 +- 5 files changed, 75 insertions(+), 3 deletions(-) diff --git a/ClavaAst/src/pt/up/fe/specs/clava/ast/type/enums/BuiltinKind.java b/ClavaAst/src/pt/up/fe/specs/clava/ast/type/enums/BuiltinKind.java index 181b5d26b..f4a94498e 100644 --- a/ClavaAst/src/pt/up/fe/specs/clava/ast/type/enums/BuiltinKind.java +++ b/ClavaAst/src/pt/up/fe/specs/clava/ast/type/enums/BuiltinKind.java @@ -124,6 +124,72 @@ public enum BuiltinKind { SveBool, VectorQuad, VectorPair, + RvvInt8mf8, + RvvInt8mf4, + RvvInt8mf2, + RvvInt8m1, + RvvInt8m2, + RvvInt8m4, + RvvInt8m8, + RvvUint8mf8, + RvvUint8mf4, + RvvUint8mf2, + RvvUint8m1, + RvvUint8m2, + RvvUint8m4, + RvvUint8m8, + RvvInt16mf4, + RvvInt16mf2, + RvvInt16m1, + RvvInt16m2, + RvvInt16m4, + RvvInt16m8, + RvvUint16mf4, + RvvUint16mf2, + RvvUint16m1, + RvvUint16m2, + RvvUint16m4, + RvvUint16m8, + RvvInt32mf2, + RvvInt32m1, + RvvInt32m2, + RvvInt32m4, + RvvInt32m8, + RvvUint32mf2, + RvvUint32m1, + RvvUint32m2, + RvvUint32m4, + RvvUint32m8, + RvvInt64m1, + RvvInt64m2, + RvvInt64m4, + RvvInt64m8, + RvvUint64m1, + RvvUint64m2, + RvvUint64m4, + RvvUint64m8, + RvvFloat16mf4, + RvvFloat16mf2, + RvvFloat16m1, + RvvFloat16m2, + RvvFloat16m4, + RvvFloat16m8, + RvvFloat32mf2, + RvvFloat32m1, + RvvFloat32m2, + RvvFloat32m4, + RvvFloat32m8, + RvvFloat64m1, + RvvFloat64m2, + RvvFloat64m4, + RvvFloat64m8, + RvvBool1, + RvvBool2, + RvvBool4, + RvvBool8, + RvvBool16, + RvvBool32, + RvvBool64, Void, Bool, Char_U, @@ -176,6 +242,7 @@ public enum BuiltinKind { Float16, BFloat16, Float128, + Ibm128, NullPtr, ObjCId, ObjCClass, diff --git a/ClavaAst/src/pt/up/fe/specs/clava/ast/type/enums/CallingConvention.java b/ClavaAst/src/pt/up/fe/specs/clava/ast/type/enums/CallingConvention.java index 3ff61eaa9..ec4f8d82f 100644 --- a/ClavaAst/src/pt/up/fe/specs/clava/ast/type/enums/CallingConvention.java +++ b/ClavaAst/src/pt/up/fe/specs/clava/ast/type/enums/CallingConvention.java @@ -34,6 +34,7 @@ public enum CallingConvention implements StringProvider { SpirFunction, OpenCLKernel, Swift, + SwiftAsync, PreserveMost, PreserveAll, AArch64VectorCall; diff --git a/ClavaAst/src/pt/up/fe/specs/clava/ast/type/enums/ElaboratedTypeKeyword.java b/ClavaAst/src/pt/up/fe/specs/clava/ast/type/enums/ElaboratedTypeKeyword.java index 4598aa9f8..3332d831b 100644 --- a/ClavaAst/src/pt/up/fe/specs/clava/ast/type/enums/ElaboratedTypeKeyword.java +++ b/ClavaAst/src/pt/up/fe/specs/clava/ast/type/enums/ElaboratedTypeKeyword.java @@ -13,6 +13,7 @@ package pt.up.fe.specs.clava.ast.type.enums; +import pt.up.fe.specs.util.SpecsStrings; import pt.up.fe.specs.util.enums.EnumHelperWithValue; import pt.up.fe.specs.util.lazy.Lazy; import pt.up.fe.specs.util.providers.StringProvider; @@ -27,7 +28,7 @@ public enum ElaboratedTypeKeyword implements StringProvider { NONE; private static final Lazy> HELPER = EnumHelperWithValue - .newLazyHelperWithValue(ElaboratedTypeKeyword.class, NONE); + .newLazyHelperWithValue(ElaboratedTypeKeyword.class); public static EnumHelperWithValue getHelper() { return HELPER.get(); @@ -43,6 +44,6 @@ public String getCode() { @Override public String getString() { - return name().toLowerCase(); + return SpecsStrings.toCamelCase(name()); } } \ No newline at end of file diff --git a/ClavaAst/src/pt/up/fe/specs/clava/language/CastKind.java b/ClavaAst/src/pt/up/fe/specs/clava/language/CastKind.java index ef6c0ee19..ce34afc8b 100644 --- a/ClavaAst/src/pt/up/fe/specs/clava/language/CastKind.java +++ b/ClavaAst/src/pt/up/fe/specs/clava/language/CastKind.java @@ -44,6 +44,7 @@ public enum CastKind implements StringProvider { PointerToIntegral, PointerToBoolean, ToVoid, + MatrixCast, VectorSplat, IntegralCast, IntegralToBoolean, diff --git a/ClavaAst/src/pt/up/fe/specs/clava/language/TagKind.java b/ClavaAst/src/pt/up/fe/specs/clava/language/TagKind.java index f4e695739..736d74fa6 100644 --- a/ClavaAst/src/pt/up/fe/specs/clava/language/TagKind.java +++ b/ClavaAst/src/pt/up/fe/specs/clava/language/TagKind.java @@ -13,6 +13,7 @@ package pt.up.fe.specs.clava.language; +import pt.up.fe.specs.util.SpecsStrings; import pt.up.fe.specs.util.enums.EnumHelperWithValue; import pt.up.fe.specs.util.lazy.Lazy; import pt.up.fe.specs.util.providers.StringProvider; @@ -49,6 +50,7 @@ public String getCode() { @Override public String getString() { - return getCode(); + return SpecsStrings.toCamelCase(name()); + // return getCode(); } } \ No newline at end of file From 651d16c96fc6af186daf42476a1048f6e66a6d3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sun, 19 Feb 2023 01:49:25 +0000 Subject: [PATCH 10/68] [ClavaAst] Adds new nodes --- .../clava/ast/decl/BuiltinTemplateDecl.java | 28 +++++++++++++++++++ .../fe/specs/clava/ast/decl/ConceptDecl.java | 28 +++++++++++++++++++ .../up/fe/specs/clava/ast/type/UsingType.java | 28 +++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 ClavaAst/src/pt/up/fe/specs/clava/ast/decl/BuiltinTemplateDecl.java create mode 100644 ClavaAst/src/pt/up/fe/specs/clava/ast/decl/ConceptDecl.java create mode 100644 ClavaAst/src/pt/up/fe/specs/clava/ast/type/UsingType.java diff --git a/ClavaAst/src/pt/up/fe/specs/clava/ast/decl/BuiltinTemplateDecl.java b/ClavaAst/src/pt/up/fe/specs/clava/ast/decl/BuiltinTemplateDecl.java new file mode 100644 index 000000000..3757e4e17 --- /dev/null +++ b/ClavaAst/src/pt/up/fe/specs/clava/ast/decl/BuiltinTemplateDecl.java @@ -0,0 +1,28 @@ +/** + * Copyright 2023 SPeCS. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. under the License. + */ + +package pt.up.fe.specs.clava.ast.decl; + +import java.util.Collection; + +import org.suikasoft.jOptions.Interfaces.DataStore; + +import pt.up.fe.specs.clava.ClavaNode; + +public class BuiltinTemplateDecl extends TemplateDecl { + + public BuiltinTemplateDecl(DataStore data, Collection children) { + super(data, children); + } + +} diff --git a/ClavaAst/src/pt/up/fe/specs/clava/ast/decl/ConceptDecl.java b/ClavaAst/src/pt/up/fe/specs/clava/ast/decl/ConceptDecl.java new file mode 100644 index 000000000..364984227 --- /dev/null +++ b/ClavaAst/src/pt/up/fe/specs/clava/ast/decl/ConceptDecl.java @@ -0,0 +1,28 @@ +/** + * Copyright 2023 SPeCS. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. under the License. + */ + +package pt.up.fe.specs.clava.ast.decl; + +import java.util.Collection; + +import org.suikasoft.jOptions.Interfaces.DataStore; + +import pt.up.fe.specs.clava.ClavaNode; + +public class ConceptDecl extends TemplateDecl { + + public ConceptDecl(DataStore data, Collection children) { + super(data, children); + } + +} diff --git a/ClavaAst/src/pt/up/fe/specs/clava/ast/type/UsingType.java b/ClavaAst/src/pt/up/fe/specs/clava/ast/type/UsingType.java new file mode 100644 index 000000000..4c5fea44b --- /dev/null +++ b/ClavaAst/src/pt/up/fe/specs/clava/ast/type/UsingType.java @@ -0,0 +1,28 @@ +/** + * Copyright 2023 SPeCS. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. under the License. + */ + +package pt.up.fe.specs.clava.ast.type; + +import java.util.Collection; + +import org.suikasoft.jOptions.Interfaces.DataStore; + +import pt.up.fe.specs.clava.ClavaNode; + +public class UsingType extends Type { + + public UsingType(DataStore data, Collection children) { + super(data, children); + } + +} From 4d41db17ca522406094b40f541ba59308e193a95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sun, 19 Feb 2023 01:50:14 +0000 Subject: [PATCH 11/68] [ClangAstParser] Moves tests that do not pass yet to their own package --- .../clang/parser/testers/ClangCTester.java | 122 ++++++++++++++++++ .../clang/parser/testers/ClangCxxTester.java | 48 +++++++ .../parser/testers/CxxProblematicTester.java | 90 +++++++++++++ 3 files changed, 260 insertions(+) create mode 100644 ClangAstParser/test/eu/antarex/clang/parser/testers/ClangCTester.java create mode 100644 ClangAstParser/test/eu/antarex/clang/parser/testers/ClangCxxTester.java create mode 100644 ClangAstParser/test/eu/antarex/clang/parser/testers/CxxProblematicTester.java diff --git a/ClangAstParser/test/eu/antarex/clang/parser/testers/ClangCTester.java b/ClangAstParser/test/eu/antarex/clang/parser/testers/ClangCTester.java new file mode 100644 index 000000000..502c1c0e8 --- /dev/null +++ b/ClangAstParser/test/eu/antarex/clang/parser/testers/ClangCTester.java @@ -0,0 +1,122 @@ +/** + * Copyright 2017 SPeCS. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. under the License. + */ + +package eu.antarex.clang.parser.testers; + +import org.junit.After; +import org.junit.BeforeClass; +import org.junit.Test; + +import eu.antarex.clang.parser.AClangAstTester; +import eu.antarex.clang.parser.ClangTester; + +public class ClangCTester { + + @BeforeClass + public static void setup() throws Exception { + AClangAstTester.clear(); + } + + @After + public void tearDown() throws Exception { + AClangAstTester.clear(); + } + + @Test + public void testCAttr() { + new ClangTester("c/ast-dump-c-attr.c") + .addFlags("-fdouble-square-bracket-attributes", "-Wno-deprecated-declarations") + .test(); + } + + @Test + public void testExpr() { + new ClangTester("c/ast-dump-expr.c").addFlags("-Wno-unused-value", "-std=gnu11").test(); + } + + @Test + public void testRecords() { + new ClangTester("c/ast-dump-records.c").test(); + } + + @Test + public void testStmt() { + new ClangTester("c/ast-dump-stmt.c").addFlags("-std=gnu11").test(); + } + + @Test + public void testBoolAsCBool() { + new ClangTester("c/ast-print-bool.c").addFlags("-DDEF_BOOL_CBOOL").test(); + } + + @Test + public void testBoolAsInt() { + new ClangTester("c/ast-print-bool.c").addFlags("-DDEF_BOOL_INT").test(); + } + + @Test + public void testEnumDecl() { + new ClangTester("c/ast-print-enum-decl.c").test(); + } + + @Test + public void testRecordDeclStruct() { + new ClangTester("c/ast-print-record-decl.c").addFlags("-DKW=struct", "-DBASES=").test(); + } + + @Test + public void testRecordDeclUnion() { + new ClangTester("c/ast-print-record-decl.c").addFlags("-DKW=union", "-DBASES=").test(); + } + + @Test + public void testAttrTarget() { + new ClangTester("c/attr-target-ast.c").test(); + } + + @Test + public void testCCasts() { + new ClangTester("c/c-casts.c").test(); + } + + @Test + public void testFixedPointToString() { + new ClangTester("c/fixed_point_to_string.c").addFlags("-ffixed-point").test(); + } + + @Test + public void testFixedPoint() { + new ClangTester("c/fixed_point.c").addFlags("-ffixed-point").test(); + } + + @Test + public void testImplicitCast() { + new ClangTester("c/implicit-cast-dump.c").test(); + } + + @Test + public void testMultistepExplicitCast() { + new ClangTester("c/multistep-explicit-cast.c").test(); + } + + @Test + public void testUnorderedComparePromote() { + new ClangTester("c/rdr6094103-unordered-compare-promote.c").test(); + } + + @Test + public void testVariadicPromotion() { + new ClangTester("c/variadic-promotion.c").test(); + } + +} diff --git a/ClangAstParser/test/eu/antarex/clang/parser/testers/ClangCxxTester.java b/ClangAstParser/test/eu/antarex/clang/parser/testers/ClangCxxTester.java new file mode 100644 index 000000000..e4b800dcd --- /dev/null +++ b/ClangAstParser/test/eu/antarex/clang/parser/testers/ClangCxxTester.java @@ -0,0 +1,48 @@ +/** + * Copyright 2017 SPeCS. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. under the License. + */ + +package eu.antarex.clang.parser.testers; + +import org.junit.After; +import org.junit.BeforeClass; +import org.junit.Test; + +import eu.antarex.clang.parser.AClangAstTester; +import eu.antarex.clang.parser.ClangTester; + +public class ClangCxxTester { + + @BeforeClass + public static void setup() throws Exception { + AClangAstTester.clear(); + } + + @After + public void tearDown() throws Exception { + AClangAstTester.clear(); + } + + private static AClangAstTester newClangCxxTester(String... files) { + return new ClangTester(files).addFlags("-std=c++11"); + } + + @Test + public void testBool() { + newClangCxxTester("cxx/ast-print-bool.c").test(); + } + + @Test + public void testRecordDeclStruct() { + newClangCxxTester("cxx/ast-print-record-decl.c").addFlags("-DKW=struct", "-DBASES=\" : B\"").test(); + } +} diff --git a/ClangAstParser/test/eu/antarex/clang/parser/testers/CxxProblematicTester.java b/ClangAstParser/test/eu/antarex/clang/parser/testers/CxxProblematicTester.java new file mode 100644 index 000000000..c378df7de --- /dev/null +++ b/ClangAstParser/test/eu/antarex/clang/parser/testers/CxxProblematicTester.java @@ -0,0 +1,90 @@ +/** + * Copyright 2017 SPeCS. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. under the License. + */ + +package eu.antarex.clang.parser.testers; + +import org.junit.After; +import org.junit.BeforeClass; +import org.junit.Test; + +import eu.antarex.clang.parser.AClangAstTester; +import eu.antarex.clang.parser.CxxTester; + +public class CxxProblematicTester { + + @BeforeClass + public static void setup() throws Exception { + AClangAstTester.clear(); + } + + @After + public void tearDown() throws Exception { + AClangAstTester.clear(); + } + + @Test + public void testBoost() { + // Jenkins machine does not have boost installed + new CxxTester("boost.cpp").test(); + } + + @Test + public void testOperator() { + // GCC on Jenkins machine does not support .operator bool() + new CxxTester("problematic/operator.cpp").test(); + } + + @Test + public void testClasses() { + // Unimplemented features + new CxxTester("classes.cpp").test(); + } + + // @Test + // public void testLambda() { + // // Lambdas not implemented + // // Reference for tests: https://msdn.microsoft.com/en-us/library/dd293608.aspx + // new CxxTester("lambda.cpp") + // .addFlags("-std=c++14") + // .test(); + // } + + @Test + public void testTemplateAuto() { + // FieldDeclParser, consumes name but has no name + new CxxTester("problematic/template_auto.cpp").test(); + } + + @Test + public void testImplicitReference() { + // FieldDeclParser, consumes name but has no name + new CxxTester("problematic/implicit_reference.cpp").test(); + } + + @Test + public void testSortedId() { + new CxxTester("bench/sorted_id.cpp", "bench/sorted_id.h").test(); + } + + @Test + public void testDummy() { + new CxxTester("problematic/dummy.cpp").showClavaAst().test(); + // onePass().showCode().showClangAst().showClavaAst() + } + + @Test + public void testMsAsm() { + new CxxTester("problematic/ms_asm.c").addFlags("-fasm-blocks").onePass().showCode().test(); + } + +} From 6f68a1dd32a303fc248c45db4d55bf0accd30928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sun, 19 Feb 2023 01:50:44 +0000 Subject: [PATCH 12/68] [ClangAstParser] Updates C++ test 'Decl' --- ClangAstParser/resources/cxx/decl.cpp.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ClangAstParser/resources/cxx/decl.cpp.txt b/ClangAstParser/resources/cxx/decl.cpp.txt index 388122c0f..bf6b9dab1 100644 --- a/ClangAstParser/resources/cxx/decl.cpp.txt +++ b/ClangAstParser/resources/cxx/decl.cpp.txt @@ -3,8 +3,8 @@ #include #include -int nullGlobal = 0; -int nullGlobal2 = 0 + 1; +int nullGlobal = 0LL; +int nullGlobal2 = 0LL + 1; class A { static int constexpr constexprInt = 3; From 32348677d0b851a96365ec1de05512b3c2f5cc6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sun, 19 Feb 2023 01:57:20 +0000 Subject: [PATCH 13/68] [ClangAstDumper] Fixes dumping of attributes names --- ClangAstDumper/ClangNodes.cpp | 24 ++++++++++++++++++++++-- ClangAstDumper/ClangNodes.h | 9 +++++++++ ClangAstDumper/ClavaDataDumperAttrs.cpp | 3 +-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/ClangAstDumper/ClangNodes.cpp b/ClangAstDumper/ClangNodes.cpp index d440e706a..83d85c63d 100644 --- a/ClangAstDumper/ClangNodes.cpp +++ b/ClangAstDumper/ClangNodes.cpp @@ -11,7 +11,7 @@ #include - +#include using namespace clang; @@ -30,8 +30,28 @@ const std::string clava::getClassName(const Type* T) { return kindName + "Type"; } +const std::string clava::getAttrKind(const Attr* A) { + // Print information about Attr + //clava::dump(clava::ATTRIBUTES[A->getKind()]); + { + switch (A->getKind()) { +#define ATTR(X) \ + case attr::X: \ + return #X; \ + break; +#include "clang/Basic/AttrList.inc" + } + + } + + return ""; +} + const std::string clava::getClassName(const Attr* A) { - const std::string kindName = clava::ATTRIBUTES[A->getKind()]; + + //const std::string kindName = clava::ATTRIBUTES[A->getKind()]; + const std::string kindName = clava::getAttrKind(A); + return kindName + "Attr"; } diff --git a/ClangAstDumper/ClangNodes.h b/ClangAstDumper/ClangNodes.h index ee738948f..d081c8758 100644 --- a/ClangAstDumper/ClangNodes.h +++ b/ClangAstDumper/ClangNodes.h @@ -46,6 +46,15 @@ namespace clava { */ const std::string getClassName(const Type* T); + /** + * Returns the kind name of the class of the given Attribute. + * + * @param A + * @return + */ + const std::string getAttrKind(const Attr* A); + + /** * Returns the name of the class of the given Attribute. * diff --git a/ClangAstDumper/ClavaDataDumperAttrs.cpp b/ClangAstDumper/ClavaDataDumperAttrs.cpp index ffcd0f4b0..cd3164c4d 100644 --- a/ClangAstDumper/ClavaDataDumperAttrs.cpp +++ b/ClangAstDumper/ClavaDataDumperAttrs.cpp @@ -65,8 +65,7 @@ void clava::ClavaDataDumper::dump(clava::AttrNode attrNode, const Attr* A) { void clava::ClavaDataDumper::DumpAttrData(const Attr *A) { clava::dumpSourceInfo(Context, A->getRange().getBegin(), A->getRange().getEnd()); - // Print information about Attr - clava::dump(clava::ATTRIBUTES[A->getKind()]); + clava::dump(clava::getAttrKind(A)); clava::dump(A->isImplicit()); clava::dump(A->isInherited()); clava::dump(A->isLateParsed()); From 0a12a6e48e6e2c5a7be299a137b702910e45e21f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sun, 19 Feb 2023 02:09:29 +0000 Subject: [PATCH 14/68] [ClangAstParser] Update related to enums --- .../clang/parsers/data/DeclDataParser.java | 2 +- .../clang/parsers/data/TypeDataParser.java | 2 +- .../clava/ast/attr/enums/AttributeKind.java | 38 +++++++++++++++++-- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/ClangAstParser/src/pt/up/fe/specs/clang/parsers/data/DeclDataParser.java b/ClangAstParser/src/pt/up/fe/specs/clang/parsers/data/DeclDataParser.java index 6e39d96c7..ecaa167a8 100644 --- a/ClangAstParser/src/pt/up/fe/specs/clang/parsers/data/DeclDataParser.java +++ b/ClangAstParser/src/pt/up/fe/specs/clang/parsers/data/DeclDataParser.java @@ -161,7 +161,7 @@ public static DataStore parseTagDeclData(LineStream lines, ClangAstData dataStor // data.set(NamedDecl.DECL_NAME, anonName); // } - data.add(TagDecl.TAG_KIND, LineStreamParsers.enumFromName(TagKind.class, lines)); + data.add(TagDecl.TAG_KIND, LineStreamParsers.enumFromName(TagKind.getHelper(), lines)); data.add(TagDecl.IS_COMPLETE_DEFINITION, LineStreamParsers.oneOrZero(lines)); return data; diff --git a/ClangAstParser/src/pt/up/fe/specs/clang/parsers/data/TypeDataParser.java b/ClangAstParser/src/pt/up/fe/specs/clang/parsers/data/TypeDataParser.java index 0544bc8f4..bf8a506c4 100644 --- a/ClangAstParser/src/pt/up/fe/specs/clang/parsers/data/TypeDataParser.java +++ b/ClangAstParser/src/pt/up/fe/specs/clang/parsers/data/TypeDataParser.java @@ -232,7 +232,7 @@ public static DataStore parseTypeWithKeywordData(LineStream lines, ClangAstData DataStore data = parseTypeData(lines, parserData); data.add(TypeWithKeyword.ELABORATED_TYPE_KEYWORD, - LineStreamParsers.enumFromName(ElaboratedTypeKeyword.class, lines)); + LineStreamParsers.enumFromName(ElaboratedTypeKeyword.getHelper(), lines)); return data; } diff --git a/ClavaAst/src/pt/up/fe/specs/clava/ast/attr/enums/AttributeKind.java b/ClavaAst/src/pt/up/fe/specs/clava/ast/attr/enums/AttributeKind.java index f151bce96..96bc6bb6d 100644 --- a/ClavaAst/src/pt/up/fe/specs/clava/ast/attr/enums/AttributeKind.java +++ b/ClavaAst/src/pt/up/fe/specs/clava/ast/attr/enums/AttributeKind.java @@ -26,7 +26,9 @@ public enum AttributeKind implements StringProvider { AddressSpace, + AnnotateType, ArmMveStrictPolymorphism, + BTFTypeTag, CmseNSCall, NoDeref, ObjCGC, @@ -49,10 +51,16 @@ public enum AttributeKind implements StringProvider { UPtr, FallThrough, Likely, + MustTail, + OpenCLUnrollHint, Suppress, Unlikely, + AlwaysInline, + NoInline, NoMerge, + AArch64SVEPcs, AArch64VectorPcs, + AMDGPUKernelCall, AcquireHandle, AnyX86NoCfCheck, CDecl, @@ -68,10 +76,12 @@ public enum AttributeKind implements StringProvider { PreserveMost, RegCall, StdCall, + SwiftAsyncCall, SwiftCall, SysVABI, ThisCall, VectorCall, + SwiftAsyncContext, SwiftContext, SwiftErrorResult, SwiftIndirectResult, @@ -100,7 +110,6 @@ public enum AttributeKind implements StringProvider { AllocAlign, AllocSize, AlwaysDestroy, - AlwaysInline, AnalyzerNoReturn, AnyX86Interrupt, AnyX86NoCallerSavedRegisters, @@ -116,6 +125,7 @@ public enum AttributeKind implements StringProvider { Assumption, Availability, BPFPreserveAccessIndex, + BTFDeclTag, Blocks, Builtin, C11NoReturn, @@ -159,13 +169,16 @@ public enum AttributeKind implements StringProvider { DLLImportStaticLocal, Deprecated, Destructor, + DiagnoseAsBuiltin, DiagnoseIf, + DisableSanitizerInstrumentation, DisableTailCalls, EmptyBases, EnableIf, EnforceTCB, EnforceTCBLeaf, EnumExtensibility, + Error, ExcludeFromExplicitInstantiation, ExclusiveTrylockFunction, ExternalSourceSymbol, @@ -174,10 +187,14 @@ public enum AttributeKind implements StringProvider { Flatten, Format, FormatArg, + FunctionReturnThunks, GNUInline, GuardedBy, GuardedVar, HIPManaged, + HLSLNumThreads, + HLSLSV_GroupIndex, + HLSLShader, Hot, IBAction, IBOutlet, @@ -189,6 +206,7 @@ public enum AttributeKind implements StringProvider { Leaf, LockReturned, LocksExcluded, + M68kInterrupt, MIGServerRoutine, MSAllocator, MSInheritance, @@ -215,10 +233,11 @@ public enum AttributeKind implements StringProvider { NoDebug, NoDestroy, NoDuplicate, - NoInline, NoInstrumentFunction, NoMicroMips, NoMips16, + NoProfileFunction, + NoRandomizeLayout, NoReturn, NoSanitize, NoSpeculativeLoadHardening, @@ -255,7 +274,6 @@ public enum AttributeKind implements StringProvider { ObjCSubclassingRestricted, OpenCLIntelReqdSubGroupSize, OpenCLKernel, - OpenCLUnrollHint, OptimizeNone, Override, Owner, @@ -274,15 +292,18 @@ public enum AttributeKind implements StringProvider { PtGuardedVar, Pure, RISCVInterrupt, + RandomizeLayout, Reinitializes, ReleaseCapability, ReqdWorkGroupSize, RequiresCapability, Restrict, + Retain, ReturnTypestate, ReturnsNonNull, ReturnsTwice, SYCLKernel, + SYCLSpecialClass, ScopedLockable, Section, SelectAny, @@ -290,8 +311,10 @@ public enum AttributeKind implements StringProvider { SetTypestate, SharedTrylockFunction, SpeculativeLoadHardening, + StandaloneDebug, StrictFP, SwiftAsync, + SwiftAsyncError, SwiftAsyncName, SwiftAttr, SwiftBridge, @@ -302,6 +325,7 @@ public enum AttributeKind implements StringProvider { SwiftPrivate, TLSModel, Target, + TargetClones, TestTypestate, TransparentUnion, TrivialABI, @@ -312,6 +336,7 @@ public enum AttributeKind implements StringProvider { Uninitialized, Unused, Used, + UsingIfExists, Uuid, VecReturn, VecTypeHint, @@ -328,9 +353,11 @@ public enum AttributeKind implements StringProvider { X86ForceAlignArgPointer, XRayInstrument, XRayLogArgs, + ZeroCallUsedRegs, AbiTag, Alias, AlignValue, + BuiltinAlias, CalledOnce, IFunc, InitSeg, @@ -407,6 +434,11 @@ private static String toAttributeName(AttributeKind kind) { return name.toLowerCase(); } + // Special case: TypeVisibility attribute is "visibility" + if (kind == TypeVisibility) { + name = Visibility.name(); + } + return SpecsStrings.camelCaseSeparate(name, "_").toLowerCase(); } From 23d17122ab97f720faa5a0c34a9f014fad5eb851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sun, 19 Feb 2023 02:12:35 +0000 Subject: [PATCH 15/68] [ClavaAst] Experiment with attribute code generation --- ClavaAst/src/pt/up/fe/specs/clava/ast/decl/Decl.java | 10 ++++++++-- .../src/pt/up/fe/specs/clava/ast/decl/RecordDecl.java | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ClavaAst/src/pt/up/fe/specs/clava/ast/decl/Decl.java b/ClavaAst/src/pt/up/fe/specs/clava/ast/decl/Decl.java index 45778bd58..9abe84255 100644 --- a/ClavaAst/src/pt/up/fe/specs/clava/ast/decl/Decl.java +++ b/ClavaAst/src/pt/up/fe/specs/clava/ast/decl/Decl.java @@ -84,21 +84,27 @@ public boolean hasAttribute(AttributeKind kind) { } public String getAttributesCode() { + // return getAttributesCode(get(ATTRIBUTES), true, true); + // } + // + // public String getAttributesCode(List attrs, boolean addNewline, boolean ignoreGenericAttrs) { + List attrs = get(ATTRIBUTES); var code = new StringBuilder(); - for (Attribute attr : get(ATTRIBUTES)) { + for (Attribute attr : attrs) { // If generic class, do not generated code for it + // if (ignoreGenericAttrs && attr.getClass().equals(Attribute.class)) { if (attr.getClass().equals(Attribute.class)) { ClavaLog.info( "Attribute '" + attr.getKind() + "' not implemented, not generating code for it"); continue; } - code.append(attr.getCode()); if (attr.getKind().isInline()) { code.append(" "); + // } else if (addNewline) { } else { code.append("\n"); } diff --git a/ClavaAst/src/pt/up/fe/specs/clava/ast/decl/RecordDecl.java b/ClavaAst/src/pt/up/fe/specs/clava/ast/decl/RecordDecl.java index 0ac1b919d..a8a23b45d 100644 --- a/ClavaAst/src/pt/up/fe/specs/clava/ast/decl/RecordDecl.java +++ b/ClavaAst/src/pt/up/fe/specs/clava/ast/decl/RecordDecl.java @@ -85,7 +85,11 @@ protected String getCode(List bases, List te code.append(getTagKind().getCode()); // Add attributes - // recordDeclData.getAttributes().forEach(attr -> code.append(" ").append(attr.getCode())); + // var preAttributes = get(ATTRIBUTES).stream() + // .filter(attr -> !attr.isPostAttr()) + // .collect(Collectors.toList()); + // + // String preAttributesCode = getAttributesCode(preAttributes, false, false); String preAttributesCode = get(ATTRIBUTES).stream() .filter(attr -> !attr.isPostAttr()) From fdece3eb817be05fdc3884e094beaeeb669d4bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sun, 19 Feb 2023 02:16:13 +0000 Subject: [PATCH 16/68] [ClavaAst] Renames TypeVisibilityAttr --- .../{TypeVisibilityAttr.java => TypeVisibilityAttr_.java} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename ClavaAst/src/pt/up/fe/specs/clava/ast/attr/{TypeVisibilityAttr.java => TypeVisibilityAttr_.java} (84%) diff --git a/ClavaAst/src/pt/up/fe/specs/clava/ast/attr/TypeVisibilityAttr.java b/ClavaAst/src/pt/up/fe/specs/clava/ast/attr/TypeVisibilityAttr_.java similarity index 84% rename from ClavaAst/src/pt/up/fe/specs/clava/ast/attr/TypeVisibilityAttr.java rename to ClavaAst/src/pt/up/fe/specs/clava/ast/attr/TypeVisibilityAttr_.java index bc2e23827..e46ffaac6 100644 --- a/ClavaAst/src/pt/up/fe/specs/clava/ast/attr/TypeVisibilityAttr.java +++ b/ClavaAst/src/pt/up/fe/specs/clava/ast/attr/TypeVisibilityAttr_.java @@ -19,9 +19,9 @@ import pt.up.fe.specs.clava.ClavaNode; -public class TypeVisibilityAttr extends InheritableAttr { +public class TypeVisibilityAttr_ extends InheritableAttr { - public TypeVisibilityAttr(DataStore data, Collection children) { + public TypeVisibilityAttr_(DataStore data, Collection children) { super(data, children); } From 2043dd82ecf9c052d36cf2134012bf4ec3075685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sun, 19 Feb 2023 02:16:29 +0000 Subject: [PATCH 17/68] [ClavaAst] Removes TypeVisibilityAttr_ --- .../clava/ast/attr/TypeVisibilityAttr_.java | 28 ------------------- 1 file changed, 28 deletions(-) delete mode 100644 ClavaAst/src/pt/up/fe/specs/clava/ast/attr/TypeVisibilityAttr_.java diff --git a/ClavaAst/src/pt/up/fe/specs/clava/ast/attr/TypeVisibilityAttr_.java b/ClavaAst/src/pt/up/fe/specs/clava/ast/attr/TypeVisibilityAttr_.java deleted file mode 100644 index e46ffaac6..000000000 --- a/ClavaAst/src/pt/up/fe/specs/clava/ast/attr/TypeVisibilityAttr_.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright 2018 SPeCS. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. under the License. - */ - -package pt.up.fe.specs.clava.ast.attr; - -import java.util.Collection; - -import org.suikasoft.jOptions.Interfaces.DataStore; - -import pt.up.fe.specs.clava.ClavaNode; - -public class TypeVisibilityAttr_ extends InheritableAttr { - - public TypeVisibilityAttr_(DataStore data, Collection children) { - super(data, children); - } - -} From d139c815218ee3ab92926e58189bbaa3c9516aa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sun, 19 Feb 2023 02:21:25 +0000 Subject: [PATCH 18/68] [ClangAstDumper] Removes references to TypeVisibilityAttr --- ClangAstDumper/ClangEnums.h | 2 +- ClangAstDumper/ClavaConstants.cpp | 2 +- ClangAstDumper/ClavaConstants.h | 2 +- ClangAstDumper/ClavaDataDumper.h | 2 +- ClangAstDumper/ClavaDataDumperAttrs.cpp | 9 +++++---- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ClangAstDumper/ClangEnums.h b/ClangAstDumper/ClangEnums.h index 56ab18c3b..6a82cbb65 100644 --- a/ClangAstDumper/ClangEnums.h +++ b/ClangAstDumper/ClangEnums.h @@ -18,7 +18,7 @@ namespace clava { /* Clang Enums */ extern const std::string CAST_KIND[]; - extern const std::string ATTRIBUTES[]; + extern const std::string ATTRIBUTES[]; // Deprecated, no not use. Instead, use clava::getAttrKind(const Attr* A) extern const std::string CALLING_CONVENTION[]; extern const std::string REFERENCE_QUALIFIER[]; extern const std::string EXCEPTION_SPECIFICATION_TYPE[]; diff --git a/ClangAstDumper/ClavaConstants.cpp b/ClangAstDumper/ClavaConstants.cpp index 426d4327f..99d373d58 100644 --- a/ClangAstDumper/ClavaConstants.cpp +++ b/ClangAstDumper/ClavaConstants.cpp @@ -145,7 +145,7 @@ const std::string clava::getName(const AttrNode attrNode) { case clava::AttrNode::FORMAT: return "FormatAttr"; case clava::AttrNode::NON_NULL: return "NonNullAttr"; case clava::AttrNode::VISIBILITY: return "VisibilityAttr"; - case clava::AttrNode::TYPE_VISIBILITY: return "TypeVisibilityAttr"; + //case clava::AttrNode::TYPE_VISIBILITY: return "TypeVisibilityAttr"; default: { std::string enumValue = std::to_string(static_cast::type>(attrNode)); diff --git a/ClangAstDumper/ClavaConstants.h b/ClangAstDumper/ClavaConstants.h index 4a363b0e8..a01138b19 100644 --- a/ClangAstDumper/ClavaConstants.h +++ b/ClangAstDumper/ClavaConstants.h @@ -155,7 +155,7 @@ namespace clava { FORMAT, NON_NULL, VISIBILITY, - TYPE_VISIBILITY, + //TYPE_VISIBILITY, }; diff --git a/ClangAstDumper/ClavaDataDumper.h b/ClangAstDumper/ClavaDataDumper.h index c5730461b..967b90e21 100644 --- a/ClangAstDumper/ClavaDataDumper.h +++ b/ClangAstDumper/ClavaDataDumper.h @@ -239,7 +239,7 @@ namespace clava { void DumpFormatAttrData(const FormatAttr *A); void DumpNonNullAttrData(const NonNullAttr *A); void DumpVisibilityAttrData(const VisibilityAttr *A); - void DumpTypeVisibilityAttrData(const TypeVisibilityAttr *A); + //void DumpTypeVisibilityAttrData(const TypeVisibilityAttr *A); const std::string getDataName(DeclNode node); const std::string getDataName(StmtNode node); const std::string getDataName(TypeNode node); diff --git a/ClangAstDumper/ClavaDataDumperAttrs.cpp b/ClangAstDumper/ClavaDataDumperAttrs.cpp index cd3164c4d..1efd82b3f 100644 --- a/ClangAstDumper/ClavaDataDumperAttrs.cpp +++ b/ClangAstDumper/ClavaDataDumperAttrs.cpp @@ -15,7 +15,7 @@ const std::map clava::ATTR_DATA_MAP = { {"FormatAttr", clava::AttrNode::FORMAT}, {"NonNullAttr", clava::AttrNode::NON_NULL}, {"VisibilityAttr", clava::AttrNode::VISIBILITY}, - {"TypeVisibilityAttr", clava::AttrNode::TYPE_VISIBILITY}, + //{"TypeVisibilityAttr", clava::AttrNode::TYPE_VISIBILITY}, }; @@ -54,8 +54,8 @@ void clava::ClavaDataDumper::dump(clava::AttrNode attrNode, const Attr* A) { DumpNonNullAttrData(static_cast(A)); break; case clava::AttrNode::VISIBILITY: DumpVisibilityAttrData(static_cast(A)); break; - case clava::AttrNode::TYPE_VISIBILITY: - DumpTypeVisibilityAttrData(static_cast(A)); break; + //case clava::AttrNode::TYPE_VISIBILITY: + // DumpTypeVisibilityAttrData(static_cast(A)); break; default: throw std::invalid_argument("ClangDataDumper::dump(DeclNode):: Case not implemented, '" + getName(attrNode) + "'"); } @@ -125,10 +125,11 @@ void clava::ClavaDataDumper::DumpVisibilityAttrData(const VisibilityAttr *A) { clava::dump(clava::VISIBILITY_ATTR_TYPE[A->getVisibility()]); } - +/* void clava::ClavaDataDumper::DumpTypeVisibilityAttrData(const TypeVisibilityAttr *A) { // Common DumpAttrData(A); clava::dump(clava::VISIBILITY_ATTR_TYPE[A->getVisibility()]); } + */ From 4ba5e2fda60edcee43b6522e486afe749dbeba88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sun, 19 Feb 2023 02:38:04 +0000 Subject: [PATCH 19/68] [ClangAstParser] Updates web resources for Windows and Ubuntu for v14.0.6 --- .../src/pt/up/fe/specs/clang/ClangAstWebResource.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java b/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java index 5a99ea4c4..74d0120bf 100644 --- a/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java +++ b/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java @@ -25,12 +25,12 @@ static WebResourceProvider create(String resourceUrl) { return WebResourceProvider.newInstance("http://specs.fe.up.pt/resources/clangast/", resourceUrl); } - WebResourceProvider BUILTIN_INCLUDES = create("clang_builtin_includes_v12.0.1.zip", "v12.0.1"); + WebResourceProvider BUILTIN_INCLUDES = create("clang_builtin_includes_v16.0.4.zip", "v16.0.4"); // WebResourceProvider LIBC_CXX = create("libcxx_7.0.1.zip", "v1.0"); - WebResourceProvider LIBC_CXX = create("libc_cxx.zip", "v12.0.1"); + WebResourceProvider LIBC_CXX = create("libc_cxx_v16.0.4.zip", "v16.0.4"); // WebResourceProvider LIBC_CXX_WINDOWS = create("libc_cxx_windows.zip", "v1.0"); - WebResourceProvider LIBC_CXX_WINDOWS = create("libc_cxx_windows.zip_", "v12.0.1"); + WebResourceProvider LIBC_CXX_WINDOWS = create("libc_cxx.zip", "v16.0.4"); // For some reason, on Linux, this file no longer downloads WebResourceProvider CUDA_LIB = create("cudalib.zip_", "v11.3.0"); @@ -39,11 +39,11 @@ static WebResourceProvider create(String resourceUrl) { // WebResourceProvider LIBC_CXX_LINUX = create("libc_cxx_linux.zip", "v1.0"); // WebResourceProvider LIBC_CXX_CENTOS6 = create("libc_cxx_centos6.zip", "v1.0"); - WebResourceProvider WIN_EXE = create("windows/clang_ast.exe", "v12.0.7"); + WebResourceProvider WIN_EXE = create("windows/clang_ast.exe", "v14.0.6_0"); WebResourceProvider WIN_DLL1 = create("windows/libwinpthread-1.dll"); WebResourceProvider WIN_DLL2 = create("windows/zlib1.dll"); - WebResourceProvider LINUX_EXE = create("linux_ubuntu_18/clang_ast", "v12.0.7"); + WebResourceProvider LINUX_EXE = create("linux_ubuntu_18/clang_ast", "v14.0.6_0"); // Disabled while we do not have an updated Odroid WebResourceProvider LINUX_ARMV7_EXE = create("linux_ubuntu_14_armv7/clang_ast", "v4.2.19"); From 677af51c8979fc662ad56a36f8dcea3da455b513 Mon Sep 17 00:00:00 2001 From: "L. Sousa" Date: Sun, 19 Feb 2023 00:24:50 +0000 Subject: [PATCH 20/68] [ClangAstDumper] Specify clang version --- .gitignore | 3 +++ ClangAstDumper/CMakeLists.txt | 5 ++--- ClangAstDumper/clang_enums/CMakeLists.txt | 4 ++-- ClangAstDumper/clang_enums/config.clava | 2 +- ...{Findllvm14.cmake => Findllvm14.0.6.cmake} | 20 +++++++++---------- 5 files changed, 18 insertions(+), 16 deletions(-) rename deps/{Findllvm14.cmake => Findllvm14.0.6.cmake} (90%) diff --git a/.gitignore b/.gitignore index 5cdd1a13e..7d11b2d83 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,9 @@ RemoteSystemsTempFiles/ # Custom ignores # ################## +.vscode +deps/temp + tomJava/ .svn/ sf.eclipse.javacc.prefs diff --git a/ClangAstDumper/CMakeLists.txt b/ClangAstDumper/CMakeLists.txt index fabae8656..88b8dca4e 100644 --- a/ClangAstDumper/CMakeLists.txt +++ b/ClangAstDumper/CMakeLists.txt @@ -15,10 +15,9 @@ include("../deps.cmake") #deps_find_package(llvm3.8 REQUIRED) # LLVM #deps_find_package(llvm7 REQUIRED) # LLVM #deps_find_package(llvm12 REQUIRED) # LLVM -deps_find_package(llvm14 REQUIRED) # LLVM +deps_find_package(llvm14.0.6 REQUIRED) # LLVM -set(COMMON_CXX_FLAGS "-std=c++14 -O3 -Wall -Wno-unused-function") -#set(COMMON_CXX_FLAGS "-std=c++14 -O3 -Wall -Wno-unused-function -fuse-ld=\"C:/Program Files/LLVM/bin/ld.lld.exe\"") +set(COMMON_CXX_FLAGS "-std=c++20 -O3 -Wall -Wno-unused-function") #-D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DVISIT_CHECK #add_definitions(-DOLD_OUTPUT) diff --git a/ClangAstDumper/clang_enums/CMakeLists.txt b/ClangAstDumper/clang_enums/CMakeLists.txt index b1238cb14..eebdeb157 100644 --- a/ClangAstDumper/clang_enums/CMakeLists.txt +++ b/ClangAstDumper/clang_enums/CMakeLists.txt @@ -8,10 +8,10 @@ include("../../deps.cmake") #deps_find_package(llvm3.8 REQUIRED) # LLVM #deps_find_package(llvm7 REQUIRED) # LLVM #deps_find_package(llvm12 REQUIRED) # LLVM -deps_find_package(llvm14 REQUIRED) # LLVM +deps_find_package(llvm14.0.6 REQUIRED) # LLVM # Set base llvm dir -set(LLVM_DIR ${llvm14_DIR}) +set(LLVM_DIR ${llvm14.0.6_DIR}) set(COMMON_CXX_FLAGS "-O3 -Wall -Wno-unused-function") diff --git a/ClangAstDumper/clang_enums/config.clava b/ClangAstDumper/clang_enums/config.clava index 0aab5c824..8ffbc5845 100644 --- a/ClangAstDumper/clang_enums/config.clava +++ b/ClangAstDumper/clang_enums/config.clava @@ -131,7 +131,7 @@ argv - {"llvmFolder":"C:/Users/JBispo/Work/Repos/Lab/clava/deps/deps-lib/../artifacts/llvm14-Windows-gcc5"} + {"llvmFolder":"C:/Users/JBispo/Work/Repos/Lab/clava/deps/deps-lib/../artifacts/llvm14.0.6-Windows-gcc5"} tools diff --git a/deps/Findllvm14.cmake b/deps/Findllvm14.0.6.cmake similarity index 90% rename from deps/Findllvm14.cmake rename to deps/Findllvm14.0.6.cmake index df2d26680..edbf63158 100644 --- a/deps/Findllvm14.cmake +++ b/deps/Findllvm14.0.6.cmake @@ -1,13 +1,13 @@ cmake_minimum_required(VERSION 3.2) # Download library -deps_resolve("llvm14" LIB_DIR) +deps_resolve("llvm14.0.6" LIB_DIR) # Expose LLVM library -set("llvm14_DIR" ${LIB_DIR}) +set("llvm14.0.6_DIR" ${LIB_DIR}) # LLVM requires C++11 -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20") if(UNIX) # Unix version uses pre-build clang binaries, which disable rtti @@ -16,7 +16,7 @@ endif() #LLVM and Clang includes -list(APPEND llvm14_INCLUDES +list(APPEND llvm14.0.6_INCLUDES "${LIB_DIR}/src/include" "${LIB_DIR}/build/include" ) @@ -45,8 +45,8 @@ endif() -#find_libraries(llvm14_LIBRARIES "${LIB_DIR}/build/lib" -list(APPEND llvm14_LIBRARIES +#find_libraries(llvm14.0.6_LIBRARIES "${LIB_DIR}/build/lib" +list(APPEND llvm14.0.6_LIBRARIES # Clang libraries, they have circular dependencies, so they are inside a group ${LINKER_GROUP_START} @@ -166,7 +166,7 @@ list(APPEND llvm14_LIBRARIES LLVMBinaryFormat LLVMTableGen LLVMSupport - LLVMDemangle + LLVMDemangle ) @@ -174,7 +174,7 @@ list(APPEND llvm14_LIBRARIES if(UNIX AND NOT APPLE) # Generic UNIX dependencies - list(APPEND llvm14_LIBRARIES + list(APPEND llvm14.0.6_LIBRARIES rt tinfo z @@ -183,7 +183,7 @@ if(UNIX AND NOT APPLE) ) elseif(APPLE) # macOS dependencies - list(APPEND llvm14_LIBRARIES + list(APPEND llvm14.0.6_LIBRARIES c++abi #stdc++ z @@ -193,7 +193,7 @@ elseif(APPLE) ) elseif(WIN32) # Windows dependencies - list(APPEND llvm14_LIBRARIES + list(APPEND llvm14.0.6_LIBRARIES version z ) From 52117cb84b83fd735898f79bc410330fa9ddd691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bi=5B=5Dspo?= Date: Sun, 19 Feb 2023 02:45:01 +0000 Subject: [PATCH 21/68] [ClangAstParser] Fixes libcxx web resource for Linux --- .../src/pt/up/fe/specs/clang/ClangAstWebResource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java b/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java index 74d0120bf..c9d1a03d4 100644 --- a/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java +++ b/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java @@ -27,7 +27,7 @@ static WebResourceProvider create(String resourceUrl) { WebResourceProvider BUILTIN_INCLUDES = create("clang_builtin_includes_v16.0.4.zip", "v16.0.4"); // WebResourceProvider LIBC_CXX = create("libcxx_7.0.1.zip", "v1.0"); - WebResourceProvider LIBC_CXX = create("libc_cxx_v16.0.4.zip", "v16.0.4"); + WebResourceProvider LIBC_CXX = create("libc_cxx.zip", "v16.0.4"); // WebResourceProvider LIBC_CXX_WINDOWS = create("libc_cxx_windows.zip", "v1.0"); WebResourceProvider LIBC_CXX_WINDOWS = create("libc_cxx.zip", "v16.0.4"); From 58c9bd6c7433f96b7390d9ea922dbdb27ae75a55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sun, 19 Feb 2023 02:53:51 +0000 Subject: [PATCH 22/68] [ClangAstParser] Fixes versions of libc and libcxx --- .../src/pt/up/fe/specs/clang/ClangAstWebResource.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java b/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java index c9d1a03d4..c70308e65 100644 --- a/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java +++ b/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java @@ -25,12 +25,12 @@ static WebResourceProvider create(String resourceUrl) { return WebResourceProvider.newInstance("http://specs.fe.up.pt/resources/clangast/", resourceUrl); } - WebResourceProvider BUILTIN_INCLUDES = create("clang_builtin_includes_v16.0.4.zip", "v16.0.4"); + WebResourceProvider BUILTIN_INCLUDES = create("clang_builtin_includes_v14.0.6.zip", "v14.0.6"); // WebResourceProvider LIBC_CXX = create("libcxx_7.0.1.zip", "v1.0"); - WebResourceProvider LIBC_CXX = create("libc_cxx.zip", "v16.0.4"); + WebResourceProvider LIBC_CXX = create("libc_cxx.zip", "v14.0.6"); // WebResourceProvider LIBC_CXX_WINDOWS = create("libc_cxx_windows.zip", "v1.0"); - WebResourceProvider LIBC_CXX_WINDOWS = create("libc_cxx.zip", "v16.0.4"); + WebResourceProvider LIBC_CXX_WINDOWS = create("libc_cxx.zip", "v14.0.6"); // For some reason, on Linux, this file no longer downloads WebResourceProvider CUDA_LIB = create("cudalib.zip_", "v11.3.0"); From 2c2a7171eba18becd039b5c8b121027e3035a958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sun, 19 Feb 2023 03:19:31 +0000 Subject: [PATCH 23/68] [ClangAstParser] Updates builtins web resources --- .../src/pt/up/fe/specs/clang/ClangAstWebResource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java b/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java index c70308e65..6f3abc94e 100644 --- a/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java +++ b/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java @@ -25,7 +25,7 @@ static WebResourceProvider create(String resourceUrl) { return WebResourceProvider.newInstance("http://specs.fe.up.pt/resources/clangast/", resourceUrl); } - WebResourceProvider BUILTIN_INCLUDES = create("clang_builtin_includes_v14.0.6.zip", "v14.0.6"); + WebResourceProvider BUILTIN_INCLUDES = create("clang_builtin_includes_v14.0.6.zip_", "v14.0.6_2"); // WebResourceProvider LIBC_CXX = create("libcxx_7.0.1.zip", "v1.0"); WebResourceProvider LIBC_CXX = create("libc_cxx.zip", "v14.0.6"); From 4885b5e68144142a91662349773e056cb95d4ff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sun, 19 Feb 2023 03:20:26 +0000 Subject: [PATCH 24/68] [deps] Updates clang instructions --- deps/deps-lib/build-instructions/LLVM-Clang.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/deps/deps-lib/build-instructions/LLVM-Clang.txt b/deps/deps-lib/build-instructions/LLVM-Clang.txt index 8fa5b590a..a5404dbfb 100644 --- a/deps/deps-lib/build-instructions/LLVM-Clang.txt +++ b/deps/deps-lib/build-instructions/LLVM-Clang.txt @@ -5,9 +5,11 @@ CLANG Was able to build Clang+LLVM using the instructions on GitHub, with the following commands: -cmake -S llvm -B build -G "MinGW Makefiles" -DLLVM_ENABLE_PROJECTS='clang' -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=On +(could also build libcas a projet, but last time it did not work) -cmake --build build +cmake -S llvm -B build -G "MinGW Makefiles" -DLLVM_ENABLE_PROJECTS='clang;openmp' -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=On -DLLVM_TARGETS_TO_BUILD=X86 + +cmake --build build -j 7 (llvm7) From d8b11cedd17c943d531dc4c725504673bca713da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sun, 19 Feb 2023 11:27:55 +0000 Subject: [PATCH 25/68] [ClangAstParser] Adds omp.h to builtin includes --- .../src/pt/up/fe/specs/clang/ClangAstWebResource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java b/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java index 6f3abc94e..39446e945 100644 --- a/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java +++ b/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java @@ -25,7 +25,7 @@ static WebResourceProvider create(String resourceUrl) { return WebResourceProvider.newInstance("http://specs.fe.up.pt/resources/clangast/", resourceUrl); } - WebResourceProvider BUILTIN_INCLUDES = create("clang_builtin_includes_v14.0.6.zip_", "v14.0.6_2"); + WebResourceProvider BUILTIN_INCLUDES = create("clang_builtin_includes_v14.0.6.zip_", "v14.0.6_3"); // WebResourceProvider LIBC_CXX = create("libcxx_7.0.1.zip", "v1.0"); WebResourceProvider LIBC_CXX = create("libc_cxx.zip", "v14.0.6"); From c056a678b988140253f4318c8b8587160bf608d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sun, 19 Feb 2023 11:28:34 +0000 Subject: [PATCH 26/68] [ClavaWeaver] Update C++ test 'OmpThreadsExplore' --- .../test/weaver/cpp/results/OmpThreadsExplore.lara.txt | 2 +- .../clava/test/weaver/cpp/src/omp_threads_explore.cpp | 2 +- .../test/pt/up/fe/specs/cxxweaver/tests/CxxTest.java | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ClavaWeaver/resources/clava/test/weaver/cpp/results/OmpThreadsExplore.lara.txt b/ClavaWeaver/resources/clava/test/weaver/cpp/results/OmpThreadsExplore.lara.txt index 0df8aa459..c1f0a5dca 100644 --- a/ClavaWeaver/resources/clava/test/weaver/cpp/results/OmpThreadsExplore.lara.txt +++ b/ClavaWeaver/resources/clava/test/weaver/cpp/results/OmpThreadsExplore.lara.txt @@ -17,7 +17,7 @@ int main() { omp_set_num_threads(omp_thread_measure); omp_thread_measure_loop1 << omp_thread_measure; - #pragma omp parallel for reduction(min : a, i) + #pragma omp parallel for reduction(min : a) for(int i = 0; i < 10; i++) { a += i; } diff --git a/ClavaWeaver/resources/clava/test/weaver/cpp/src/omp_threads_explore.cpp b/ClavaWeaver/resources/clava/test/weaver/cpp/src/omp_threads_explore.cpp index b19b36843..a9d89adc8 100644 --- a/ClavaWeaver/resources/clava/test/weaver/cpp/src/omp_threads_explore.cpp +++ b/ClavaWeaver/resources/clava/test/weaver/cpp/src/omp_threads_explore.cpp @@ -4,7 +4,7 @@ int main() { #pragma lara marker loop1 { - #pragma omp parallel for reduction( min : a, i ) + #pragma omp parallel for reduction( min : a ) for(int i=0; i<10; i++) { a += i; } diff --git a/ClavaWeaver/test/pt/up/fe/specs/cxxweaver/tests/CxxTest.java b/ClavaWeaver/test/pt/up/fe/specs/cxxweaver/tests/CxxTest.java index 41c549ece..d7341b08d 100644 --- a/ClavaWeaver/test/pt/up/fe/specs/cxxweaver/tests/CxxTest.java +++ b/ClavaWeaver/test/pt/up/fe/specs/cxxweaver/tests/CxxTest.java @@ -17,11 +17,13 @@ import org.junit.BeforeClass; import org.junit.Test; +import pt.up.fe.specs.clava.ClavaOptions; import pt.up.fe.specs.clava.language.Standard; import pt.up.fe.specs.clava.weaver.options.CxxWeaverOption; import pt.up.fe.specs.cxxweaver.ClavaWeaverTester; import pt.up.fe.specs.util.SpecsLogs; import pt.up.fe.specs.util.SpecsSystem; +import pt.up.fe.specs.util.utilities.StringList; public class CxxTest { @@ -103,7 +105,9 @@ public void testHdf5Types() { @Test public void testOmpThreadsExplore() { - newTester().test("OmpThreadsExplore.lara", "omp_threads_explore.cpp"); + newTester() + .set(ClavaOptions.FLAGS_LIST, StringList.newInstance("-fopenmp=libomp")) + .test("OmpThreadsExplore.lara", "omp_threads_explore.cpp"); } @Test From 8bf52dc1c60947491a35c8b7ffad9c6d1734deef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sun, 19 Feb 2023 13:27:01 +0000 Subject: [PATCH 27/68] [ClangAstParser] Updates dumper binary for Linux --- .../src/pt/up/fe/specs/clang/ClangAstWebResource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java b/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java index 39446e945..279b3a4de 100644 --- a/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java +++ b/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java @@ -43,7 +43,7 @@ static WebResourceProvider create(String resourceUrl) { WebResourceProvider WIN_DLL1 = create("windows/libwinpthread-1.dll"); WebResourceProvider WIN_DLL2 = create("windows/zlib1.dll"); - WebResourceProvider LINUX_EXE = create("linux_ubuntu_18/clang_ast", "v14.0.6_0"); + WebResourceProvider LINUX_EXE = create("linux_ubuntu_18/clang_ast", "v14.0.6_0_1"); // Disabled while we do not have an updated Odroid WebResourceProvider LINUX_ARMV7_EXE = create("linux_ubuntu_14_armv7/clang_ast", "v4.2.19"); From c52b58bf5a175f2a629204457936298369da5034 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sun, 19 Feb 2023 13:48:01 +0000 Subject: [PATCH 28/68] [ClangAstParser] Removes commented code --- .../src/pt/up/fe/specs/clang/ClangAstWebResource.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java b/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java index 279b3a4de..52c290f8d 100644 --- a/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java +++ b/ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java @@ -35,10 +35,6 @@ static WebResourceProvider create(String resourceUrl) { // For some reason, on Linux, this file no longer downloads WebResourceProvider CUDA_LIB = create("cudalib.zip_", "v11.3.0"); - // WebResourceProvider LIBC_CXX_MAC_OS = create("libc_cxx_mac_os.zip", "v1.0"); - // WebResourceProvider LIBC_CXX_LINUX = create("libc_cxx_linux.zip", "v1.0"); - // WebResourceProvider LIBC_CXX_CENTOS6 = create("libc_cxx_centos6.zip", "v1.0"); - WebResourceProvider WIN_EXE = create("windows/clang_ast.exe", "v14.0.6_0"); WebResourceProvider WIN_DLL1 = create("windows/libwinpthread-1.dll"); WebResourceProvider WIN_DLL2 = create("windows/zlib1.dll"); From 6daf77deb84ee797b25a019415c3918c8c6e5e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Thu, 23 Feb 2023 19:25:16 +0000 Subject: [PATCH 29/68] [ClangAstDumper] Downgrades C++ standard from 20 to 17 --- ClangAstDumper/CMakeLists.txt | 2 +- deps/Findllvm14.0.6.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ClangAstDumper/CMakeLists.txt b/ClangAstDumper/CMakeLists.txt index 88b8dca4e..7ae930aa0 100644 --- a/ClangAstDumper/CMakeLists.txt +++ b/ClangAstDumper/CMakeLists.txt @@ -17,7 +17,7 @@ include("../deps.cmake") #deps_find_package(llvm12 REQUIRED) # LLVM deps_find_package(llvm14.0.6 REQUIRED) # LLVM -set(COMMON_CXX_FLAGS "-std=c++20 -O3 -Wall -Wno-unused-function") +set(COMMON_CXX_FLAGS "-std=c++17 -O3 -Wall -Wno-unused-function") #-D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DVISIT_CHECK #add_definitions(-DOLD_OUTPUT) diff --git a/deps/Findllvm14.0.6.cmake b/deps/Findllvm14.0.6.cmake index edbf63158..8be641f16 100644 --- a/deps/Findllvm14.0.6.cmake +++ b/deps/Findllvm14.0.6.cmake @@ -7,7 +7,7 @@ deps_resolve("llvm14.0.6" LIB_DIR) set("llvm14.0.6_DIR" ${LIB_DIR}) # LLVM requires C++11 -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") if(UNIX) # Unix version uses pre-build clang binaries, which disable rtti From e1c9bfbca61a20ffe5a8a70356f996bb249d99d8 Mon Sep 17 00:00:00 2001 From: "L. Sousa" Date: Tue, 28 Mar 2023 18:18:08 +0100 Subject: [PATCH 30/68] Moved sources to dedicated folder --- ClangAstDumper/.gitignore | 3 +- .../{ => src}/ChildrenVisitorAttrs.cpp | 0 .../{ => src}/ChildrenVisitorDecls.cpp | 0 .../{ => src}/ChildrenVisitorExtras.cpp | 0 .../{ => src}/ChildrenVisitorStmts.cpp | 0 .../{ => src}/ChildrenVisitorTypes.cpp | 0 ClangAstDumper/{ => src}/ClangAst.cpp | 0 ClangAstDumper/{ => src}/ClangAst.h | 0 ClangAstDumper/{ => src}/ClangAstDumper.cpp | 0 ClangAstDumper/{ => src}/ClangAstDumper.h | 0 .../ClangAstDumperAttr.cpp} | 0 .../{ => src}/ClangAstDumperConstants.h | 0 .../{ => src}/ClangAstDumperDecls.cpp | 0 .../{ => src}/ClangAstDumperExprs.cpp | 0 .../{ => src}/ClangAstDumperExtra.cpp | 0 .../{ => src}/ClangAstDumperStmts.cpp | 0 .../{ => src}/ClangAstDumperTypes.cpp | 0 ClangAstDumper/{ => src}/ClangEnums.cpp | 0 ClangAstDumper/{ => src}/ClangEnums.h | 0 ClangAstDumper/{ => src}/ClangNodes.cpp | 0 ClangAstDumper/{ => src}/ClangNodes.h | 0 ClangAstDumper/{ => src}/ClavaConstants.cpp | 0 ClangAstDumper/{ => src}/ClavaConstants.h | 0 ClangAstDumper/{ => src}/ClavaDataDumper.cpp | 0 ClangAstDumper/{ => src}/ClavaDataDumper.h | 0 .../{ => src}/ClavaDataDumperAttrs.cpp | 0 .../{ => src}/ClavaDataDumperDecls.cpp | 0 .../{ => src}/ClavaDataDumperStmts.cpp | 0 .../{ => src}/ClavaDataDumperTypes.cpp | 0 ClangAstDumper/{ => src}/ClavaDecl.cpp | 0 ClangAstDumper/{ => src}/ClavaDecl.h | 0 ClangAstDumper/{ => src}/TypeMarker.cpp | 0 ClangAstDumper/{ => src}/TypeMarker.h | 0 .../{ => src}/enums_AttrKinds_h.cpp | 0 ClangAstDumper/{ => src}/enums_Attr_h.cpp | 0 ClangAstDumper/{ => src}/enums_DeclCxx_h.cpp | 0 ClangAstDumper/{ => src}/enums_Decl_h.cpp | 0 .../enums_ExceptionSpecificationType_h.cpp | 0 ClangAstDumper/{ => src}/enums_ExprCXX_h.cpp | 0 ClangAstDumper/{ => src}/enums_Expr_h.cpp | 0 ClangAstDumper/{ => src}/enums_Lambda_h.cpp | 0 ClangAstDumper/{ => src}/enums_Linkage_h.cpp | 0 .../{ => src}/enums_NestedNameSpecifier_h.cpp | 0 .../{ => src}/enums_OperationKinds_h.cpp | 0 .../{ => src}/enums_Specifiers_h.cpp | 0 .../{ => src}/enums_TemplateBase_h.cpp | 0 .../{ => src}/enums_TemplateName_h.cpp | 0 .../{ => src}/enums_TypeTraits_h.cpp | 0 ClangAstDumper/{ => src}/enums_Type_h.cpp | 0 .../{ => src}/enums_Visibility_h.cpp | 0 ClangAstDumper/{ => src}/main.cpp | 0 ClangAstDumper/src/newmain.cpp | 72 +++++++++++++++++++ 52 files changed, 74 insertions(+), 1 deletion(-) rename ClangAstDumper/{ => src}/ChildrenVisitorAttrs.cpp (100%) rename ClangAstDumper/{ => src}/ChildrenVisitorDecls.cpp (100%) rename ClangAstDumper/{ => src}/ChildrenVisitorExtras.cpp (100%) rename ClangAstDumper/{ => src}/ChildrenVisitorStmts.cpp (100%) rename ClangAstDumper/{ => src}/ChildrenVisitorTypes.cpp (100%) rename ClangAstDumper/{ => src}/ClangAst.cpp (100%) rename ClangAstDumper/{ => src}/ClangAst.h (100%) rename ClangAstDumper/{ => src}/ClangAstDumper.cpp (100%) rename ClangAstDumper/{ => src}/ClangAstDumper.h (100%) rename ClangAstDumper/{ClangastDumperAttr.cpp => src/ClangAstDumperAttr.cpp} (100%) rename ClangAstDumper/{ => src}/ClangAstDumperConstants.h (100%) rename ClangAstDumper/{ => src}/ClangAstDumperDecls.cpp (100%) rename ClangAstDumper/{ => src}/ClangAstDumperExprs.cpp (100%) rename ClangAstDumper/{ => src}/ClangAstDumperExtra.cpp (100%) rename ClangAstDumper/{ => src}/ClangAstDumperStmts.cpp (100%) rename ClangAstDumper/{ => src}/ClangAstDumperTypes.cpp (100%) rename ClangAstDumper/{ => src}/ClangEnums.cpp (100%) rename ClangAstDumper/{ => src}/ClangEnums.h (100%) rename ClangAstDumper/{ => src}/ClangNodes.cpp (100%) rename ClangAstDumper/{ => src}/ClangNodes.h (100%) rename ClangAstDumper/{ => src}/ClavaConstants.cpp (100%) rename ClangAstDumper/{ => src}/ClavaConstants.h (100%) rename ClangAstDumper/{ => src}/ClavaDataDumper.cpp (100%) rename ClangAstDumper/{ => src}/ClavaDataDumper.h (100%) rename ClangAstDumper/{ => src}/ClavaDataDumperAttrs.cpp (100%) rename ClangAstDumper/{ => src}/ClavaDataDumperDecls.cpp (100%) rename ClangAstDumper/{ => src}/ClavaDataDumperStmts.cpp (100%) rename ClangAstDumper/{ => src}/ClavaDataDumperTypes.cpp (100%) rename ClangAstDumper/{ => src}/ClavaDecl.cpp (100%) rename ClangAstDumper/{ => src}/ClavaDecl.h (100%) rename ClangAstDumper/{ => src}/TypeMarker.cpp (100%) rename ClangAstDumper/{ => src}/TypeMarker.h (100%) rename ClangAstDumper/{ => src}/enums_AttrKinds_h.cpp (100%) rename ClangAstDumper/{ => src}/enums_Attr_h.cpp (100%) rename ClangAstDumper/{ => src}/enums_DeclCxx_h.cpp (100%) rename ClangAstDumper/{ => src}/enums_Decl_h.cpp (100%) rename ClangAstDumper/{ => src}/enums_ExceptionSpecificationType_h.cpp (100%) rename ClangAstDumper/{ => src}/enums_ExprCXX_h.cpp (100%) rename ClangAstDumper/{ => src}/enums_Expr_h.cpp (100%) rename ClangAstDumper/{ => src}/enums_Lambda_h.cpp (100%) rename ClangAstDumper/{ => src}/enums_Linkage_h.cpp (100%) rename ClangAstDumper/{ => src}/enums_NestedNameSpecifier_h.cpp (100%) rename ClangAstDumper/{ => src}/enums_OperationKinds_h.cpp (100%) rename ClangAstDumper/{ => src}/enums_Specifiers_h.cpp (100%) rename ClangAstDumper/{ => src}/enums_TemplateBase_h.cpp (100%) rename ClangAstDumper/{ => src}/enums_TemplateName_h.cpp (100%) rename ClangAstDumper/{ => src}/enums_TypeTraits_h.cpp (100%) rename ClangAstDumper/{ => src}/enums_Type_h.cpp (100%) rename ClangAstDumper/{ => src}/enums_Visibility_h.cpp (100%) rename ClangAstDumper/{ => src}/main.cpp (100%) create mode 100644 ClangAstDumper/src/newmain.cpp diff --git a/ClangAstDumper/.gitignore b/ClangAstDumper/.gitignore index 0f0eb1643..b0ee288d8 100644 --- a/ClangAstDumper/.gitignore +++ b/ClangAstDumper/.gitignore @@ -1,7 +1,8 @@ CMakeFiles/ cmake_install.cmake CMakeCache.txt -*Plugin.so +*.so Makefile .vscode testSources +build diff --git a/ClangAstDumper/ChildrenVisitorAttrs.cpp b/ClangAstDumper/src/ChildrenVisitorAttrs.cpp similarity index 100% rename from ClangAstDumper/ChildrenVisitorAttrs.cpp rename to ClangAstDumper/src/ChildrenVisitorAttrs.cpp diff --git a/ClangAstDumper/ChildrenVisitorDecls.cpp b/ClangAstDumper/src/ChildrenVisitorDecls.cpp similarity index 100% rename from ClangAstDumper/ChildrenVisitorDecls.cpp rename to ClangAstDumper/src/ChildrenVisitorDecls.cpp diff --git a/ClangAstDumper/ChildrenVisitorExtras.cpp b/ClangAstDumper/src/ChildrenVisitorExtras.cpp similarity index 100% rename from ClangAstDumper/ChildrenVisitorExtras.cpp rename to ClangAstDumper/src/ChildrenVisitorExtras.cpp diff --git a/ClangAstDumper/ChildrenVisitorStmts.cpp b/ClangAstDumper/src/ChildrenVisitorStmts.cpp similarity index 100% rename from ClangAstDumper/ChildrenVisitorStmts.cpp rename to ClangAstDumper/src/ChildrenVisitorStmts.cpp diff --git a/ClangAstDumper/ChildrenVisitorTypes.cpp b/ClangAstDumper/src/ChildrenVisitorTypes.cpp similarity index 100% rename from ClangAstDumper/ChildrenVisitorTypes.cpp rename to ClangAstDumper/src/ChildrenVisitorTypes.cpp diff --git a/ClangAstDumper/ClangAst.cpp b/ClangAstDumper/src/ClangAst.cpp similarity index 100% rename from ClangAstDumper/ClangAst.cpp rename to ClangAstDumper/src/ClangAst.cpp diff --git a/ClangAstDumper/ClangAst.h b/ClangAstDumper/src/ClangAst.h similarity index 100% rename from ClangAstDumper/ClangAst.h rename to ClangAstDumper/src/ClangAst.h diff --git a/ClangAstDumper/ClangAstDumper.cpp b/ClangAstDumper/src/ClangAstDumper.cpp similarity index 100% rename from ClangAstDumper/ClangAstDumper.cpp rename to ClangAstDumper/src/ClangAstDumper.cpp diff --git a/ClangAstDumper/ClangAstDumper.h b/ClangAstDumper/src/ClangAstDumper.h similarity index 100% rename from ClangAstDumper/ClangAstDumper.h rename to ClangAstDumper/src/ClangAstDumper.h diff --git a/ClangAstDumper/ClangastDumperAttr.cpp b/ClangAstDumper/src/ClangAstDumperAttr.cpp similarity index 100% rename from ClangAstDumper/ClangastDumperAttr.cpp rename to ClangAstDumper/src/ClangAstDumperAttr.cpp diff --git a/ClangAstDumper/ClangAstDumperConstants.h b/ClangAstDumper/src/ClangAstDumperConstants.h similarity index 100% rename from ClangAstDumper/ClangAstDumperConstants.h rename to ClangAstDumper/src/ClangAstDumperConstants.h diff --git a/ClangAstDumper/ClangAstDumperDecls.cpp b/ClangAstDumper/src/ClangAstDumperDecls.cpp similarity index 100% rename from ClangAstDumper/ClangAstDumperDecls.cpp rename to ClangAstDumper/src/ClangAstDumperDecls.cpp diff --git a/ClangAstDumper/ClangAstDumperExprs.cpp b/ClangAstDumper/src/ClangAstDumperExprs.cpp similarity index 100% rename from ClangAstDumper/ClangAstDumperExprs.cpp rename to ClangAstDumper/src/ClangAstDumperExprs.cpp diff --git a/ClangAstDumper/ClangAstDumperExtra.cpp b/ClangAstDumper/src/ClangAstDumperExtra.cpp similarity index 100% rename from ClangAstDumper/ClangAstDumperExtra.cpp rename to ClangAstDumper/src/ClangAstDumperExtra.cpp diff --git a/ClangAstDumper/ClangAstDumperStmts.cpp b/ClangAstDumper/src/ClangAstDumperStmts.cpp similarity index 100% rename from ClangAstDumper/ClangAstDumperStmts.cpp rename to ClangAstDumper/src/ClangAstDumperStmts.cpp diff --git a/ClangAstDumper/ClangAstDumperTypes.cpp b/ClangAstDumper/src/ClangAstDumperTypes.cpp similarity index 100% rename from ClangAstDumper/ClangAstDumperTypes.cpp rename to ClangAstDumper/src/ClangAstDumperTypes.cpp diff --git a/ClangAstDumper/ClangEnums.cpp b/ClangAstDumper/src/ClangEnums.cpp similarity index 100% rename from ClangAstDumper/ClangEnums.cpp rename to ClangAstDumper/src/ClangEnums.cpp diff --git a/ClangAstDumper/ClangEnums.h b/ClangAstDumper/src/ClangEnums.h similarity index 100% rename from ClangAstDumper/ClangEnums.h rename to ClangAstDumper/src/ClangEnums.h diff --git a/ClangAstDumper/ClangNodes.cpp b/ClangAstDumper/src/ClangNodes.cpp similarity index 100% rename from ClangAstDumper/ClangNodes.cpp rename to ClangAstDumper/src/ClangNodes.cpp diff --git a/ClangAstDumper/ClangNodes.h b/ClangAstDumper/src/ClangNodes.h similarity index 100% rename from ClangAstDumper/ClangNodes.h rename to ClangAstDumper/src/ClangNodes.h diff --git a/ClangAstDumper/ClavaConstants.cpp b/ClangAstDumper/src/ClavaConstants.cpp similarity index 100% rename from ClangAstDumper/ClavaConstants.cpp rename to ClangAstDumper/src/ClavaConstants.cpp diff --git a/ClangAstDumper/ClavaConstants.h b/ClangAstDumper/src/ClavaConstants.h similarity index 100% rename from ClangAstDumper/ClavaConstants.h rename to ClangAstDumper/src/ClavaConstants.h diff --git a/ClangAstDumper/ClavaDataDumper.cpp b/ClangAstDumper/src/ClavaDataDumper.cpp similarity index 100% rename from ClangAstDumper/ClavaDataDumper.cpp rename to ClangAstDumper/src/ClavaDataDumper.cpp diff --git a/ClangAstDumper/ClavaDataDumper.h b/ClangAstDumper/src/ClavaDataDumper.h similarity index 100% rename from ClangAstDumper/ClavaDataDumper.h rename to ClangAstDumper/src/ClavaDataDumper.h diff --git a/ClangAstDumper/ClavaDataDumperAttrs.cpp b/ClangAstDumper/src/ClavaDataDumperAttrs.cpp similarity index 100% rename from ClangAstDumper/ClavaDataDumperAttrs.cpp rename to ClangAstDumper/src/ClavaDataDumperAttrs.cpp diff --git a/ClangAstDumper/ClavaDataDumperDecls.cpp b/ClangAstDumper/src/ClavaDataDumperDecls.cpp similarity index 100% rename from ClangAstDumper/ClavaDataDumperDecls.cpp rename to ClangAstDumper/src/ClavaDataDumperDecls.cpp diff --git a/ClangAstDumper/ClavaDataDumperStmts.cpp b/ClangAstDumper/src/ClavaDataDumperStmts.cpp similarity index 100% rename from ClangAstDumper/ClavaDataDumperStmts.cpp rename to ClangAstDumper/src/ClavaDataDumperStmts.cpp diff --git a/ClangAstDumper/ClavaDataDumperTypes.cpp b/ClangAstDumper/src/ClavaDataDumperTypes.cpp similarity index 100% rename from ClangAstDumper/ClavaDataDumperTypes.cpp rename to ClangAstDumper/src/ClavaDataDumperTypes.cpp diff --git a/ClangAstDumper/ClavaDecl.cpp b/ClangAstDumper/src/ClavaDecl.cpp similarity index 100% rename from ClangAstDumper/ClavaDecl.cpp rename to ClangAstDumper/src/ClavaDecl.cpp diff --git a/ClangAstDumper/ClavaDecl.h b/ClangAstDumper/src/ClavaDecl.h similarity index 100% rename from ClangAstDumper/ClavaDecl.h rename to ClangAstDumper/src/ClavaDecl.h diff --git a/ClangAstDumper/TypeMarker.cpp b/ClangAstDumper/src/TypeMarker.cpp similarity index 100% rename from ClangAstDumper/TypeMarker.cpp rename to ClangAstDumper/src/TypeMarker.cpp diff --git a/ClangAstDumper/TypeMarker.h b/ClangAstDumper/src/TypeMarker.h similarity index 100% rename from ClangAstDumper/TypeMarker.h rename to ClangAstDumper/src/TypeMarker.h diff --git a/ClangAstDumper/enums_AttrKinds_h.cpp b/ClangAstDumper/src/enums_AttrKinds_h.cpp similarity index 100% rename from ClangAstDumper/enums_AttrKinds_h.cpp rename to ClangAstDumper/src/enums_AttrKinds_h.cpp diff --git a/ClangAstDumper/enums_Attr_h.cpp b/ClangAstDumper/src/enums_Attr_h.cpp similarity index 100% rename from ClangAstDumper/enums_Attr_h.cpp rename to ClangAstDumper/src/enums_Attr_h.cpp diff --git a/ClangAstDumper/enums_DeclCxx_h.cpp b/ClangAstDumper/src/enums_DeclCxx_h.cpp similarity index 100% rename from ClangAstDumper/enums_DeclCxx_h.cpp rename to ClangAstDumper/src/enums_DeclCxx_h.cpp diff --git a/ClangAstDumper/enums_Decl_h.cpp b/ClangAstDumper/src/enums_Decl_h.cpp similarity index 100% rename from ClangAstDumper/enums_Decl_h.cpp rename to ClangAstDumper/src/enums_Decl_h.cpp diff --git a/ClangAstDumper/enums_ExceptionSpecificationType_h.cpp b/ClangAstDumper/src/enums_ExceptionSpecificationType_h.cpp similarity index 100% rename from ClangAstDumper/enums_ExceptionSpecificationType_h.cpp rename to ClangAstDumper/src/enums_ExceptionSpecificationType_h.cpp diff --git a/ClangAstDumper/enums_ExprCXX_h.cpp b/ClangAstDumper/src/enums_ExprCXX_h.cpp similarity index 100% rename from ClangAstDumper/enums_ExprCXX_h.cpp rename to ClangAstDumper/src/enums_ExprCXX_h.cpp diff --git a/ClangAstDumper/enums_Expr_h.cpp b/ClangAstDumper/src/enums_Expr_h.cpp similarity index 100% rename from ClangAstDumper/enums_Expr_h.cpp rename to ClangAstDumper/src/enums_Expr_h.cpp diff --git a/ClangAstDumper/enums_Lambda_h.cpp b/ClangAstDumper/src/enums_Lambda_h.cpp similarity index 100% rename from ClangAstDumper/enums_Lambda_h.cpp rename to ClangAstDumper/src/enums_Lambda_h.cpp diff --git a/ClangAstDumper/enums_Linkage_h.cpp b/ClangAstDumper/src/enums_Linkage_h.cpp similarity index 100% rename from ClangAstDumper/enums_Linkage_h.cpp rename to ClangAstDumper/src/enums_Linkage_h.cpp diff --git a/ClangAstDumper/enums_NestedNameSpecifier_h.cpp b/ClangAstDumper/src/enums_NestedNameSpecifier_h.cpp similarity index 100% rename from ClangAstDumper/enums_NestedNameSpecifier_h.cpp rename to ClangAstDumper/src/enums_NestedNameSpecifier_h.cpp diff --git a/ClangAstDumper/enums_OperationKinds_h.cpp b/ClangAstDumper/src/enums_OperationKinds_h.cpp similarity index 100% rename from ClangAstDumper/enums_OperationKinds_h.cpp rename to ClangAstDumper/src/enums_OperationKinds_h.cpp diff --git a/ClangAstDumper/enums_Specifiers_h.cpp b/ClangAstDumper/src/enums_Specifiers_h.cpp similarity index 100% rename from ClangAstDumper/enums_Specifiers_h.cpp rename to ClangAstDumper/src/enums_Specifiers_h.cpp diff --git a/ClangAstDumper/enums_TemplateBase_h.cpp b/ClangAstDumper/src/enums_TemplateBase_h.cpp similarity index 100% rename from ClangAstDumper/enums_TemplateBase_h.cpp rename to ClangAstDumper/src/enums_TemplateBase_h.cpp diff --git a/ClangAstDumper/enums_TemplateName_h.cpp b/ClangAstDumper/src/enums_TemplateName_h.cpp similarity index 100% rename from ClangAstDumper/enums_TemplateName_h.cpp rename to ClangAstDumper/src/enums_TemplateName_h.cpp diff --git a/ClangAstDumper/enums_TypeTraits_h.cpp b/ClangAstDumper/src/enums_TypeTraits_h.cpp similarity index 100% rename from ClangAstDumper/enums_TypeTraits_h.cpp rename to ClangAstDumper/src/enums_TypeTraits_h.cpp diff --git a/ClangAstDumper/enums_Type_h.cpp b/ClangAstDumper/src/enums_Type_h.cpp similarity index 100% rename from ClangAstDumper/enums_Type_h.cpp rename to ClangAstDumper/src/enums_Type_h.cpp diff --git a/ClangAstDumper/enums_Visibility_h.cpp b/ClangAstDumper/src/enums_Visibility_h.cpp similarity index 100% rename from ClangAstDumper/enums_Visibility_h.cpp rename to ClangAstDumper/src/enums_Visibility_h.cpp diff --git a/ClangAstDumper/main.cpp b/ClangAstDumper/src/main.cpp similarity index 100% rename from ClangAstDumper/main.cpp rename to ClangAstDumper/src/main.cpp diff --git a/ClangAstDumper/src/newmain.cpp b/ClangAstDumper/src/newmain.cpp new file mode 100644 index 000000000..9ba8f2fd1 --- /dev/null +++ b/ClangAstDumper/src/newmain.cpp @@ -0,0 +1,72 @@ +#include "clang/AST/AST.h" +#include "clang/AST/ASTConsumer.h" +#include "clang/AST/RecursiveASTVisitor.h" +#include "clang/Basic/SourceManager.h" +#include "clang/Frontend/CompilerInstance.h" +#include "clang/Frontend/FrontendPluginRegistry.h" + +#include "ClangAst.h" + +using namespace clang; + +namespace { + +// Define a visitor class that will traverse the AST and detect the function +// call +class MyASTVisitor : public RecursiveASTVisitor { + public: + explicit MyASTVisitor(ASTContext *context) : context_(context) {} + + bool VisitCallExpr(CallExpr *call) { + FunctionDecl *funcDecl = call->getDirectCallee(); + if (funcDecl && funcDecl->getNameAsString() == "myFunction") { + SourceManager &SM = context_->getSourceManager(); + SourceLocation loc = call->getBeginLoc(); + llvm::outs() << "Found call to myFunction at " + << SM.getFilename(loc) << ":" + << SM.getSpellingLineNumber(loc) << "\n"; + } + return true; + } + + private: + ASTContext *context_; +}; + +// Define an AST consumer that will create the AST visitor +class MyASTConsumer : public ASTConsumer { + public: + explicit MyASTConsumer(ASTContext *context) : visitor_(context) {} + + void HandleTranslationUnit(ASTContext &context) override { + visitor_.TraverseDecl(context.getTranslationUnitDecl()); + } + + private: + MyASTVisitor visitor_; +}; + +// Define a plugin that will create the AST consumer +class MyPlugin : public PluginASTAction { + public: + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef file) override { + return std::make_unique(&CI.getASTContext()); + } + + bool ParseArgs(const CompilerInstance &CI, + const std::vector &args) override { + // No arguments to parse + return true; + } + + PluginASTAction::ActionType getActionType() override { + return AddBeforeMainAction; + } +}; + +} // end anonymous namespace + +// Register the plugin with Clang +static FrontendPluginRegistry::Add + X("myplugin", "Detect use of myFunction in input code"); From 302a39c2630bfb0384d82badcde2249ca312ac04 Mon Sep 17 00:00:00 2001 From: "L. Sousa" Date: Tue, 28 Mar 2023 18:21:02 +0100 Subject: [PATCH 31/68] Modified Cmake to build a plugin --- ClangAstDumper/.gitignore | 9 +- ClangAstDumper/CMakeLists.txt | 150 +++++++++------------------- ClangAstDumper/src/ClangAst.h | 147 +++++++++++++++------------ ClangAstDumper/testSources/foo.cpp | 6 ++ ClangAstDumper/testSources/foo.h | 6 ++ ClangAstDumper/testSources/main.cpp | 6 ++ 6 files changed, 157 insertions(+), 167 deletions(-) create mode 100644 ClangAstDumper/testSources/foo.cpp create mode 100644 ClangAstDumper/testSources/foo.h create mode 100644 ClangAstDumper/testSources/main.cpp diff --git a/ClangAstDumper/.gitignore b/ClangAstDumper/.gitignore index b0ee288d8..b03e30d73 100644 --- a/ClangAstDumper/.gitignore +++ b/ClangAstDumper/.gitignore @@ -1,8 +1,11 @@ +.vscode +build CMakeFiles/ cmake_install.cmake CMakeCache.txt -*.so Makefile -.vscode testSources -build +*.so +*.gch +*.o +*.a diff --git a/ClangAstDumper/CMakeLists.txt b/ClangAstDumper/CMakeLists.txt index 7ae930aa0..48ccf89c7 100644 --- a/ClangAstDumper/CMakeLists.txt +++ b/ClangAstDumper/CMakeLists.txt @@ -1,111 +1,59 @@ -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.14) project(ClangAstDumper) -#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin") -#message(STATUS HELLO) +set(LLVM_VERSION 14) +SET(CMAKE_C_COMPILER "clang-14") +SET(CMAKE_CXX_COMPILER "clang++-14") -#SET(CMAKE_C_COMPILER "clang") -#SET(CMAKE_CXX_COMPILER "clang++") - -# Initialize Deps -include("../deps.cmake") - -# Add Modules -#deps_find_package(llvm3.8 REQUIRED) # LLVM -#deps_find_package(llvm7 REQUIRED) # LLVM -#deps_find_package(llvm12 REQUIRED) # LLVM -deps_find_package(llvm14.0.6 REQUIRED) # LLVM - -set(COMMON_CXX_FLAGS "-std=c++17 -O3 -Wall -Wno-unused-function") -#-D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DVISIT_CHECK - -#add_definitions(-DOLD_OUTPUT) - -if(SYSTEM_PLATFORM STREQUAL "MacOS") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_CXX_FLAGS} -stdlib=libc++") -else() - #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_CXX_FLAGS} -static-libgcc -static-libstdc++") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_CXX_FLAGS}") -endif() - - -#Enable debug -#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG") - -# For CentOS and macOS -# Set SYSTEM_PLATFORM in deps_config.cmake -if(SYSTEM_PLATFORM STREQUAL "Centos" OR SYSTEM_PLATFORM STREQUAL "MacOS") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS") -endif() - - -OPTION(USE_CLAVA "Uses Clava during compilation") - -# Enable Clava -if(USE_CLAVA) -# message(STATUS "Using Clava in this project") - find_package(Clava REQUIRED) -#else() -# message(STATUS "Not using Clava") -endif(USE_CLAVA) -unset(USE_CLAVA CACHE) # So that the value is refreshed +find_package(Clang REQUIRED CONFIG) +include_directories(/usr/lib/llvm-14/include) set(SOURCE_FILES - main.cpp - ClangAst.cpp - ClangAstDumper.cpp - ClangAstDumperTypes.cpp - ClangAstDumperStmts.cpp - ClangAstDumperDecls.cpp - ClangAstDumperExtra.cpp - TypeMarker.cpp - ClavaDataDumper.cpp - ClavaDataDumperDecls.cpp - ChildrenVisitorDecls.cpp - ClangNodes.cpp - ClavaDataDumperStmts.cpp - ClavaDataDumperTypes.cpp - ClangAstDumperExprs.cpp - ChildrenVisitorStmts.cpp - ClavaConstants.cpp - ChildrenVisitorTypes.cpp - ClangEnums.cpp - ClangastDumperAttr.cpp - ChildrenVisitorAttrs.cpp - ClavaDataDumperAttrs.cpp - ChildrenVisitorExtras.cpp - ClavaDecl.cpp - enums_Type_h.cpp - enums_OperationKinds_h.cpp - enums_AttrKinds_h.cpp - enums_Specifiers_h.cpp - enums_ExceptionSpecificationType_h.cpp - enums_Linkage_h.cpp - enums_Visibility_h.cpp - enums_TemplateBase_h.cpp - enums_Decl_h.cpp - enums_ExprCXX_h.cpp - enums_TypeTraits_h.cpp - enums_NestedNameSpecifier_h.cpp - enums_DeclCxx_h.cpp - enums_Lambda_h.cpp - enums_TemplateName_h.cpp - enums_Attr_h.cpp - enums_Expr_h.cpp + src/newmain.cpp + src/ClangAst.cpp + src/ClangNodes.cpp + src/TypeMarker.cpp + src/ClavaDataDumper.cpp + src/ClavaDataDumperAttrs.cpp + src/ClavaDataDumperDecls.cpp + src/ClavaDataDumperStmts.cpp + src/ClavaDataDumperTypes.cpp + src/ClavaConstants.cpp + src/ClavaDecl.cpp + src/ChildrenVisitorAttrs.cpp + src/ChildrenVisitorDecls.cpp + src/ChildrenVisitorExtras.cpp + src/ChildrenVisitorStmts.cpp + src/ChildrenVisitorTypes.cpp + src/ClangAstDumper.cpp + src/ClangAstDumperAttr.cpp + src/ClangAstDumperDecls.cpp + src/ClangAstDumperExprs.cpp + src/ClangAstDumperExtra.cpp + src/ClangAstDumperStmts.cpp + src/ClangAstDumperTypes.cpp + src/ClangEnums.cpp + src/enums_Type_h.cpp + src/enums_OperationKinds_h.cpp + src/enums_AttrKinds_h.cpp + src/enums_Specifiers_h.cpp + src/enums_ExceptionSpecificationType_h.cpp + src/enums_Linkage_h.cpp + src/enums_Visibility_h.cpp + src/enums_TemplateBase_h.cpp + src/enums_Decl_h.cpp + src/enums_ExprCXX_h.cpp + src/enums_TypeTraits_h.cpp + src/enums_NestedNameSpecifier_h.cpp + src/enums_DeclCxx_h.cpp + src/enums_Lambda_h.cpp + src/enums_TemplateName_h.cpp + src/enums_Attr_h.cpp + src/enums_Expr_h.cpp ) -add_executable(ClangAstDumper ${SOURCE_FILES}) - -# Add includes -target_include_directories(ClangAstDumper - SYSTEM PUBLIC ${DEPS_INCLUDES} -) - -# Add enums helper +add_library(MyPlugin SHARED ${SOURCE_FILES}) -# Add Libraries -target_link_libraries(ClangAstDumper - ${DEPS_LIBRARIES} -) +target_compile_features(MyPlugin PRIVATE cxx_std_17) diff --git a/ClangAstDumper/src/ClangAst.h b/ClangAstDumper/src/ClangAst.h index 2673400b0..74cd42e3e 100644 --- a/ClangAstDumper/src/ClangAst.h +++ b/ClangAstDumper/src/ClangAst.h @@ -10,29 +10,26 @@ #include "ClangAstDumper.h" - #include "clang/AST/AST.h" -#include "clang/Frontend/FrontendActions.h" #include "clang/AST/RecursiveASTVisitor.h" +#include "clang/Frontend/FrontendActions.h" #include - using namespace clang; // Class for managing ClavaDump resources class DumpResources { -public: + public: static void init(int runId, int systemLevelThreshold); static void finish(); static void writeCounter(int set); - static std::ofstream includes; static std::ofstream nodetypes; - //static std::ofstream template_args; + // static std::ofstream template_args; static std::ofstream is_temporary; static std::ofstream omp; static std::ofstream enum_integer_type; @@ -41,98 +38,124 @@ class DumpResources { static int runId; static int systemHeaderThreshold; -private: - + private: }; /** * Dumps includes to a file. * - * Based on explanation from this website: https://xaizek.github.io/2015-04-23/detecting-wrong-first-include/ + * Based on explanation from this website: + * https://xaizek.github.io/2015-04-23/detecting-wrong-first-include/ */ class DumpIncludesAction : public PreprocessOnlyAction { -protected: + protected: virtual void ExecuteAction(); }; class IncludeDumper : public PPCallbacks { -public: + public: IncludeDumper(CompilerInstance &compilerInstance); std::unique_ptr createPreprocessorCallbacks(); - virtual void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType); - virtual void MacroExpands(const Token & MacroNameTok, const MacroDefinition & MD, SourceRange Range, const MacroArgs * Args); - virtual void PragmaDirective(SourceLocation Loc, PragmaIntroducerKind Introducer); - virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID); - -private: - + virtual void InclusionDirective( + SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, + bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, + StringRef SearchPath, StringRef RelativePath, const Module *Imported, + SrcMgr::CharacteristicKind FileType); + virtual void MacroExpands(const Token &MacroNameTok, + const MacroDefinition &MD, SourceRange Range, + const MacroArgs *Args); + virtual void PragmaDirective(SourceLocation Loc, + PragmaIntroducerKind Introducer); + virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason, + SrcMgr::CharacteristicKind FileType, + FileID PrevFID); + + private: const CompilerInstance &compilerInstance; const clang::SourceManager &sm; - }; class CallbacksProxy : public PPCallbacks { -public: + public: CallbacksProxy(IncludeDumper &original); - virtual void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType); - virtual void MacroExpands(const Token & MacroNameTok, const MacroDefinition & MD, SourceRange Range, const MacroArgs * Args); - virtual void PragmaDirective(SourceLocation Loc, PragmaIntroducerKind Introducer); - virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID); -private: - + virtual void InclusionDirective( + SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, + bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, + StringRef SearchPath, StringRef RelativePath, const Module *Imported, + SrcMgr::CharacteristicKind FileType); + virtual void MacroExpands(const Token &MacroNameTok, + const MacroDefinition &MD, SourceRange Range, + const MacroArgs *Args); + virtual void PragmaDirective(SourceLocation Loc, + PragmaIntroducerKind Introducer); + virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason, + SrcMgr::CharacteristicKind FileType, + FileID PrevFID); + + private: IncludeDumper original; }; // For each source file provided to the tool, a new FrontendAction is created. -class DumpAstAction : public ASTFrontendAction { -public: +class DumpAstAction : public PluginASTAction { + public: + virtual std::unique_ptr + CreateASTConsumer(CompilerInstance &CI, StringRef file) override; + + bool ParseArgs(const CompilerInstance &CI, + const std::vector &args) override { + // No arguments to parse + return true; + } - virtual std::unique_ptr CreateASTConsumer(CompilerInstance &CI, StringRef file); + PluginASTAction::ActionType getActionType() override { + return AddBeforeMainAction; + } void dumpCompilerInstanceData(CompilerInstance &CI, StringRef file); }; - - - - // By implementing RecursiveASTVisitor, we can specify which AST nodes // we're interested in by overriding relevant methods. class DumpAstVisitor : public RecursiveASTVisitor { -public: - //explicit DumpAstVisitor(ASTContext *Context, int id, ClangAstDumper *dumper) : Context(Context) , id(id), dumper(dumper) {} - explicit DumpAstVisitor(ASTContext *Context, int id) : Context(Context) , id(id) {} + public: + // explicit DumpAstVisitor(ASTContext *Context, int id, ClangAstDumper + // *dumper) : Context(Context) , id(id), dumper(dumper) {} + explicit DumpAstVisitor(ASTContext *Context, int id) + : Context(Context), id(id) {} bool TraverseDecl(Decl *D); -private: + private: ASTContext *Context; int id; - //ClangAstDumper dumper; - //ClangAstDumper *dumper; + // ClangAstDumper dumper; + // ClangAstDumper *dumper; }; +class PrintNodesTypesRelationsVisitor + : public RecursiveASTVisitor { -class PrintNodesTypesRelationsVisitor : public RecursiveASTVisitor { - -private: + private: ASTContext *Context; int id; ClangAstDumper dumper; - //ClangAstDumper *dumper; + // ClangAstDumper *dumper; std::set seenNodes; -public: - //explicit PrintNodesTypesRelationsVisitor(ASTContext *Context, int id, ClangAstDumper *dumper); - explicit PrintNodesTypesRelationsVisitor(ASTContext *Context, int id, ClangAstDumper dumper); - //bool TraverseDecl(Decl *D); + public: + // explicit PrintNodesTypesRelationsVisitor(ASTContext *Context, int id, + // ClangAstDumper *dumper); + explicit PrintNodesTypesRelationsVisitor(ASTContext *Context, int id, + ClangAstDumper dumper); + // bool TraverseDecl(Decl *D); - //bool VisitOMPExecutableDirective(OMPExecutableDirective * D); - //bool VisitDeclRefExpr(DeclRefExpr * D); - bool VisitCXXConstructExpr(CXXConstructExpr * D); + // bool VisitOMPExecutableDirective(OMPExecutableDirective * D); + // bool VisitDeclRefExpr(DeclRefExpr * D); + bool VisitCXXConstructExpr(CXXConstructExpr *D); bool VisitExpr(Expr *D); bool VisitLambdaExpr(LambdaExpr *D); bool VisitTypeDecl(TypeDecl *D); @@ -142,7 +165,6 @@ class PrintNodesTypesRelationsVisitor : public RecursiveASTVisitor Date: Tue, 28 Mar 2023 19:12:17 +0100 Subject: [PATCH 32/68] Remove unused code --- ClangAstDumper/src/ClangAst.cpp | 264 +------------------------------- 1 file changed, 6 insertions(+), 258 deletions(-) diff --git a/ClangAstDumper/src/ClangAst.cpp b/ClangAstDumper/src/ClangAst.cpp index 3420a2cb8..299b9f9c0 100644 --- a/ClangAstDumper/src/ClangAst.cpp +++ b/ClangAstDumper/src/ClangAst.cpp @@ -31,7 +31,6 @@ using namespace clang; -//#define OLD_OUTPUT static llvm::cl::OptionCategory ToolingSampleCategory("Tooling Sample"); @@ -44,18 +43,11 @@ static constexpr const char* const PREFIX = "COUNTER"; bool DumpAstVisitor::TraverseDecl(Decl *D) { FullSourceLoc fullLocation = Context->getFullLoc(D->getBeginLoc()); if (fullLocation.isValid() && !fullLocation.isInSystemHeader()) { -#ifdef OLD_OUTPUT - (*D).dump(llvm::outs()); -#endif + // Top-level Node llvm::errs() << TOP_LEVEL_NODES << "\n"; llvm::errs() << D << "_" << id << "\n"; - // If it is not being visited, if this is called it can give an error - // Visit Top Node - // Experiment: can this visitor replace all other visitors? - //dumper.VisitDeclTop(D); - //dumper->VisitDeclTop(D); } return false; @@ -64,36 +56,10 @@ bool DumpAstVisitor::TraverseDecl(Decl *D) { -//bool PrintNodesTypesRelationsVisitor::TraverseDecl(Decl *D) { -/* - FullSourceLoc fullLocation = Context->getFullLoc(D->getLocStart()); - if (fullLocation.isValid() && !fullLocation.isInSystemHeader()) { - // Visit Top Node - // Experiment: can this visitor replace all other visitors? - dumper.VisitDeclTop(D); - } - -*/ -// return RecursiveASTVisitor::TraverseDecl(D); - /* - FullSourceLoc fullLocation = Context->getFullLoc(D->getLocStart()); - if (fullLocation.isValid() && !fullLocation.isInSystemHeader()) { - // Visit Top Node - // Experiment: can this visitor replace all other visitors? - dumper.VisitDeclTop(D); - //dumper->VisitDeclTop(D); - } - - // TODO: If at some moment dumper provides all information, this can be set to false - return true; -*/ -//} - PrintNodesTypesRelationsVisitor::PrintNodesTypesRelationsVisitor(ASTContext *Context, int id, ClangAstDumper dumper) : Context(Context), id(id), dumper(dumper) {}; -//PrintNodesTypesRelationsVisitor::PrintNodesTypesRelationsVisitor(ASTContext *Context, int id, ClangAstDumper *dumper) : Context(Context), id(id), dumper(dumper) {}; static std::string stmt2str(clang::Stmt *d, clang::SourceManager *sm, clang::LangOptions lopt) { clang::SourceLocation b(d->getBeginLoc()), _e(d->getEndLoc()); @@ -111,50 +77,6 @@ static std::string stmt2str(clang::Stmt *d, clang::SourceManager *sm, clang::Lan return std::string(sm->getCharacterData(b), sm->getCharacterData(e)-sm->getCharacterData(b)); } - -/* - bool PrintNodesTypesRelationsVisitor::VisitOMPExecutableDirective(OMPExecutableDirective * D) { - - FullSourceLoc fullLocation = Context->getFullLoc(D->getBeginLoc()); - - if (!fullLocation.isInSystemHeader()) { - // Get OMP Directive - DumpResources::omp << D << "_" << id << "->" << stmt2str(D, &Context->getSourceManager(), Context->getLangOpts()) << "\n"; - DumpResources::omp << "NUM_CLAUSES" << "->" << D->getNumClauses() << "\n"; - for(unsigned i=0; igetNumClauses(); i++) { - OMPClause* clause = D->getClause(i); - DumpResources::omp << clause->getClauseKind() << "->" << loc2str(clause->getBeginLoc(), clause->getEndLoc(), Context) << "\n"; - } - } - - return true; - } -*/ - -/* - bool PrintNodesTypesRelationsVisitor::VisitDeclRefExpr(DeclRefExpr * D) { - - FullSourceLoc fullLocation = Context->getFullLoc(D->getLocStart()); - - if (!fullLocation.isInSystemHeader()) { - if (D->getQualifier() != nullptr) { - llvm::errs() << "DECL_REF_EXPR QUALIFIER BEGIN\n"; - llvm::errs() << D << "_" << id << "\n"; - D->getQualifier()->dump(); - llvm::errs() << "\nDECL_REF_EXPR QUALIFIER END\n"; - } - - - if(D->hasExplicitTemplateArgs()) { - DumpResources::template_args << D << "_" << id << "\n"; - } - - } - return true; - } -*/ - - bool PrintNodesTypesRelationsVisitor::VisitCXXConstructExpr(CXXConstructExpr * D) { FullSourceLoc fullLocation = Context->getFullLoc(D->getBeginLoc()); @@ -173,28 +95,10 @@ static std::string stmt2str(clang::Stmt *d, clang::SourceManager *sm, clang::Lan // Dump types for Expr, TypeDecl and ValueDecl, as well as the connection between them bool PrintNodesTypesRelationsVisitor::VisitExpr(Expr *D) { -#ifdef OLD_OUTPUT - FullSourceLoc fullLocation = Context->getFullLoc(D->getBeginLoc()); - if (fullLocation.isValid() && !fullLocation.isInSystemHeader()) { - //if(D->getType().isNull()) { - // llvm::errs() << "VisitExpr null type\n"; - //} - dumpNodeToType(DumpResources::nodetypes,D, D->getType()); - - } -#endif return true; } bool PrintNodesTypesRelationsVisitor::VisitTypeDecl(TypeDecl *D) { - -#ifdef OLD_OUTPUT - FullSourceLoc fullLocation = Context->getFullLoc(D->getBeginLoc()); - if (fullLocation.isValid() && !fullLocation.isInSystemHeader()) { - //llvm::errs() << "Visiting Type Decl: " << D << "\n"; - dumpNodeToType(DumpResources::nodetypes, D, D->getTypeForDecl()); - } -#endif return true; } @@ -204,16 +108,6 @@ static std::string stmt2str(clang::Stmt *d, clang::SourceManager *sm, clang::Lan * @return */ bool PrintNodesTypesRelationsVisitor::VisitTypedefNameDecl(TypedefNameDecl *D) { -#ifdef OLD_OUTPUT - FullSourceLoc fullLocation = Context->getFullLoc(D->getBeginLoc()); - if (fullLocation.isValid() && !fullLocation.isInSystemHeader()) { - //if(D->getUnderlyingType().isNull()) { - // llvm::errs() << "VisitNameDecl null type\n"; - //} - dumpNodeToType(DumpResources::nodetypes, D, D->getUnderlyingType()); - - } -#endif return true; } @@ -234,18 +128,6 @@ static std::string stmt2str(clang::Stmt *d, clang::SourceManager *sm, clang::Lan bool PrintNodesTypesRelationsVisitor::VisitValueDecl(ValueDecl *D) { -#ifdef OLD_OUTPUT - FullSourceLoc fullLocation = Context->getFullLoc(D->getLocStart()); - if (fullLocation.isValid() && !fullLocation.isInSystemHeader()) { - //llvm::errs() << "Visiting Value Decl: " << D << "\n"; - //if(D->getType().isNull()) { - // llvm::errs() << "VisitValueDecl null type\n"; - //} - dumpNodeToType(DumpResources::nodetypes, D, D->getType()); - - return true; - } -#endif return true; } @@ -275,20 +157,6 @@ static std::string stmt2str(clang::Stmt *d, clang::SourceManager *sm, clang::Lan } bool PrintNodesTypesRelationsVisitor::VisitLambdaExpr(LambdaExpr *D) { - - #ifdef OLD_OUTPUT - FullSourceLoc fullLocation = Context->getFullLoc(D->getBeginLoc()); - if (fullLocation.isValid() && !fullLocation.isInSystemHeader()) { - // Dump self - dumpNodeToType(DumpResources::nodetypes,D, D->getType()); - - // Traverse lambda class - TraverseCXXRecordDecl(D->getLambdaClass()); - //TraverseDecl(D->getLambdaClass()); - //VisitTypeDecl(D->getLambdaClass()); - } - #endif - return true; } @@ -297,7 +165,6 @@ void PrintNodesTypesRelationsVisitor::dumpNodeToType(std::ofstream &stream, void // Opaque pointer, so that we can obtain the qualifiers void* typeAddr = !type.isNull() ? type.getAsOpaquePtr() : nullptr; - //const Type* typeAddr = type.getTypePtrOrNull(); if(checkDuplicates) { if(seenNodes.count(nodeAddr) == 0) { @@ -310,7 +177,6 @@ void PrintNodesTypesRelationsVisitor::dumpNodeToType(std::ofstream &stream, void dumper.VisitTypeTop(type); - //dumper->VisitTypeTop(type); } @@ -331,32 +197,11 @@ void PrintNodesTypesRelationsVisitor::dumpNodeToType(std::ofstream &stream, void } dumper.VisitTypeTop(typeAddr); - // dumper->VisitTypeTop(typeAddr); } -/* -ClangAstDumper PrintNodesTypesRelationsVisitor::getDumper() { - return dumper; - } -*/ -/* - MyASTConsumer::MyASTConsumer(ASTContext *C, int id) : topLevelDeclVisitor(C, id), printRelationsVisitor(C, id), id(id) { - std::ofstream consumer; - consumer.open("consumer_order.txt", std::ofstream::app); - consumer << "ASTConsumer built " << id << "\n"; - consumer.close(); - } -*/ MyASTConsumer::MyASTConsumer(ASTContext *C, int id, ClangAstDumper dumper) : id(id) -//MyASTConsumer::MyASTConsumer(ASTContext *C, int id, ClangAstDumper *dumper) : id(id) ,topLevelDeclVisitor(C, id), printRelationsVisitor(C, id, dumper) { -/* - this->id = id; - this->dumper = ClangAstDumper(C, id); - topLevelDeclVisitor = DumpAstVisitor(C, id, dumper); - printRelationsVisitor = PrintNodesTypesRelationsVisitor(C, id, dumper); -*/ - //dumper(C, id), topLevelDeclVisitor(C, id, dumper), printRelationsVisitor(C, id, dumper), id(id) + std::ofstream consumer; consumer.open("consumer_order.txt", std::ofstream::app); consumer << "ASTConsumer built " << id << "\n"; @@ -390,26 +235,7 @@ MyASTConsumer::MyASTConsumer(ASTContext *C, int id, ClangAstDumper dumper) : id( } void MyASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { - /* - for (auto b = Ctx.getTranslationUnitDecl()->decls().begin(), e = Ctx.getTranslationUnitDecl()->decls().end(); b != e; ++b) { - //counter++; - //llvm::errs() << "Decl kind: " << (*b)->getKind() << " decls\n"; - topLevelDeclVisitor.TraverseDecl(*b); - } - - for (auto b = Ctx.getTranslationUnitDecl()->decls().begin(), e = Ctx.getTranslationUnitDecl()->decls().end(); b != e; ++b) { - printRelationsVisitor.TraverseDecl(*b); - } - - //llvm::errs() << "Found " << counter << " decls\n"; - - int counter = 0; - llvm::errs() << "After translation unit\n"; - for (auto b = Ctx.getTranslationUnitDecl()->decls().begin(), e = Ctx.getTranslationUnitDecl()->decls().end(); b != e; ++b) { - counter++; - llvm::errs() << "Decl kind: " << (*b)->getKind() << " decls\n"; - } - */ + } @@ -431,11 +257,6 @@ MyASTConsumer::MyASTConsumer(ASTContext *C, int id, ClangAstDumper dumper) : id( counter = DumpResources::runId; } -#ifdef OLD_OUTPUT - DumpResources::writeCounter(counter); -#endif - //llvm::errs() << "CUSTOM ID: " << DumpResources::runId << "\n"; - dumpCompilerInstanceData(CI, file); @@ -449,14 +270,12 @@ MyASTConsumer::MyASTConsumer(ASTContext *C, int id, ClangAstDumper dumper) : id( ClangAstDumper dumper(Context, counter, DumpResources::systemHeaderThreshold); return std::make_unique(Context, counter, dumper); - //return llvm::make_unique(Context, counter, &dumper); } void DumpAstAction::dumpCompilerInstanceData(CompilerInstance &CI, StringRef file) { clava::dump(COMPILER_INSTANCE_DATA); - //llvm::errs() << "File\n"; clava::dump(file.str()); clava::dump(CI.getInvocation().getLangOpts()->LineComment); @@ -522,16 +341,8 @@ MyASTConsumer::MyASTConsumer(ASTContext *C, int id, ClangAstDumper dumper) : id( bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { - //clang::SourceManager &sm = compilerInstance.getSourceManager(); - + if (!sm.isInSystemHeader(HashLoc)) { -#ifdef OLD_OUTPUT - DumpResources::includes << "source:" << sm.getFilename(HashLoc).str() << "|"; - DumpResources::includes << "include:" << FileName.str() << "|"; - DumpResources::includes << "line:" << sm.getSpellingLineNumber(HashLoc) << "|"; - DumpResources::includes << "angled:" << IsAngled ? "true" : "false"; - DumpResources::includes << "\n"; -#endif // Includes information in stream llvm::errs() << INCLUDES << "\n"; // Source @@ -545,8 +356,7 @@ MyASTConsumer::MyASTConsumer(ASTContext *C, int id, ClangAstDumper dumper) : id( void IncludeDumper::PragmaDirective(SourceLocation Loc, PragmaIntroducerKind Introducer) { - //clang::SourceManager &sm = compilerInstance.getSourceManager(); - + // Ignore system headers if(sm.isInSystemHeader(Loc)) { return; @@ -560,57 +370,11 @@ MyASTConsumer::MyASTConsumer(ASTContext *C, int id, ClangAstDumper dumper) : id( } void IncludeDumper::FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID) { -//llvm::errs() << "File changed: " << sm.getFilename(Loc) << "\n"; -//llvm::errs() << "Reason: " << Reason << "\n"; + } void IncludeDumper::MacroExpands(const Token & MacroNameTok, const MacroDefinition & MD, SourceRange Range, const MacroArgs * Args) { -/* - llvm::errs() << "Dumping Macro info:\n"; - MD.getMacroInfo()->dump(); - llvm::errs() << "\n"; - //llvm::errs() << "\nDumping Macro info end\n"; - - - llvm::errs() << "Definition begin:\n"; - MD.getMacroInfo()->getDefinitionLoc().dump(compilerInstance.getSourceManager()); - llvm::errs() << "\nDefinition length: " << MD.getMacroInfo()->getDefinitionLength(compilerInstance.getSourceManager()) <<"\n"; - llvm::errs() << "\n"; - //llvm::errs() << "\nDefinition begin end\n"; - llvm::errs() << "Expansion begin:\n"; - Range.getBegin().dump(compilerInstance.getSourceManager()); - llvm::errs() << "\n"; - - */ - - - -/* - llvm::errs() << "Is id: " << MacroNameTok.isAnyIdentifier() << "\n"; - if(MacroNameTok.isAnyIdentifier()) { - llvm::errs() << "RAW id: " << MacroNameTok.getRawIdentifier().str() << "\n"; - } - llvm::errs() << "Kind: " << MacroNameTok.getKind() << "\n"; - */ - // llvm::errs() << "ID INFO: " << MacroNameTok. << "\n"; -// llvm::errs() << "Token begin:\n"; - // MacroNameTok.getLocation().dump(compilerInstance.getSourceManager()); - // llvm::errs() << "\nToken end\n"; - - - //llvm::errs() << "\nSource begin end\n"; - -/* - llvm::errs() << "Source end:\n"; - Range.getEnd().dump(compilerInstance.getSourceManager()); - llvm::errs() << "\nSource end end\n"; -*/ -/* - if(MacroNameTok.isLiteral()) { - llvm::errs() << "Token literal: " << MacroNameTok.getLiteralData() << "\n"; - } -*/ } @@ -648,7 +412,6 @@ MyASTConsumer::MyASTConsumer(ASTContext *C, int id, ClangAstDumper dumper) : id( // File instantiations std::ofstream DumpResources::includes; std::ofstream DumpResources::nodetypes; -//std::ofstream DumpResources::template_args; std::ofstream DumpResources::is_temporary; std::ofstream DumpResources::omp; std::ofstream DumpResources::enum_integer_type; @@ -675,14 +438,6 @@ void DumpResources::init(int runId, int systemLevelThreshold) { DumpResources::runId = runId; DumpResources::systemHeaderThreshold = systemLevelThreshold; - // Clear files -#ifdef OLD_OUTPUT - DumpResources::includes.open("includes.txt", std::ofstream::out | std::fstream::trunc); - DumpResources::nodetypes.open("nodetypes.txt", std::ofstream::out | std::ofstream::trunc); -#endif - - - //DumpResources::template_args.open("template_args.txt", std::ofstream::out | std::ofstream::trunc); DumpResources::is_temporary.open("is_temporary.txt", std::ofstream::out | std::ofstream::trunc); DumpResources::omp.open("omp.txt", std::ofstream::out | std::ofstream::trunc); DumpResources::enum_integer_type.open("enum_integer_type.txt", std::ofstream::out | std::ofstream::trunc); @@ -691,13 +446,6 @@ void DumpResources::init(int runId, int systemLevelThreshold) { } void DumpResources::finish() { -#ifdef OLD_OUTPUT - DumpResources::includes.close(); - DumpResources::nodetypes.close(); -#endif - - - //DumpResources::template_args.close(); DumpResources::is_temporary.close(); DumpResources::omp.close(); DumpResources::enum_integer_type.close(); From 5026ced1506ab569ac34bf81df83f73389103611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Thu, 6 Apr 2023 14:41:13 +0100 Subject: [PATCH 33/68] [ClavaAst] Changes some methods in DeclRefExpr to refer to Decl --- .../fe/specs/clava/ast/expr/DeclRefExpr.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/ClavaAst/src/pt/up/fe/specs/clava/ast/expr/DeclRefExpr.java b/ClavaAst/src/pt/up/fe/specs/clava/ast/expr/DeclRefExpr.java index 91aad8825..5eb6bcd60 100644 --- a/ClavaAst/src/pt/up/fe/specs/clava/ast/expr/DeclRefExpr.java +++ b/ClavaAst/src/pt/up/fe/specs/clava/ast/expr/DeclRefExpr.java @@ -50,7 +50,8 @@ public class DeclRefExpr extends Expr implements Nameable { // DATAKEY BEGIN /** - * The nested-name qualifier that precedes the name, or empty string if it has none. + * The nested-name qualifier that precedes the name, or empty string if it has + * none. */ public final static DataKey QUALIFIER = KeyFactory.string("qualifier"); @@ -240,18 +241,18 @@ public Expr getUseExpr() { DeclRefKind kind = getKind(); switch (kind) { - case VAR_ACCESS: - return this; - case ARRAY_ACCESS: - return getArrayAccessExpr(this); - case FUNCTION_CALL: - case POINTER_ACCESS: - case ADDRESS_OF: - return (Expr) ClavaNodes.getParentNormalized(this); - case UNKNOWN: - return this; - default: - throw new CaseNotDefinedException(kind); + case VAR_ACCESS: + return this; + case ARRAY_ACCESS: + return getArrayAccessExpr(this); + case FUNCTION_CALL: + case POINTER_ACCESS: + case ADDRESS_OF: + return (Expr) ClavaNodes.getParentNormalized(this); + case UNKNOWN: + return this; + default: + throw new CaseNotDefinedException(kind); } } From b43d36fe75ec8f07d422b156cf5e318d99a6b48f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Thu, 6 Apr 2023 14:49:57 +0100 Subject: [PATCH 34/68] Using standard clang binary for compilation --- ClangAstDumper/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ClangAstDumper/CMakeLists.txt b/ClangAstDumper/CMakeLists.txt index 48ccf89c7..973dba17f 100644 --- a/ClangAstDumper/CMakeLists.txt +++ b/ClangAstDumper/CMakeLists.txt @@ -3,11 +3,11 @@ project(ClangAstDumper) set(LLVM_VERSION 14) -SET(CMAKE_C_COMPILER "clang-14") -SET(CMAKE_CXX_COMPILER "clang++-14") +SET(CMAKE_C_COMPILER "clang") +SET(CMAKE_CXX_COMPILER "clang++") find_package(Clang REQUIRED CONFIG) -include_directories(/usr/lib/llvm-14/include) +include_directories(C:/msys64/mingw64/include) set(SOURCE_FILES From c7b9a889c8e775f7dc9915a5cbf1cd21f0a81d73 Mon Sep 17 00:00:00 2001 From: "L. Sousa" Date: Sat, 27 Apr 2024 19:43:23 +0100 Subject: [PATCH 35/68] Refactor CMakeLists.txt --- ClangAstDumper/CMakeLists.txt | 100 ++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 46 deletions(-) diff --git a/ClangAstDumper/CMakeLists.txt b/ClangAstDumper/CMakeLists.txt index 973dba17f..d9f77e0c2 100644 --- a/ClangAstDumper/CMakeLists.txt +++ b/ClangAstDumper/CMakeLists.txt @@ -1,58 +1,66 @@ cmake_minimum_required(VERSION 3.14) project(ClangAstDumper) -set(LLVM_VERSION 14) +set(CLANG_VERSION 14) + +SET(CMAKE_C_COMPILER "clang-${CLANG_VERSION}") +SET(CMAKE_CXX_COMPILER "clang++-${CLANG_VERSION}") + +#SET(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL) +#SET(CMAKE_FIND_PACKAGE_SORT_DIRECTION DEC) + +SET(Clang_DIR "/usr/lib/cmake/clang-${CLANG_VERSION}") +SET(LLVM_DIR "/usr/lib/llvm-${CLANG_VERSION}/lib/cmake/llvm") -SET(CMAKE_C_COMPILER "clang") -SET(CMAKE_CXX_COMPILER "clang++") find_package(Clang REQUIRED CONFIG) -include_directories(C:/msys64/mingw64/include) +include_directories("/usr/lib/clang/${CLANG_VERSION}/include/") +include_directories("/usr/lib/llvm-${CLANG_VERSION}/include/") set(SOURCE_FILES - src/newmain.cpp - src/ClangAst.cpp - src/ClangNodes.cpp - src/TypeMarker.cpp - src/ClavaDataDumper.cpp - src/ClavaDataDumperAttrs.cpp - src/ClavaDataDumperDecls.cpp - src/ClavaDataDumperStmts.cpp - src/ClavaDataDumperTypes.cpp - src/ClavaConstants.cpp - src/ClavaDecl.cpp - src/ChildrenVisitorAttrs.cpp - src/ChildrenVisitorDecls.cpp - src/ChildrenVisitorExtras.cpp - src/ChildrenVisitorStmts.cpp - src/ChildrenVisitorTypes.cpp - src/ClangAstDumper.cpp - src/ClangAstDumperAttr.cpp - src/ClangAstDumperDecls.cpp - src/ClangAstDumperExprs.cpp - src/ClangAstDumperExtra.cpp - src/ClangAstDumperStmts.cpp - src/ClangAstDumperTypes.cpp - src/ClangEnums.cpp - src/enums_Type_h.cpp - src/enums_OperationKinds_h.cpp - src/enums_AttrKinds_h.cpp - src/enums_Specifiers_h.cpp - src/enums_ExceptionSpecificationType_h.cpp - src/enums_Linkage_h.cpp - src/enums_Visibility_h.cpp - src/enums_TemplateBase_h.cpp - src/enums_Decl_h.cpp - src/enums_ExprCXX_h.cpp - src/enums_TypeTraits_h.cpp - src/enums_NestedNameSpecifier_h.cpp - src/enums_DeclCxx_h.cpp - src/enums_Lambda_h.cpp - src/enums_TemplateName_h.cpp - src/enums_Attr_h.cpp - src/enums_Expr_h.cpp - ) + src/newmain.cpp + src/ClangAst.cpp + src/ClangNodes.cpp + src/TypeMarker.cpp + src/ClavaDataDumper.cpp + src/ClavaDataDumperAttrs.cpp + src/ClavaDataDumperDecls.cpp + src/ClavaDataDumperStmts.cpp + src/ClavaDataDumperTypes.cpp + src/ClavaConstants.cpp + src/ClavaDecl.cpp + src/ChildrenVisitorAttrs.cpp + src/ChildrenVisitorDecls.cpp + src/ChildrenVisitorExtras.cpp + src/ChildrenVisitorStmts.cpp + src/ChildrenVisitorTypes.cpp + src/ClangAstDumper.cpp + src/ClangAstDumperAttr.cpp + src/ClangAstDumperDecls.cpp + src/ClangAstDumperExprs.cpp + src/ClangAstDumperExtra.cpp + src/ClangAstDumperStmts.cpp + src/ClangAstDumperTypes.cpp + src/ClangEnums.cpp + src/enums_Type_h.cpp + src/enums_OperationKinds_h.cpp + src/enums_AttrKinds_h.cpp + src/enums_Specifiers_h.cpp + src/enums_ExceptionSpecificationType_h.cpp + src/enums_Linkage_h.cpp + src/enums_Visibility_h.cpp + src/enums_TemplateBase_h.cpp + src/enums_Decl_h.cpp + src/enums_ExprCXX_h.cpp + src/enums_TypeTraits_h.cpp + src/enums_NestedNameSpecifier_h.cpp + src/enums_DeclCxx_h.cpp + src/enums_Lambda_h.cpp + src/enums_TemplateName_h.cpp + src/enums_Attr_h.cpp + src/enums_Expr_h.cpp + ) add_library(MyPlugin SHARED ${SOURCE_FILES}) From 6788124a6853a4eade165acdc678488ab2de309a Mon Sep 17 00:00:00 2001 From: "L. Sousa" Date: Tue, 30 Apr 2024 20:04:15 +0100 Subject: [PATCH 36/68] Refactor clang_enums code Removed old clava config file Removed commented code from scripts Added type documentation to the extraction scripts Updated the cmake configuration to support newer versions of llvm Added a .gitignore file to ignore all the files generated by the build process --- ClangAstDumper/.gitignore | 1 + ClangAstDumper/clang_enums/.gitignore | 10 + ClangAstDumper/clang_enums/CMakeLists.txt | 55 +---- ClangAstDumper/clang_enums/ClangEnum.js | 79 +++----- ClangAstDumper/clang_enums/ClangEnums.js | 106 +++++----- ClangAstDumper/clang_enums/Extractors.js | 26 +-- ClangAstDumper/clang_enums/HeaderEnums.js | 84 +++----- ClangAstDumper/clang_enums/Main.js | 106 ---------- ClangAstDumper/clang_enums/config.clava | 236 ---------------------- 9 files changed, 138 insertions(+), 565 deletions(-) create mode 100644 ClangAstDumper/clang_enums/.gitignore delete mode 100644 ClangAstDumper/clang_enums/config.clava diff --git a/ClangAstDumper/.gitignore b/ClangAstDumper/.gitignore index b03e30d73..470f97119 100644 --- a/ClangAstDumper/.gitignore +++ b/ClangAstDumper/.gitignore @@ -1,4 +1,5 @@ .vscode +.cache build CMakeFiles/ cmake_install.cmake diff --git a/ClangAstDumper/clang_enums/.gitignore b/ClangAstDumper/clang_enums/.gitignore new file mode 100644 index 000000000..167960718 --- /dev/null +++ b/ClangAstDumper/clang_enums/.gitignore @@ -0,0 +1,10 @@ +.vscode +.cache +CMakeFiles/ +cmake_install.cmake +CMakeCache.txt + +Clava.jar +Clava_system_options.xml +ClavaWeaver_lib/ +EnumGen_clava_weave/ \ No newline at end of file diff --git a/ClangAstDumper/clang_enums/CMakeLists.txt b/ClangAstDumper/clang_enums/CMakeLists.txt index eebdeb157..26310b80f 100644 --- a/ClangAstDumper/clang_enums/CMakeLists.txt +++ b/ClangAstDumper/clang_enums/CMakeLists.txt @@ -1,17 +1,17 @@ cmake_minimum_required(VERSION 3.2) project(ClangEnumGenerator) -# Initialize Deps -include("../../deps.cmake") +set(CLANG_VERSION 15) + +SET(CMAKE_C_COMPILER "clang-${CLANG_VERSION}") +SET(CMAKE_CXX_COMPILER "clang++-${CLANG_VERSION}") + +SET(Clang_DIR "/usr/lib/cmake/clang-${CLANG_VERSION}") +SET(LLVM_DIR "/usr/lib/llvm-${CLANG_VERSION}/lib/cmake/llvm") # Add Modules -#deps_find_package(llvm3.8 REQUIRED) # LLVM -#deps_find_package(llvm7 REQUIRED) # LLVM -#deps_find_package(llvm12 REQUIRED) # LLVM -deps_find_package(llvm14.0.6 REQUIRED) # LLVM +find_package(LLVM REQUIRED) # LLVM -# Set base llvm dir -set(LLVM_DIR ${llvm14.0.6_DIR}) set(COMMON_CXX_FLAGS "-O3 -Wall -Wno-unused-function") @@ -24,42 +24,3 @@ message(STATUS "LLVM DIR: ${LLVM_DIR}") add_library(EnumGen) clava_weave(EnumGen "Main.js" ARGS "llvmFolder:'${LLVM_DIR}', outputFolder:'${CMAKE_CURRENT_LIST_DIR}/..'" JAVA_FLAGS -Xmx8000m) - - -# Make enum extractor available -#include(${CMAKE_CURRENT_LIST_DIR}/ExtractEnums.cmake) - -#extract_enums("${LLVM_DIR}/src/include/clang/AST" "Type.h") -#extract_enums("${LLVM_DIR}/src/include/clang/AST" "OperationKinds.h") -#extract_enums("${LLVM_DIR}/src/include/clang/Basic" "AttrKinds.h") -#extract_enums("${LLVM_DIR}/src/include/clang/Basic" "Specifiers.h") -#extract_enums("${LLVM_DIR}/src/include/clang/Basic" "ExceptionSpecificationType.h") -#extract_enums("${LLVM_DIR}/src/include/clang/Basic" "Linkage.h") -#extract_enums("${LLVM_DIR}/src/include/clang/Basic" "Visibility.h") -#extract_enums("${LLVM_DIR}/src/include/clang/AST" "TemplateBase.h") -#extract_enums("${LLVM_DIR}/src/include/clang/AST" "Decl.h") -#extract_enums("${LLVM_DIR}/src/include/clang/AST" "ExprCXX.h") -#extract_enums("${LLVM_DIR}/src/include/clang/Basic" "TypeTraits.h") -#extract_enums("${LLVM_DIR}/src/include/clang/AST" "NestedNameSpecifier.h") -#extract_enums("${LLVM_DIR}/src/include/clang/AST" "DeclCxx.h") -#extract_enums("${LLVM_DIR}/src/include/clang/Basic" "Lambda.h") -#extract_enums("${LLVM_DIR}/src/include/clang/AST" "TemplateName.h") -#extract_enums("${LLVM_DIR}/src/include/clang/AST" "Attr.h") -#extract_enums("${LLVM_DIR}/src/include/clang/AST" "Expr.h") - - -# Create target for clang/AST/Type.h -#add_library(Type_H "${LLVM_DIR}/src/include/clang/AST/Type.h") - -#set_property(TARGET Type_H PROPERTY CXX_STANDARD 14) - -# Because it is a header file, it cannot figure it out alone -#set_target_properties(Type_H PROPERTIES LINKER_LANGUAGE CXX) - -# Add includes -#target_include_directories(Type_H -# SYSTEM PUBLIC ${DEPS_INCLUDES} -#) - -# Add enums helper -#clava_weave(Type_H "ClangEnumsGenerator.lara" ARGS "header:'Type.h', outputFolder:'${CMAKE_CURRENT_LIST_DIR}/..'" JAVA_FLAGS -Xmx8000m) diff --git a/ClangAstDumper/clang_enums/ClangEnum.js b/ClangAstDumper/clang_enums/ClangEnum.js index e641c7cd6..b5910ff88 100644 --- a/ClangAstDumper/clang_enums/ClangEnum.js +++ b/ClangAstDumper/clang_enums/ClangEnum.js @@ -5,35 +5,39 @@ laraImport("Extractors"); * @class */ class ClangEnum { - constructor(name, cppVarName, mapper, excludeArray, className) { + /** + * + * @param {string} name Name of the enum + * @param {string} cppVarName Original name of the enum in the C++ source files + * @param {(string) => string} mapper + * @param {string[]} excludeArray + * @param {string | undefined} className + */ + constructor( + name, + cppVarName, + mapper = (el) => el, + excludeArray = [], + className = undefined + ) { + mapper ??= (el) => el; + excludeArray ??= []; + this.name = name; this.cppVarName = cppVarName; - - if (mapper === undefined) { - mapper = (element) => element; - } this.mapper = mapper; - - if (excludeArray === undefined) { - excludeArray = []; - } this.excludeSet = new StringSet(excludeArray); - //println("Exclude set: " + this.excludeSet.values()); - this.className = className; - this.enumValues = undefined; - - /* - if (extractor == undefined) { - extractor = Extractors.simpleExtractor; - } - this.extractor = extractor; - */ this.extractor = Extractors.simpleExtractor; this.occurence = 1; } + /** + * + * @param {number} occurence + * @returns + */ setOccurence(occurence) { this.occurence = occurence; return this; @@ -55,48 +59,25 @@ class ClangEnum { return this.className; } - /* -ClangEnum.prototype.getStartingNode = function() { - if(this.className === undefined) { - return Query.root(); - } - - var startingClass = Query.search("class", this.className).first(); - - if(startingClass === undefined) { - throw new Error("Clang enum specifies class '"+this.className+"', but it could not be found"); - } - - return startingClass; -} -*/ - + /** + * + * @param {string[]} headerLines + */ setEnumValues(headerLines) { this.enumValues = this.extractor(this.name, headerLines, this.occurence); } - /* - setEnumValues(enumValues) { - if (this.enumValues !== undefined) { - println("Setting enum values again for enum " + this.name); - } - - this.enumValues = enumValues; - } - */ - getCode() { if (this.enumValues === undefined) { println("No enum values set for enum '" + this.name + "'"); return undefined; } - var code = ""; + let code = ""; code += "extern const std::string clava::" + this.cppVarName + "[] = {\n"; - for (var enumValue of this.enumValues) { - //println("Enum: " + enumValue); + for (let enumValue of this.enumValues) { if (this.excludeSet.has(enumValue.toString())) { println("Excluded enum '" + enumValue + "'"); continue; @@ -105,7 +86,7 @@ ClangEnum.prototype.getStartingNode = function() { // Map enum value enumValue = this.mapper(enumValue); - code += ' "' + enumValue + '",\n'; + code += ` "${enumValue}",\n`; } code += "};\n"; diff --git a/ClangAstDumper/clang_enums/ClangEnums.js b/ClangAstDumper/clang_enums/ClangEnums.js index b8304e86a..045cd5445 100644 --- a/ClangAstDumper/clang_enums/ClangEnums.js +++ b/ClangAstDumper/clang_enums/ClangEnums.js @@ -6,7 +6,7 @@ laraImport("weaver.Query"); * @class */ class ClangEnums { - static _TYPE_H = new HeaderEnums("src/include/clang/AST/Type.h", [ + static _TYPE_H = new HeaderEnums("../../../include/clang/AST/Type.h", [ new ClangEnum("Kind", "BUILTIN_KIND", undefined, ["LastKind"]).setOccurence( 3 ), @@ -38,7 +38,7 @@ class ClangEnums { ]); static _OPERATIONS_KINDS_H = new HeaderEnums( - "src/include/clang/AST/OperationKinds.h", + "../../../include/clang/AST/OperationKinds.h", [ new ClangEnum( "CastKind", @@ -62,12 +62,12 @@ class ClangEnums { ); static _ATTR_KINDS_H = new HeaderEnums( - "src/include/clang/Basic/AttrKinds.h", + "../../../include/clang/Basic/AttrKinds.h", [new ClangEnum("Kind", "ATTRIBUTES", undefined, undefined)] ); static _SPECIFIERS_H = new HeaderEnums( - "src/include/clang/Basic/Specifiers.h", + "../../../include/clang/Basic/Specifiers.h", [ new ClangEnum( "CallingConv", @@ -103,7 +103,7 @@ class ClangEnums { ); static _EXCEPTION_SPECIFICATION_TYPE_H = new HeaderEnums( - "src/include/clang/Basic/ExceptionSpecificationType.h", + "../../../include/clang/Basic/ExceptionSpecificationType.h", [ new ClangEnum( "ExceptionSpecificationType", @@ -114,7 +114,7 @@ class ClangEnums { ] ); - static _LINKAGE_H = new HeaderEnums("src/include/clang/Basic/Linkage.h", [ + static _LINKAGE_H = new HeaderEnums("../../../include/clang/Basic/Linkage.h", [ new ClangEnum( "Linkage", "LINKAGE", @@ -124,7 +124,7 @@ class ClangEnums { ]); static _VISIBILITY_H = new HeaderEnums( - "src/include/clang/Basic/Visibility.h", + "../../../include/clang/Basic/Visibility.h", [ new ClangEnum( "Visibility", @@ -136,11 +136,11 @@ class ClangEnums { ); static _TEMPLATE_BASE_H = new HeaderEnums( - "src/include/clang/AST/TemplateBase.h", + "../../../include/clang/AST/TemplateBase.h", [new ClangEnum("ArgKind", "TEMPLATE_ARG_KIND", undefined, undefined)] ); - static _DECL_H = new HeaderEnums("src/include/clang/AST/Decl.h", [ + static _DECL_H = new HeaderEnums("../../../include/clang/AST/Decl.h", [ new ClangEnum( "InitializationStyle", "INIT_STYLE", @@ -161,7 +161,7 @@ class ClangEnums { ListInit: "LIST_INIT", }; - static _EXPR_CXX_H = new HeaderEnums("src/include/clang/AST/ExprCXX.h", [ + static _EXPR_CXX_H = new HeaderEnums("../../../include/clang/AST/ExprCXX.h", [ new ClangEnum( "InitializationStyle", "NEW_INIT_STYLE", @@ -183,7 +183,7 @@ class ClangEnums { }; static _TYPE_TRAITS_H = new HeaderEnums( - "src/include/clang/Basic/TypeTraits.h", + "../../../include/clang/Basic/TypeTraits.h", [ new ClangEnum( "UnaryExprOrTypeTrait", @@ -195,7 +195,7 @@ class ClangEnums { ); static _NESTED_NAME_SPECIFIER_H = new HeaderEnums( - "src/include/clang/AST/NestedNameSpecifier.h", + "../../../include/clang/AST/NestedNameSpecifier.h", [ new ClangEnum( "SpecifierKind", @@ -206,7 +206,7 @@ class ClangEnums { ] ); - static _DECL_CXX_H = new HeaderEnums("src/include/clang/AST/DeclCxx.h", [ + static _DECL_CXX_H = new HeaderEnums("../../../include/clang/AST/DeclCxx.h", [ new ClangEnum( "LanguageIDs", "LINKAGE_LANGUAGE", @@ -215,7 +215,7 @@ class ClangEnums { ), ]); - static _LAMBDA_H = new HeaderEnums("src/include/clang/Basic/Lambda.h", [ + static _LAMBDA_H = new HeaderEnums("../../../include/clang/Basic/Lambda.h", [ new ClangEnum( "LambdaCaptureDefault", "LAMBDA_CAPTURE_DEFAULT", @@ -231,11 +231,11 @@ class ClangEnums { ]); static _TEMPLATE_NAME_H = new HeaderEnums( - "src/include/clang/AST/TemplateName.h", + "../../../include/clang/AST/TemplateName.h", [new ClangEnum("NameKind", "TEMPLATE_NAME_KIND", undefined, undefined)] ); - static _ATTR_H = new HeaderEnums("src/include/clang/AST/Attr.h", [ + static _ATTR_H = new HeaderEnums("../../../include/clang/AST/Attr.h", [ new ClangEnum( "VisibilityType", "VISIBILITY_ATTR_TYPE", @@ -244,7 +244,7 @@ class ClangEnums { ), ]); - static _EXPR_H = new HeaderEnums("src/include/clang/AST/Expr.h", [ + static _EXPR_H = new HeaderEnums("../../../include/clang/AST/Expr.h", [ new ClangEnum( "Kind", "OFFSET_OF_NODE_KIND", @@ -302,7 +302,12 @@ Kind, DESIGNATOR_KIND (class Designator) ClangEnums._EXPR_H, ]; - static getHeader = function (headerFilename) { + /** + * + * @param {string} headerFilename + * @returns {HeaderEnums} + */ + static getHeader (headerFilename) { if (ClangEnums._HEADER_MAP === undefined) { ClangEnums._HEADER_MAP = ClangEnums.buildHeaderMap(); } @@ -310,21 +315,30 @@ Kind, DESIGNATOR_KIND (class Designator) return ClangEnums._HEADER_MAP[headerFilename]; }; - static buildHeaderMap = function () { - var map = {}; + /** + * + * @returns {Record} + */ + static buildHeaderMap() { + const map = {}; - for (var header of ClangEnums._HEADERS) { + for (const header of ClangEnums._HEADERS) { map[header.getName()] = header; } - //println("Header map"); - //printlnObject(map); + return map; }; /** * Mappers */ - static _removePrefix = function (enumValue, prefix) { + /** + * + * @param {string} enumValue + * @param {string} prefix + * @returns + */ + static _removePrefix(enumValue, prefix) { if (enumValue.startsWith(prefix)) { enumValue = enumValue.substring(prefix.length); } @@ -332,47 +346,17 @@ Kind, DESIGNATOR_KIND (class Designator) return enumValue; }; - static _removeSuffix = function (enumValue, suffix) { + /** + * + * @param {string} enumValue + * @param {string} suffix + * @returns + */ + static _removeSuffix(enumValue, suffix) { if (enumValue.endsWith(suffix)) { enumValue = enumValue.substring(0, enumValue.length - suffix.length); } return enumValue; }; - - /* -ClangEnums._refQualMapper = function(enumValue) { -//println("MAPPER FOR " + enumValue); - if(enumValue.startsWith("RQ_")) { -// println("Starts with RQ_"); - enumValue = enumValue.substring(3); - } -// println("RETURNING: " + enumValue); - return enumValue; -} -*/ - /* -ClangEnums._elaboratedTypeKeyworkMapper = function(enumValue) { - - if(enumValue.startsWith("ETK_")) { - enumValue = enumValue.substring(4); - } - - enumValue = enumValue.toUpperCase(); - - return enumValue; -} -*/ - /* -ClangEnums._tagKindMapperMapper = function(enumValue) { - - if(enumValue.startsWith("TTK_")) { - enumValue = enumValue.substring(4); - } - - enumValue = enumValue.toUpperCase(); - - return enumValue; -} -*/ } diff --git a/ClangAstDumper/clang_enums/Extractors.js b/ClangAstDumper/clang_enums/Extractors.js index 8ce7daa83..ab6eb6d6d 100644 --- a/ClangAstDumper/clang_enums/Extractors.js +++ b/ClangAstDumper/clang_enums/Extractors.js @@ -1,15 +1,21 @@ class Extractors { + /** + * + * @param {string} enumName + * @param {string[]} lines + * @param {number} occurence + * @returns + */ static simpleExtractor(enumName, lines, occurence) { const regex = "enum\\s+(class\\s+)?" + enumName + "\\s.*{"; const enumNameRegex = new RegExp(regex); - //const enumNameRegex = new RegExp("\\s"+enumName+"\\s"); const enums = []; let searching = true; let completed = false; let currentOccurence = 0; - for (var line of lines) { + for (let line of lines) { if (searching) { // Find enum const matchResult = line.match(enumNameRegex); @@ -30,8 +36,6 @@ class Extractors { const indexOfBracket = line.indexOf("{"); line = line.substring(indexOfBracket + 1); - - //continue; } // Collect enums until } is found @@ -57,15 +61,8 @@ class Extractors { .filter((s) => s.length > 0) // Remove =, } if present .map((s) => Extractors._processEnum(s)); - /* - // Remove , if present - if (line.endsWith(",")) { - line = line.substring(0, line.length - 1); - } -*/ - // Get enum - //println("Enum: " + line) + // Get enum for (const enumName of enumNames) { enums.push(enumName); } @@ -84,6 +81,11 @@ class Extractors { return enums; } + /** + * + * @param {string} enumName + * @returns + */ static _processEnum(enumName) { // Check for = const indexOfEquals = enumName.indexOf("="); diff --git a/ClangAstDumper/clang_enums/HeaderEnums.js b/ClangAstDumper/clang_enums/HeaderEnums.js index 805e01468..b18bc8cdd 100644 --- a/ClangAstDumper/clang_enums/HeaderEnums.js +++ b/ClangAstDumper/clang_enums/HeaderEnums.js @@ -8,17 +8,22 @@ laraImport("weaver.Query"); * @class */ class HeaderEnums { + /** + * + * @param {string} headerFilename + * @param {ClangEnum[]} clangEnums + */ constructor(headerFilename, clangEnums) { this.headerFilename = headerFilename; this.enumMap = {}; this.currentEnumSet = new StringSet(); this.enumsInsideClass = new StringSet(); - for (var clangEnum of clangEnums) { + for (const clangEnum of clangEnums) { this.enumMap[clangEnum.getCompleteEnumName()] = clangEnum; this.currentEnumSet.add(clangEnum.getCompleteEnumName()); - var className = clangEnum.getClassName(); + const className = clangEnum.getClassName(); if (className !== undefined) { this.enumsInsideClass.add(clangEnum.getEnumName()); } @@ -29,6 +34,11 @@ class HeaderEnums { return this.headerFilename; } + /** + * + * @param {ClangEnum} $enum + * @returns + */ _getEnumName($enum) { // Check if enum needs to be prefixed by class if (!this.enumsInsideClass.has($enum.name)) { @@ -36,11 +46,15 @@ class HeaderEnums { } // Get class - var $class = $enum.ancestor("class"); + const $class = $enum.ancestor("class"); - return $class.name + "_" + $enum.name; + return `${$class.name}_${$enum.name}`; } + /** + * + * @param {string} llvmFolder + */ process(llvmFolder) { const compilerCmd = "clang"; const headerFile = Io.getPath(llvmFolder, this.headerFilename); @@ -65,66 +79,28 @@ class HeaderEnums { const headerLines = Strings.asLines(preprocessedFile); - //println("Header: " + headerLines); - for (const enumName in this.enumMap) { const clangEnum = this.enumMap[enumName]; - //println("Enum name: " + enumName); - //printlnObject(clangEnum); // Extract enums - //const enumValues = clangEnum.extractor(enumName, headerLines); - //println("Values: " + enumValues); clangEnum.setEnumValues(headerLines); - /* - var filename = - this.headerFilename.replace(".", "_") + "_" + enumName + ".txt"; - var file = Io.getPath(filename); - println("Saving enum values to file '" + file.getAbsolutePath() + "'"); - Io.writeFile(filename, enumValues.join("\n")); - */ - } - //println("Enums:"); - //printlnObject(this.enumMap); - /* - // Get enum name - var enumName = this._getEnumName($enum); - - // Check if valid enum - //if(!this.currentEnumSet.has($enum.name)) { - if (!this.currentEnumSet.has(enumName)) { - return; } - - //println("Adding enum '"+$enum.name+"'"); - println("Adding enum '" + enumName + "'"); - - // Set enums - var enumValues = $enum.enumerators.map(($enumValue) => $enumValue.name); - //this.enumMap[$enum.name].setEnumValues(enumValues); - this.enumMap[enumName].setEnumValues(enumValues); - - // Save enums, for referece - //var filename = this.headerFilename.replace(".", "_") + "_" + $enum.name + ".txt"; - var filename = - this.headerFilename.replace(".", "_") + "_" + enumName + ".txt"; - var file = Io.getPath(filename); - println("Saving enum values to file '" + file.getAbsolutePath() + "'"); - Io.writeFile(filename, enumValues.join("\n")); - */ } + /** + * + * @param {string} outputFolder + */ generateCode(outputFolder) { const headerFile = Io.getPath(this.headerFilename); - //var filename = "enums_" + this.headerFilename.replace(".", "_") + ".cpp"; - var filename = "enums_" + headerFile.getName().replace(".", "_") + ".cpp"; + const filename = "enums_" + headerFile.getName().replace(".", "_") + ".cpp"; - var code = '#include "ClangEnums.h"\n\n'; + let code = '#include "ClangEnums.h"\n\n'; // Generate code for each of the enums - for (var enumName in this.enumMap) { - var enumCode = this.enumMap[enumName].getCode(); + for (const enumName in this.enumMap) { + const enumCode = this.enumMap[enumName].getCode(); if (enumCode === undefined) { println( @@ -145,17 +121,17 @@ class HeaderEnums { const headerFile = Io.getPath(this.headerFilename); // Dump the names of each enum - for (var enumName in this.enumMap) { - var enumValues = this.enumMap[enumName].getEnumValues(); + for (const enumName in this.enumMap) { + const enumValues = this.enumMap[enumName].getEnumValues(); - var filename = + const filename = "enums_" + headerFile.getName().replace(".", "_") + "_" + enumName + ".txt"; - var code = enumValues.join(",\n") + ";"; + const code = enumValues.join(",\n") + ";"; const outputFile = Io.getPath(outputFolder, filename); println( diff --git a/ClangAstDumper/clang_enums/Main.js b/ClangAstDumper/clang_enums/Main.js index 7cba6978a..b7c184b50 100644 --- a/ClangAstDumper/clang_enums/Main.js +++ b/ClangAstDumper/clang_enums/Main.js @@ -15,110 +15,4 @@ for (const header of ClangEnums._HEADERS) { header.process(llvmFolder); header.generateCode(outputFolder); header.generateJavaEnums(Io.mkdir(outputFolder, "java_enums")); - /* - try { - header.process(llvmFolder); - header.generateCode("C:\\Users\\JBispo\\Work\\Repos\\Lab\\clava\\ClangAstDumper"); - } catch(e) { - println("Skipping header " + header.getName() + ": " + e); - } -*/ } - -/* - const header = ClangEnums._DECL_CXX_H; - header.process(llvmFolder); - header.generateCode("C:\\Users\\JBispo\\Work\\Repos\\Lab\\clava\\ClangAstDumper"); - header.generateJavaEnums("C:\\Users\\JBispo\\Work\\Repos\\Lab\\clava\\ClangAstDumper\\clang_enums_v2\\JavaEnums"); -*/ -/* -const testHeaderEnum = ClangEnums._OPERATIONS_KINDS_H; - -testHeaderEnum.process(llvmFolder) - -testHeaderEnum.generateCode("C:\\Users\\JBispo\\Work\\Repos\\Lab\\clava\\ClangAstDumper"); -*/ -/* -const compilerCmd = "clang" -const baseFolder = Clava.getData().getContextFolder(); - - - -const headerFile = Io.getPath(llvmFolder, "/src/include/clang/AST/OperationKinds.h"); - -//const preprocessorFolder = Io.mkdir(baseFolder, "preprocessorOutput") - -// Preprocess header -const exec = new ProcessExecutor(); -// Clean folder and set working directory -//Io.deleteFolderContents(preprocessorFolder); -//exec.setWorkingDir(preprocessorFolder); -exec.setPrintToConsole(false); -const preprocessedFile = exec.execute(compilerCmd, "-E", headerFile.getAbsolutePath()); -//println(headerFile.getAbsolutePath()) - -println(preprocessedFile) - -const headerLines = Strings.asLines(preprocessedFile); - -// Extract enum from header -const enums = extractEnum("CastKind", headerLines); -println("enums:\n"+enums); -*/ -/* -function extractEnum(enumName, lines) { - const regex = "enum\\s+"+enumName+"\\s+{"; - const enumNameRegex = new RegExp(regex); - //const enumNameRegex = new RegExp("\\s"+enumName+"\\s"); - - const enums = []; - let searching = true; - let completed = false; - - - for(var line of lines) { - if(searching) { - // Find enum - const matchResult = line.match(enumNameRegex) - if(matchResult == null) { - continue; - } - - // Found enum, finish search - searching = false; - continue; - } - - // Collect enums until } is found - line = line.trim(); - - if(line.startsWith("}")){ - // Finished, set flag - completed = true; - break; - } - - // Continue if empty or comment - if(line == "" || line.startsWith("#")) { - continue; - } - - // Remove , if present - if(line.endsWith(",")) { - line = line.substring(0, line.length-1); - } - - // Get enum - - //println("Enum: " + line) - enums.push(line); - - } - - if(!completed) { - throw new Error("Could not find } for enum " + enumName); - } - - return enums; -} -*/ diff --git a/ClangAstDumper/clang_enums/config.clava b/ClangAstDumper/clang_enums/config.clava deleted file mode 100644 index 8ffbc5845..000000000 --- a/ClangAstDumper/clang_enums/config.clava +++ /dev/null @@ -1,236 +0,0 @@ - - LaraI Options - - - workspace - - - - - - library includes - - - - - - main - - - - output - - - - parsingNumThreads - 0 - - - libcCxxMode - AUTO - - - cudaGpuArch - - - - parseIncludes - true - - - javascript - false - - - Disable Remote Dependencies - false - - - joptions_current_folder_path - - - - Generate Modified Code Only - false - - - parallelParsing - true - - - api_autoload - true - - - continueOnParsingErrors - false - - - Weaved code foldername - woven_code - - - external_dependencies - - - - - - Disable Weaving - false - - - metrics - - - false - - - - C/C++ Standard - GNUXX11 - - - workspace_extra - - - - Clava Custom Resources - false - - - restrict mode - false - - - loc - false - - - Disable Code Generation - false - - - log - - - false - - - - autoimportjs - false - - - Clean intermediate files - true - - - systemIncludesThreshold - 1 - - - argv - {"llvmFolder":"C:/Users/JBispo/Work/Repos/Lab/clava/deps/deps-lib/../artifacts/llvm14.0.6-Windows-gcc5"} - - - tools - - - false - - - - jsEngine - GRAALVM_COMPAT - - - flatOutputFolder - false - - - bundle_tags - - - - customClangAstDumperExe - - - - Compiler Flags - - - - Compiler Flags in list format - - - -Wno-narrowing - -Wno-deprecated-register - -Wno-unused-value - - - - - Check C/CXX Syntax - false - - - aspect - Main.js - - - ignoreHeaderIncludes - - - - - - cudaPath - - - - stack trace - true - - - include - - - - - - debug - false - - - Disable Clava Info - false - - - Copy files in sources - false - - - Generate CMake Integration Helper Files - false - - - verbose - warnings - - - header includes - - - - - - report - - - false - - - - false - \ No newline at end of file From 20e221abca64387d5ddea8106a1ce05f3cc08ad6 Mon Sep 17 00:00:00 2001 From: "L. Sousa" Date: Thu, 2 May 2024 00:47:36 +0100 Subject: [PATCH 37/68] Removed Clava as a dependency to build the ClangAstDumper --- ClangAstDumper/clang_enums/.gitignore | 10 - ClangAstDumper/clang_enums/CMakeLists.txt | 26 - ClangAstDumper/clang_enums/ClangEnum.js | 26 +- ClangAstDumper/clang_enums/ClangEnums.js | 568 ++++++++++------------ ClangAstDumper/clang_enums/Extractors.js | 170 ++++--- ClangAstDumper/clang_enums/HeaderEnums.js | 117 ++--- ClangAstDumper/clang_enums/Main.js | 31 +- 7 files changed, 432 insertions(+), 516 deletions(-) delete mode 100644 ClangAstDumper/clang_enums/.gitignore delete mode 100644 ClangAstDumper/clang_enums/CMakeLists.txt mode change 100644 => 100755 ClangAstDumper/clang_enums/Main.js diff --git a/ClangAstDumper/clang_enums/.gitignore b/ClangAstDumper/clang_enums/.gitignore deleted file mode 100644 index 167960718..000000000 --- a/ClangAstDumper/clang_enums/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -.vscode -.cache -CMakeFiles/ -cmake_install.cmake -CMakeCache.txt - -Clava.jar -Clava_system_options.xml -ClavaWeaver_lib/ -EnumGen_clava_weave/ \ No newline at end of file diff --git a/ClangAstDumper/clang_enums/CMakeLists.txt b/ClangAstDumper/clang_enums/CMakeLists.txt deleted file mode 100644 index 26310b80f..000000000 --- a/ClangAstDumper/clang_enums/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -cmake_minimum_required(VERSION 3.2) -project(ClangEnumGenerator) - -set(CLANG_VERSION 15) - -SET(CMAKE_C_COMPILER "clang-${CLANG_VERSION}") -SET(CMAKE_CXX_COMPILER "clang++-${CLANG_VERSION}") - -SET(Clang_DIR "/usr/lib/cmake/clang-${CLANG_VERSION}") -SET(LLVM_DIR "/usr/lib/llvm-${CLANG_VERSION}/lib/cmake/llvm") - -# Add Modules -find_package(LLVM REQUIRED) # LLVM - - -set(COMMON_CXX_FLAGS "-O3 -Wall -Wno-unused-function") - -set(Clava_DIR "../../CMake") -find_package(Clava REQUIRED) - -message(STATUS "LLVM DIR: ${LLVM_DIR}") - -# Create target for clang/AST/Type.h -add_library(EnumGen) - -clava_weave(EnumGen "Main.js" ARGS "llvmFolder:'${LLVM_DIR}', outputFolder:'${CMAKE_CURRENT_LIST_DIR}/..'" JAVA_FLAGS -Xmx8000m) diff --git a/ClangAstDumper/clang_enums/ClangEnum.js b/ClangAstDumper/clang_enums/ClangEnum.js index b5910ff88..1f3649e04 100644 --- a/ClangAstDumper/clang_enums/ClangEnum.js +++ b/ClangAstDumper/clang_enums/ClangEnum.js @@ -1,10 +1,6 @@ -laraImport("weaver.Query"); -laraImport("Extractors"); +import { simpleExtractor } from "./Extractors.js"; -/** - * @class - */ -class ClangEnum { +export default class ClangEnum { /** * * @param {string} name Name of the enum @@ -26,17 +22,17 @@ class ClangEnum { this.name = name; this.cppVarName = cppVarName; this.mapper = mapper; - this.excludeSet = new StringSet(excludeArray); + this.excludeSet = new Set(excludeArray); this.className = className; this.enumValues = undefined; - this.extractor = Extractors.simpleExtractor; + this.extractor = simpleExtractor; this.occurence = 1; } /** - * - * @param {number} occurence - * @returns + * + * @param {number} occurence + * @returns */ setOccurence(occurence) { this.occurence = occurence; @@ -60,8 +56,8 @@ class ClangEnum { } /** - * - * @param {string[]} headerLines + * + * @param {string[]} headerLines */ setEnumValues(headerLines) { this.enumValues = this.extractor(this.name, headerLines, this.occurence); @@ -69,7 +65,7 @@ class ClangEnum { getCode() { if (this.enumValues === undefined) { - println("No enum values set for enum '" + this.name + "'"); + console.log("No enum values set for enum '" + this.name + "'"); return undefined; } @@ -79,7 +75,7 @@ class ClangEnum { for (let enumValue of this.enumValues) { if (this.excludeSet.has(enumValue.toString())) { - println("Excluded enum '" + enumValue + "'"); + console.log("Excluded enum '" + enumValue + "'"); continue; } diff --git a/ClangAstDumper/clang_enums/ClangEnums.js b/ClangAstDumper/clang_enums/ClangEnums.js index 045cd5445..ac91d4dd5 100644 --- a/ClangAstDumper/clang_enums/ClangEnums.js +++ b/ClangAstDumper/clang_enums/ClangEnums.js @@ -1,274 +1,264 @@ -laraImport("HeaderEnums"); -laraImport("ClangEnum"); -laraImport("weaver.Query"); - -/** - * @class - */ -class ClangEnums { - static _TYPE_H = new HeaderEnums("../../../include/clang/AST/Type.h", [ - new ClangEnum("Kind", "BUILTIN_KIND", undefined, ["LastKind"]).setOccurence( - 3 - ), - new ClangEnum( - "RefQualifierKind", - "REFERENCE_QUALIFIER", - (value) => ClangEnums._removePrefix(value, "RQ_"), - undefined - ), +import ClangEnum from "./ClangEnum.js"; +import HeaderEnums from "./HeaderEnums.js"; + +const _TYPE_H = new HeaderEnums("../../../include/clang/AST/Type.h", [ + new ClangEnum("Kind", "BUILTIN_KIND", undefined, ["LastKind"]).setOccurence( + 3 + ), + new ClangEnum( + "RefQualifierKind", + "REFERENCE_QUALIFIER", + (value) => _removePrefix(value, "RQ_"), + undefined + ), + new ClangEnum( + "ArraySizeModifier", + "ARRAY_SIZE_MODIFIER", + undefined, + undefined + ), + new ClangEnum("UTTKind", "UTT_KIND", undefined, undefined), + new ClangEnum( + "ElaboratedTypeKeyword", + "ELABORATED_TYPE_KEYWORD", + (value) => _removePrefix(value, "ETK_"), + undefined + ), + new ClangEnum( + "TagTypeKind", + "TAG_KIND", + (value) => _removePrefix(value, "TTK_"), + undefined + ), +]); + +const _OPERATIONS_KINDS_H = new HeaderEnums( + "../../../include/clang/AST/OperationKinds.h", + [ new ClangEnum( - "ArraySizeModifier", - "ARRAY_SIZE_MODIFIER", - undefined, + "CastKind", + "CAST_KIND", + (value) => _removePrefix(value, "CK_"), undefined ), - new ClangEnum("UTTKind", "UTT_KIND", undefined, undefined), new ClangEnum( - "ElaboratedTypeKeyword", - "ELABORATED_TYPE_KEYWORD", - (value) => ClangEnums._removePrefix(value, "ETK_"), + "BinaryOperatorKind", + "BINARY_OPERATOR_KIND", + (value) => _removePrefix(value, "BO_"), undefined ), new ClangEnum( - "TagTypeKind", - "TAG_KIND", - (value) => ClangEnums._removePrefix(value, "TTK_"), + "UnaryOperatorKind", + "UNARY_OPERATOR_KIND", + (value) => _removePrefix(value, "UO_"), undefined ), - ]); - - static _OPERATIONS_KINDS_H = new HeaderEnums( - "../../../include/clang/AST/OperationKinds.h", - [ - new ClangEnum( - "CastKind", - "CAST_KIND", - (value) => ClangEnums._removePrefix(value, "CK_"), - undefined - ), - new ClangEnum( - "BinaryOperatorKind", - "BINARY_OPERATOR_KIND", - (value) => ClangEnums._removePrefix(value, "BO_"), - undefined - ), - new ClangEnum( - "UnaryOperatorKind", - "UNARY_OPERATOR_KIND", - (value) => ClangEnums._removePrefix(value, "UO_"), - undefined - ), - ] - ); + ] +); - static _ATTR_KINDS_H = new HeaderEnums( - "../../../include/clang/Basic/AttrKinds.h", - [new ClangEnum("Kind", "ATTRIBUTES", undefined, undefined)] - ); +const _ATTR_KINDS_H = new HeaderEnums( + "../../../include/clang/Basic/AttrKinds.h", + [new ClangEnum("Kind", "ATTRIBUTES", undefined, undefined)] +); - static _SPECIFIERS_H = new HeaderEnums( - "../../../include/clang/Basic/Specifiers.h", - [ - new ClangEnum( - "CallingConv", - "CALLING_CONVENTION", - (value) => ClangEnums._removePrefix(value, "CC_"), - undefined - ), - new ClangEnum( - "AccessSpecifier", - "ACCESS_SPECIFIER", - (value) => ClangEnums._removePrefix(value, "AS_").toUpperCase(), - undefined - ), - new ClangEnum( - "StorageClass", - "STORAGE_CLASS", - (value) => ClangEnums._removePrefix(value, "SC_"), - undefined - ), - new ClangEnum( - "ExplicitSpecKind", - "EXPLICIT_SPEC_KIND", - undefined, - undefined - ), - new ClangEnum( - "TemplateSpecializationKind", - "TEMPLATE_SPECIALIZATION_KIND", - (value) => ClangEnums._removePrefix(value, "TSK_"), - undefined - ), - ] - ); - - static _EXCEPTION_SPECIFICATION_TYPE_H = new HeaderEnums( - "../../../include/clang/Basic/ExceptionSpecificationType.h", - [ - new ClangEnum( - "ExceptionSpecificationType", - "EXCEPTION_SPECIFICATION_TYPE", - (value) => ClangEnums._removePrefix(value, "EST_"), - undefined - ), - ] - ); - - static _LINKAGE_H = new HeaderEnums("../../../include/clang/Basic/Linkage.h", [ +const _SPECIFIERS_H = new HeaderEnums( + "../../../include/clang/Basic/Specifiers.h", + [ new ClangEnum( - "Linkage", - "LINKAGE", - (value) => ClangEnums._removePrefix(value, "EST_"), + "CallingConv", + "CALLING_CONVENTION", + (value) => _removePrefix(value, "CC_"), undefined ), - ]); - - static _VISIBILITY_H = new HeaderEnums( - "../../../include/clang/Basic/Visibility.h", - [ - new ClangEnum( - "Visibility", - "VISIBILITY", - (value) => ClangEnums._removeSuffix(value, "Visibility"), - undefined - ), - ] - ); - - static _TEMPLATE_BASE_H = new HeaderEnums( - "../../../include/clang/AST/TemplateBase.h", - [new ClangEnum("ArgKind", "TEMPLATE_ARG_KIND", undefined, undefined)] - ); - - static _DECL_H = new HeaderEnums("../../../include/clang/AST/Decl.h", [ new ClangEnum( - "InitializationStyle", - "INIT_STYLE", - (value) => ClangEnums._INIT_STYLE_ENUMS[value], + "AccessSpecifier", + "ACCESS_SPECIFIER", + (value) => _removePrefix(value, "AS_").toUpperCase(), undefined ), new ClangEnum( - "TLSKind", - "TLS_KIND", - (value) => ClangEnums._removePrefix(value, "TLS_").toUpperCase(), + "StorageClass", + "STORAGE_CLASS", + (value) => _removePrefix(value, "SC_"), undefined ), - ]); - - static _INIT_STYLE_ENUMS = { - CInit: "CINIT", - CallInit: "CALL_INIT", - ListInit: "LIST_INIT", - }; - - static _EXPR_CXX_H = new HeaderEnums("../../../include/clang/AST/ExprCXX.h", [ - new ClangEnum( - "InitializationStyle", - "NEW_INIT_STYLE", - (value) => ClangEnums._NEW_INIT_STYLE_ENUMS[value], - undefined - ).setOccurence(2), new ClangEnum( - "ConstructionKind", - "CONSTRUCTION_KIND", - (value) => ClangEnums._removePrefix(value, "CK_"), + "ExplicitSpecKind", + "EXPLICIT_SPEC_KIND", + undefined, undefined ), - ]); - - static _NEW_INIT_STYLE_ENUMS = { - NoInit: "NO_INIT", - CallInit: "CALL_INIT", - ListInit: "LIST_INIT", - }; - - static _TYPE_TRAITS_H = new HeaderEnums( - "../../../include/clang/Basic/TypeTraits.h", - [ - new ClangEnum( - "UnaryExprOrTypeTrait", - "UETT_KIND", - (value) => ClangEnums._removePrefix(value, "UETT_"), - ["UETT_Last"] - ), - ] - ); - - static _NESTED_NAME_SPECIFIER_H = new HeaderEnums( - "../../../include/clang/AST/NestedNameSpecifier.h", - [ - new ClangEnum( - "SpecifierKind", - "NESTED_NAMED_SPECIFIER", - undefined, - undefined - ), - ] - ); - - static _DECL_CXX_H = new HeaderEnums("../../../include/clang/AST/DeclCxx.h", [ new ClangEnum( - "LanguageIDs", - "LINKAGE_LANGUAGE", - (value) => ClangEnums._removePrefix(value, "lang_").toUpperCase(), + "TemplateSpecializationKind", + "TEMPLATE_SPECIALIZATION_KIND", + (value) => _removePrefix(value, "TSK_"), undefined ), - ]); + ] +); - static _LAMBDA_H = new HeaderEnums("../../../include/clang/Basic/Lambda.h", [ +const _EXCEPTION_SPECIFICATION_TYPE_H = new HeaderEnums( + "../../../include/clang/Basic/ExceptionSpecificationType.h", + [ new ClangEnum( - "LambdaCaptureDefault", - "LAMBDA_CAPTURE_DEFAULT", - (value) => ClangEnums._removePrefix(value, "LCD_"), + "ExceptionSpecificationType", + "EXCEPTION_SPECIFICATION_TYPE", + (value) => _removePrefix(value, "EST_"), undefined ), + ] +); + +const _LINKAGE_H = new HeaderEnums("../../../include/clang/Basic/Linkage.h", [ + new ClangEnum( + "Linkage", + "LINKAGE", + (value) => _removePrefix(value, "EST_"), + undefined + ), +]); + +const _VISIBILITY_H = new HeaderEnums( + "../../../include/clang/Basic/Visibility.h", + [ new ClangEnum( - "LambdaCaptureKind", - "LAMBDA_CAPTURE_KIND", - (value) => ClangEnums._removePrefix(value, "LCK_"), + "Visibility", + "VISIBILITY", + (value) => _removeSuffix(value, "Visibility"), undefined ), - ]); - - static _TEMPLATE_NAME_H = new HeaderEnums( - "../../../include/clang/AST/TemplateName.h", - [new ClangEnum("NameKind", "TEMPLATE_NAME_KIND", undefined, undefined)] - ); - - static _ATTR_H = new HeaderEnums("../../../include/clang/AST/Attr.h", [ + ] +); + +const _TEMPLATE_BASE_H = new HeaderEnums( + "../../../include/clang/AST/TemplateBase.h", + [new ClangEnum("ArgKind", "TEMPLATE_ARG_KIND", undefined, undefined)] +); + +const _DECL_H = new HeaderEnums("../../../include/clang/AST/Decl.h", [ + new ClangEnum( + "InitializationStyle", + "INIT_STYLE", + (value) => _INIT_STYLE_ENUMS[value], + undefined + ), + new ClangEnum( + "TLSKind", + "TLS_KIND", + (value) => _removePrefix(value, "TLS_").toUpperCase(), + undefined + ), +]); + +const _INIT_STYLE_ENUMS = { + CInit: "CINIT", + CallInit: "CALL_INIT", + ListInit: "LIST_INIT", +}; + +const _EXPR_CXX_H = new HeaderEnums("../../../include/clang/AST/ExprCXX.h", [ + new ClangEnum( + "InitializationStyle", + "NEW_INIT_STYLE", + (value) => _NEW_INIT_STYLE_ENUMS[value], + undefined + ).setOccurence(2), + new ClangEnum( + "ConstructionKind", + "CONSTRUCTION_KIND", + (value) => _removePrefix(value, "CK_"), + undefined + ), +]); + +const _NEW_INIT_STYLE_ENUMS = { + NoInit: "NO_INIT", + CallInit: "CALL_INIT", + ListInit: "LIST_INIT", +}; + +const _TYPE_TRAITS_H = new HeaderEnums( + "../../../include/clang/Basic/TypeTraits.h", + [ new ClangEnum( - "VisibilityType", - "VISIBILITY_ATTR_TYPE", - undefined, - undefined + "UnaryExprOrTypeTrait", + "UETT_KIND", + (value) => _removePrefix(value, "UETT_"), + ["UETT_Last"] ), - ]); + ] +); - static _EXPR_H = new HeaderEnums("../../../include/clang/AST/Expr.h", [ - new ClangEnum( - "Kind", - "OFFSET_OF_NODE_KIND", - (value) => value.toUpperCase(), - undefined, - "OffsetOfNode" - ).setOccurence(10), +const _NESTED_NAME_SPECIFIER_H = new HeaderEnums( + "../../../include/clang/AST/NestedNameSpecifier.h", + [ new ClangEnum( - "IdentKind", - "PREDEFINED_ID_TYPE", + "SpecifierKind", + "NESTED_NAMED_SPECIFIER", undefined, - undefined, - "PredefinedExpr" - ), - new ClangEnum( - "StringKind", - "STRING_KIND", - (value) => value.toUpperCase(), undefined ), - //new ClangEnum('Kind', 'DESIGNATOR_KIND', undefined, undefined, 'Designator') - ]); + ] +); + +const _DECL_CXX_H = new HeaderEnums("../../../include/clang/AST/DeclCxx.h", [ + new ClangEnum( + "LanguageIDs", + "LINKAGE_LANGUAGE", + (value) => _removePrefix(value, "lang_").toUpperCase(), + undefined + ), +]); + +const _LAMBDA_H = new HeaderEnums("../../../include/clang/Basic/Lambda.h", [ + new ClangEnum( + "LambdaCaptureDefault", + "LAMBDA_CAPTURE_DEFAULT", + (value) => _removePrefix(value, "LCD_"), + undefined + ), + new ClangEnum( + "LambdaCaptureKind", + "LAMBDA_CAPTURE_KIND", + (value) => _removePrefix(value, "LCK_"), + undefined + ), +]); + +const _TEMPLATE_NAME_H = new HeaderEnums( + "../../../include/clang/AST/TemplateName.h", + [new ClangEnum("NameKind", "TEMPLATE_NAME_KIND", undefined, undefined)] +); + +const _ATTR_H = new HeaderEnums("../../../include/clang/AST/Attr.h", [ + new ClangEnum("VisibilityType", "VISIBILITY_ATTR_TYPE", undefined, undefined), +]); + +const _EXPR_H = new HeaderEnums("../../../include/clang/AST/Expr.h", [ + new ClangEnum( + "Kind", + "OFFSET_OF_NODE_KIND", + (value) => value.toUpperCase(), + undefined, + "OffsetOfNode" + ).setOccurence(10), + new ClangEnum( + "IdentKind", + "PREDEFINED_ID_TYPE", + undefined, + undefined, + "PredefinedExpr" + ), + new ClangEnum( + "StringKind", + "STRING_KIND", + (value) => value.toUpperCase(), + undefined + ), + //new ClangEnum('Kind', 'DESIGNATOR_KIND', undefined, undefined, 'Designator') +]); - /** +/** @@ -282,81 +272,53 @@ Kind, DESIGNATOR_KIND (class Designator) */ - static _HEADERS = [ - ClangEnums._TYPE_H, - ClangEnums._OPERATIONS_KINDS_H, - ClangEnums._ATTR_KINDS_H, - ClangEnums._SPECIFIERS_H, - ClangEnums._EXCEPTION_SPECIFICATION_TYPE_H, - ClangEnums._LINKAGE_H, - ClangEnums._VISIBILITY_H, - ClangEnums._TEMPLATE_BASE_H, - ClangEnums._DECL_H, - ClangEnums._EXPR_CXX_H, - ClangEnums._TYPE_TRAITS_H, - ClangEnums._NESTED_NAME_SPECIFIER_H, - ClangEnums._DECL_CXX_H, - ClangEnums._LAMBDA_H, - ClangEnums._TEMPLATE_NAME_H, - ClangEnums._ATTR_H, - ClangEnums._EXPR_H, - ]; - - /** - * - * @param {string} headerFilename - * @returns {HeaderEnums} - */ - static getHeader (headerFilename) { - if (ClangEnums._HEADER_MAP === undefined) { - ClangEnums._HEADER_MAP = ClangEnums.buildHeaderMap(); - } +export const Headers = [ + _TYPE_H, + _OPERATIONS_KINDS_H, + _ATTR_KINDS_H, + _SPECIFIERS_H, + _EXCEPTION_SPECIFICATION_TYPE_H, + _LINKAGE_H, + _VISIBILITY_H, + _TEMPLATE_BASE_H, + _DECL_H, + _EXPR_CXX_H, + _TYPE_TRAITS_H, + _NESTED_NAME_SPECIFIER_H, + _DECL_CXX_H, + _LAMBDA_H, + _TEMPLATE_NAME_H, + _ATTR_H, + _EXPR_H, +]; - return ClangEnums._HEADER_MAP[headerFilename]; - }; - - /** - * - * @returns {Record} - */ - static buildHeaderMap() { - const map = {}; - - for (const header of ClangEnums._HEADERS) { - map[header.getName()] = header; - } - - return map; - }; - - /** - * Mappers - */ - /** - * - * @param {string} enumValue - * @param {string} prefix - * @returns - */ - static _removePrefix(enumValue, prefix) { - if (enumValue.startsWith(prefix)) { - enumValue = enumValue.substring(prefix.length); - } +/** + * Mappers + */ +/** + * + * @param {string} enumValue + * @param {string} prefix + * @returns + */ +function _removePrefix(enumValue, prefix) { + if (enumValue.startsWith(prefix)) { + enumValue = enumValue.substring(prefix.length); + } - return enumValue; - }; + return enumValue; +} - /** - * - * @param {string} enumValue - * @param {string} suffix - * @returns - */ - static _removeSuffix(enumValue, suffix) { - if (enumValue.endsWith(suffix)) { - enumValue = enumValue.substring(0, enumValue.length - suffix.length); - } +/** + * + * @param {string} enumValue + * @param {string} suffix + * @returns + */ +function _removeSuffix(enumValue, suffix) { + if (enumValue.endsWith(suffix)) { + enumValue = enumValue.substring(0, enumValue.length - suffix.length); + } - return enumValue; - }; + return enumValue; } diff --git a/ClangAstDumper/clang_enums/Extractors.js b/ClangAstDumper/clang_enums/Extractors.js index ab6eb6d6d..8897a4fd6 100644 --- a/ClangAstDumper/clang_enums/Extractors.js +++ b/ClangAstDumper/clang_enums/Extractors.js @@ -1,104 +1,102 @@ -class Extractors { - /** - * - * @param {string} enumName - * @param {string[]} lines - * @param {number} occurence - * @returns - */ - static simpleExtractor(enumName, lines, occurence) { - const regex = "enum\\s+(class\\s+)?" + enumName + "\\s.*{"; - const enumNameRegex = new RegExp(regex); - - const enums = []; - let searching = true; - let completed = false; - let currentOccurence = 0; - - for (let line of lines) { - if (searching) { - // Find enum - const matchResult = line.match(enumNameRegex); - if (matchResult == null) { - continue; - } - - // Found enum, increment occurence - currentOccurence++; - - // If not correct occurent, continue - if (currentOccurence !== occurence) { - continue; - } - - // Found occurence, finish search and fallthrough, updating line - searching = false; - - const indexOfBracket = line.indexOf("{"); - line = line.substring(indexOfBracket + 1); +/** + * + * @param {string} enumName + * @param {string[]} lines + * @param {number} occurence + * @returns + */ +export function simpleExtractor(enumName, lines, occurence) { + const regex = "enum\\s+(class\\s+)?" + enumName + "\\s.*{"; + const enumNameRegex = new RegExp(regex); + + const enums = []; + let searching = true; + let completed = false; + let currentOccurence = 0; + + for (let line of lines) { + if (searching) { + // Find enum + const matchResult = line.match(enumNameRegex); + if (matchResult == null) { + continue; } - // Collect enums until } is found - line = line.trim(); - - if (line.startsWith("}")) { - // Finished, set flag - completed = true; - break; - } + // Found enum, increment occurence + currentOccurence++; - // Continue if empty or comment - if (line == "" || line.startsWith("#") || line.startsWith("+")) { + // If not correct occurent, continue + if (currentOccurence !== occurence) { continue; } - // Split by , - const enumNames = line - .split(",") - // Trim string - .map((s) => s.trim()) - // Remove empty strings - .filter((s) => s.length > 0) - // Remove =, } if present - .map((s) => Extractors._processEnum(s)); - - // Get enum - for (const enumName of enumNames) { - enums.push(enumName); - } + // Found occurence, finish search and fallthrough, updating line + searching = false; - if (line.includes("}")) { - // Finished, set flag - completed = true; - break; - } + const indexOfBracket = line.indexOf("{"); + line = line.substring(indexOfBracket + 1); } - if (!completed) { - throw new Error("Could not find } for enum " + enumName); + // Collect enums until } is found + line = line.trim(); + + if (line.startsWith("}")) { + // Finished, set flag + completed = true; + break; } - return enums; - } + // Continue if empty or comment + if (line == "" || line.startsWith("#") || line.startsWith("+")) { + continue; + } - /** - * - * @param {string} enumName - * @returns - */ - static _processEnum(enumName) { - // Check for = - const indexOfEquals = enumName.indexOf("="); - if (indexOfEquals !== -1) { - enumName = enumName.substring(0, indexOfEquals).trim(); + // Split by , + const enumNames = line + .split(",") + // Trim string + .map((s) => s.trim()) + // Remove empty strings + .filter((s) => s.length > 0) + // Remove =, } if present + .map((s) => processEnum(s)); + + // Get enum + for (const enumName of enumNames) { + enums.push(enumName); } - // Check for } - const indexOfBraket = enumName.indexOf("}"); - if (indexOfBraket !== -1) { - enumName = enumName.substring(0, indexOfBraket).trim(); + if (line.includes("}")) { + // Finished, set flag + completed = true; + break; } + } + + if (!completed) { + throw new Error("Could not find } for enum " + enumName); + } + + return enums; +} + +/** + * + * @param {string} enumName + * @returns + */ +function processEnum(enumName) { + // Check for = + const indexOfEquals = enumName.indexOf("="); + if (indexOfEquals !== -1) { + enumName = enumName.substring(0, indexOfEquals).trim(); + } - return enumName; + // Check for } + const indexOfBraket = enumName.indexOf("}"); + if (indexOfBraket !== -1) { + enumName = enumName.substring(0, indexOfBraket).trim(); } + + return enumName; } diff --git a/ClangAstDumper/clang_enums/HeaderEnums.js b/ClangAstDumper/clang_enums/HeaderEnums.js index b18bc8cdd..cc3bb5d9f 100644 --- a/ClangAstDumper/clang_enums/HeaderEnums.js +++ b/ClangAstDumper/clang_enums/HeaderEnums.js @@ -1,23 +1,21 @@ -laraImport("lara.util.StringSet"); -laraImport("lara.Io"); -laraImport("lara.Strings"); -laraImport("lara.util.ProcessExecutor"); -laraImport("weaver.Query"); +import fs from "fs"; +import path from "path"; +import { spawnSync } from "child_process"; /** * @class */ -class HeaderEnums { +export default class HeaderEnums { /** - * - * @param {string} headerFilename - * @param {ClangEnum[]} clangEnums + * + * @param {string} headerFilename + * @param {ClangEnum[]} clangEnums */ constructor(headerFilename, clangEnums) { this.headerFilename = headerFilename; this.enumMap = {}; - this.currentEnumSet = new StringSet(); - this.enumsInsideClass = new StringSet(); + this.currentEnumSet = new Set(); + this.enumsInsideClass = new Set(); for (const clangEnum of clangEnums) { this.enumMap[clangEnum.getCompleteEnumName()] = clangEnum; @@ -35,49 +33,44 @@ class HeaderEnums { } /** - * - * @param {ClangEnum} $enum - * @returns + * + * @param {string} llvmFolder */ - _getEnumName($enum) { - // Check if enum needs to be prefixed by class - if (!this.enumsInsideClass.has($enum.name)) { - return $enum.name; - } - - // Get class - const $class = $enum.ancestor("class"); - - return `${$class.name}_${$enum.name}`; - } + process(compilerCmd, llvmFolder) { + const headerFile = path.join(llvmFolder, this.headerFilename); - /** - * - * @param {string} llvmFolder - */ - process(llvmFolder) { - const compilerCmd = "clang"; - const headerFile = Io.getPath(llvmFolder, this.headerFilename); - - // Preprocess header - const exec = new ProcessExecutor(); // Clean folder and set working directory - - exec.setPrintToConsole(false); - const preprocessedFile = exec.execute( + const result = spawnSync( compilerCmd, - "-E", - headerFile.getAbsolutePath() + [ + "-E", + path.resolve(headerFile), + "-isystem", + path.join(llvmFolder, "../../../include"), + ], + { + stdio: ["ignore", "pipe", "ignore"], + maxBuffer: 1024 * 1024 * 1024, + } ); - debug( - "Processed header '" + - headerFile.getAbsolutePath() + - "':\n" + - preprocessedFile - ); + if (result.error) { + throw new Error( + "Could not process header '" + + path.resolve(headerFile) + + "': " + + result.error + ); + } + + const { stdout } = result; + + // Get stdout from spawn without writing to the console + let preprocessedFile = String(stdout); + + console.debug("Processed header '" + path.resolve(headerFile) + "':"); - const headerLines = Strings.asLines(preprocessedFile); + const headerLines = preprocessedFile.split("\n"); for (const enumName in this.enumMap) { const clangEnum = this.enumMap[enumName]; @@ -88,13 +81,13 @@ class HeaderEnums { } /** - * - * @param {string} outputFolder + * + * @param {string} outputFolder */ generateCode(outputFolder) { - const headerFile = Io.getPath(this.headerFilename); + const headerFile = path.basename(this.headerFilename); - const filename = "enums_" + headerFile.getName().replace(".", "_") + ".cpp"; + const filename = "enums_" + headerFile.replace(".", "_") + ".cpp"; let code = '#include "ClangEnums.h"\n\n'; @@ -103,7 +96,7 @@ class HeaderEnums { const enumCode = this.enumMap[enumName].getCode(); if (enumCode === undefined) { - println( + console.log( "Skipped code generation for " + this.headerFilename + "::" + enumName ); continue; @@ -112,13 +105,13 @@ class HeaderEnums { code += enumCode + "\n"; } - const outputFile = Io.getPath(outputFolder, filename); - println("Generating header file '" + outputFile.getAbsolutePath() + "'"); - Io.writeFile(Io.getPath(outputFolder, filename), code); + const outputFile = path.join(outputFolder, filename); + console.log("Generating header file '" + path.resolve(outputFile) + "'"); + fs.writeFileSync(path.join(outputFolder, filename), code); } generateJavaEnums(outputFolder) { - const headerFile = Io.getPath(this.headerFilename); + const headerFile = path.basename(this.headerFilename); // Dump the names of each enum for (const enumName in this.enumMap) { @@ -126,20 +119,18 @@ class HeaderEnums { const filename = "enums_" + - headerFile.getName().replace(".", "_") + + headerFile.replace(".", "_") + "_" + enumName + ".txt"; const code = enumValues.join(",\n") + ";"; - const outputFile = Io.getPath(outputFolder, filename); - println( - "Generating Java enum values file '" + - outputFile.getAbsolutePath() + - "'" + const outputFile = path.join(outputFolder, filename); + console.log( + "Generating Java enum values file '" + path.resolve(outputFile) + "'" ); - Io.writeFile(Io.getPath(outputFolder, filename), code); + fs.writeFileSync(path.join(outputFolder, filename), code); } } } diff --git a/ClangAstDumper/clang_enums/Main.js b/ClangAstDumper/clang_enums/Main.js old mode 100644 new mode 100755 index b7c184b50..bc16231f7 --- a/ClangAstDumper/clang_enums/Main.js +++ b/ClangAstDumper/clang_enums/Main.js @@ -1,18 +1,23 @@ -laraImport("clava.Clava"); -laraImport("lara.Io"); -laraImport("lara.Strings"); -laraImport("lara.util.ProcessExecutor"); -laraImport("ClangEnums"); -laraImport("HeaderEnums"); +#!/usr/bin/env node +import fs from "fs"; +import path from "path"; +import { Headers } from "./ClangEnums.js"; -const llvmFolder = laraArgs.llvmFolder; -const outputFolder = laraArgs.outputFolder; +// Get the command line arguments +const llvmVersion = process.argv[2]; +const outputFolder = process.argv[3]; -println("Using LLVM folder '" + llvmFolder + "'"); -println("Generating enums to folder '" + outputFolder + "'"); +const compilerCmd = `clang++-${llvmVersion}`; +const llvmFolder = `/usr/lib/llvm-${llvmVersion}/lib/cmake/llvm`; +const javaEnumsOutputFolder = path.join(outputFolder, "java_enums"); -for (const header of ClangEnums._HEADERS) { - header.process(llvmFolder); +console.log("Using LLVM folder '" + llvmFolder + "'"); +console.log("Generating enums to folder '" + outputFolder + "'"); + +fs.mkdirSync(javaEnumsOutputFolder, {recursive: true}); + +for (const header of Headers) { + header.process(compilerCmd, llvmFolder); header.generateCode(outputFolder); - header.generateJavaEnums(Io.mkdir(outputFolder, "java_enums")); + header.generateJavaEnums(javaEnumsOutputFolder); } From 7e197f79261e0b6673c8c9d725752af7d4383558 Mon Sep 17 00:00:00 2001 From: "L. Sousa" Date: Thu, 2 May 2024 11:09:06 +0100 Subject: [PATCH 38/68] Pipe through clang's stderr in case of error --- ClangAstDumper/clang_enums/HeaderEnums.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ClangAstDumper/clang_enums/HeaderEnums.js b/ClangAstDumper/clang_enums/HeaderEnums.js index cc3bb5d9f..b80ed2261 100644 --- a/ClangAstDumper/clang_enums/HeaderEnums.js +++ b/ClangAstDumper/clang_enums/HeaderEnums.js @@ -49,17 +49,17 @@ export default class HeaderEnums { path.join(llvmFolder, "../../../include"), ], { - stdio: ["ignore", "pipe", "ignore"], + stdio: ["ignore", "pipe", "pipe"], maxBuffer: 1024 * 1024 * 1024, } ); - if (result.error) { + if (result.status !== 0) { throw new Error( "Could not process header '" + path.resolve(headerFile) + - "': " + - result.error + "':\n\t" + + String(result.stderr).split("\n").join("\n\t") ); } From d312d830487b1b94d2dcee70868ce23f6ab8011c Mon Sep 17 00:00:00 2001 From: "L. Sousa" Date: Thu, 2 May 2024 11:12:13 +0100 Subject: [PATCH 39/68] Added compatibility with clang-15 Updated filename Updated the generated files (shouldn't these be in gitignore?) --- ClangAstDumper/.gitignore | 2 ++ ClangAstDumper/CMakeLists.txt | 2 +- ClangAstDumper/clang_enums/ClangEnums.js | 2 +- ClangAstDumper/src/{enums_DeclCxx_h.cpp => enums_DeclCXX_h.cpp} | 0 ClangAstDumper/src/enums_Expr_h.cpp | 2 +- ClangAstDumper/src/enums_Specifiers_h.cpp | 2 ++ ClangAstDumper/src/enums_TemplateName_h.cpp | 1 + 7 files changed, 8 insertions(+), 3 deletions(-) rename ClangAstDumper/src/{enums_DeclCxx_h.cpp => enums_DeclCXX_h.cpp} (100%) diff --git a/ClangAstDumper/.gitignore b/ClangAstDumper/.gitignore index 470f97119..247a090e8 100644 --- a/ClangAstDumper/.gitignore +++ b/ClangAstDumper/.gitignore @@ -10,3 +10,5 @@ testSources *.gch *.o *.a + +java_enums/ \ No newline at end of file diff --git a/ClangAstDumper/CMakeLists.txt b/ClangAstDumper/CMakeLists.txt index d9f77e0c2..cd2df2436 100644 --- a/ClangAstDumper/CMakeLists.txt +++ b/ClangAstDumper/CMakeLists.txt @@ -55,7 +55,7 @@ set(SOURCE_FILES src/enums_ExprCXX_h.cpp src/enums_TypeTraits_h.cpp src/enums_NestedNameSpecifier_h.cpp - src/enums_DeclCxx_h.cpp + src/enums_DeclCXX_h.cpp src/enums_Lambda_h.cpp src/enums_TemplateName_h.cpp src/enums_Attr_h.cpp diff --git a/ClangAstDumper/clang_enums/ClangEnums.js b/ClangAstDumper/clang_enums/ClangEnums.js index ac91d4dd5..368e23a99 100644 --- a/ClangAstDumper/clang_enums/ClangEnums.js +++ b/ClangAstDumper/clang_enums/ClangEnums.js @@ -201,7 +201,7 @@ const _NESTED_NAME_SPECIFIER_H = new HeaderEnums( ] ); -const _DECL_CXX_H = new HeaderEnums("../../../include/clang/AST/DeclCxx.h", [ +const _DECL_CXX_H = new HeaderEnums("../../../include/clang/AST/DeclCXX.h", [ new ClangEnum( "LanguageIDs", "LINKAGE_LANGUAGE", diff --git a/ClangAstDumper/src/enums_DeclCxx_h.cpp b/ClangAstDumper/src/enums_DeclCXX_h.cpp similarity index 100% rename from ClangAstDumper/src/enums_DeclCxx_h.cpp rename to ClangAstDumper/src/enums_DeclCXX_h.cpp diff --git a/ClangAstDumper/src/enums_Expr_h.cpp b/ClangAstDumper/src/enums_Expr_h.cpp index bccbf71a5..3ec6a7480 100644 --- a/ClangAstDumper/src/enums_Expr_h.cpp +++ b/ClangAstDumper/src/enums_Expr_h.cpp @@ -19,7 +19,7 @@ extern const std::string clava::PREDEFINED_ID_TYPE[] = { }; extern const std::string clava::STRING_KIND[] = { - "ASCII", + "ORDINARY", "WIDE", "UTF8", "UTF16", diff --git a/ClangAstDumper/src/enums_Specifiers_h.cpp b/ClangAstDumper/src/enums_Specifiers_h.cpp index 9fa228124..4c5003a27 100644 --- a/ClangAstDumper/src/enums_Specifiers_h.cpp +++ b/ClangAstDumper/src/enums_Specifiers_h.cpp @@ -20,6 +20,8 @@ extern const std::string clava::CALLING_CONVENTION[] = { "PreserveMost", "PreserveAll", "AArch64VectorCall", + "AArch64SVEPCS", + "AMDGPUKernelCall", }; extern const std::string clava::ACCESS_SPECIFIER[] = { diff --git a/ClangAstDumper/src/enums_TemplateName_h.cpp b/ClangAstDumper/src/enums_TemplateName_h.cpp index 2378f794b..d184dd6fb 100644 --- a/ClangAstDumper/src/enums_TemplateName_h.cpp +++ b/ClangAstDumper/src/enums_TemplateName_h.cpp @@ -8,5 +8,6 @@ extern const std::string clava::TEMPLATE_NAME_KIND[] = { "DependentTemplate", "SubstTemplateTemplateParm", "SubstTemplateTemplateParmPack", + "UsingTemplate", }; From 085512167cfa3eaee478494524567386a8dabe4a Mon Sep 17 00:00:00 2001 From: "L. Sousa" Date: Thu, 2 May 2024 13:57:15 +0100 Subject: [PATCH 40/68] Refactor the project structure --- ClangAstDumper/.gitignore | 1 + ClangAstDumper/CMakeLists.txt | 82 ++-- ClangAstDumper/clang_enums/Main.js | 6 +- .../ChildrenVisitorAttrs.cpp | 6 +- .../ChildrenVisitorDecls.cpp | 8 +- .../ChildrenVisitorExtras.cpp | 8 +- .../ChildrenVisitorStmts.cpp | 8 +- .../ChildrenVisitorTypes.cpp | 6 +- ClangAstDumper/src/{ => Clang}/ClangAst.cpp | 2 +- ClangAstDumper/src/{ => Clang}/ClangAst.h | 2 +- ClangAstDumper/src/{ => Clang}/ClangNodes.cpp | 2 +- ClangAstDumper/src/{ => Clang}/ClangNodes.h | 0 .../{ => ClangAstDumper}/ClangAstDumper.cpp | 4 +- .../src/{ => ClangAstDumper}/ClangAstDumper.h | 2 +- .../ClangAstDumperAttr.cpp | 2 +- .../ClangAstDumperConstants.h | 0 .../ClangAstDumperDecls.cpp | 2 +- .../ClangAstDumperExprs.cpp | 2 +- .../ClangAstDumperExtra.cpp | 0 .../ClangAstDumperStmts.cpp | 2 +- .../ClangAstDumperTypes.cpp | 2 +- .../src/{ => ClangEnums}/ClangEnums.cpp | 0 .../src/{ => ClangEnums}/ClangEnums.h | 0 .../src/{ => Clava}/ClavaConstants.cpp | 0 .../src/{ => Clava}/ClavaConstants.h | 0 ClangAstDumper/src/{ => Clava}/ClavaDecl.cpp | 0 ClangAstDumper/src/{ => Clava}/ClavaDecl.h | 0 .../{ => ClavaDataDumper}/ClavaDataDumper.cpp | 4 +- .../{ => ClavaDataDumper}/ClavaDataDumper.h | 4 +- .../ClavaDataDumperAttrs.cpp | 8 +- .../ClavaDataDumperDecls.cpp | 7 +- .../ClavaDataDumperStmts.cpp | 6 +- .../ClavaDataDumperTypes.cpp | 6 +- .../src/{ => TypeMarker}/TypeMarker.cpp | 0 .../src/{ => TypeMarker}/TypeMarker.h | 5 +- ClangAstDumper/src/enums_AttrKinds_h.cpp | 379 ------------------ ClangAstDumper/src/enums_Attr_h.cpp | 8 - ClangAstDumper/src/enums_DeclCXX_h.cpp | 7 - ClangAstDumper/src/enums_Decl_h.cpp | 14 - .../enums_ExceptionSpecificationType_h.cpp | 17 - ClangAstDumper/src/enums_ExprCXX_h.cpp | 15 - ClangAstDumper/src/enums_Expr_h.cpp | 28 -- ClangAstDumper/src/enums_Lambda_h.cpp | 16 - ClangAstDumper/src/enums_Linkage_h.cpp | 12 - .../src/enums_NestedNameSpecifier_h.cpp | 12 - ClangAstDumper/src/enums_OperationKinds_h.cpp | 123 ------ ClangAstDumper/src/enums_Specifiers_h.cpp | 56 --- ClangAstDumper/src/enums_TemplateBase_h.cpp | 14 - ClangAstDumper/src/enums_TemplateName_h.cpp | 13 - ClangAstDumper/src/enums_TypeTraits_h.cpp | 10 - ClangAstDumper/src/enums_Type_h.cpp | 277 ------------- ClangAstDumper/src/enums_Visibility_h.cpp | 8 - .../src/{newmain.cpp => plugin.cpp} | 7 +- .../src/{main.cpp => standalone.cpp} | 0 54 files changed, 97 insertions(+), 1106 deletions(-) rename ClangAstDumper/src/{ => ChildrenVisitor}/ChildrenVisitorAttrs.cpp (93%) rename ClangAstDumper/src/{ => ChildrenVisitor}/ChildrenVisitorDecls.cpp (99%) rename ClangAstDumper/src/{ => ChildrenVisitor}/ChildrenVisitorExtras.cpp (95%) rename ClangAstDumper/src/{ => ChildrenVisitor}/ChildrenVisitorStmts.cpp (99%) rename ClangAstDumper/src/{ => ChildrenVisitor}/ChildrenVisitorTypes.cpp (99%) rename ClangAstDumper/src/{ => Clang}/ClangAst.cpp (99%) rename ClangAstDumper/src/{ => Clang}/ClangAst.h (99%) rename ClangAstDumper/src/{ => Clang}/ClangNodes.cpp (99%) rename ClangAstDumper/src/{ => Clang}/ClangNodes.h (100%) rename ClangAstDumper/src/{ => ClangAstDumper}/ClangAstDumper.cpp (99%) rename ClangAstDumper/src/{ => ClangAstDumper}/ClangAstDumper.h (99%) rename ClangAstDumper/src/{ => ClangAstDumper}/ClangAstDumperAttr.cpp (97%) rename ClangAstDumper/src/{ => ClangAstDumper}/ClangAstDumperConstants.h (100%) rename ClangAstDumper/src/{ => ClangAstDumper}/ClangAstDumperDecls.cpp (99%) rename ClangAstDumper/src/{ => ClangAstDumper}/ClangAstDumperExprs.cpp (99%) rename ClangAstDumper/src/{ => ClangAstDumper}/ClangAstDumperExtra.cpp (100%) rename ClangAstDumper/src/{ => ClangAstDumper}/ClangAstDumperStmts.cpp (98%) rename ClangAstDumper/src/{ => ClangAstDumper}/ClangAstDumperTypes.cpp (98%) rename ClangAstDumper/src/{ => ClangEnums}/ClangEnums.cpp (100%) rename ClangAstDumper/src/{ => ClangEnums}/ClangEnums.h (100%) rename ClangAstDumper/src/{ => Clava}/ClavaConstants.cpp (100%) rename ClangAstDumper/src/{ => Clava}/ClavaConstants.h (100%) rename ClangAstDumper/src/{ => Clava}/ClavaDecl.cpp (100%) rename ClangAstDumper/src/{ => Clava}/ClavaDecl.h (100%) rename ClangAstDumper/src/{ => ClavaDataDumper}/ClavaDataDumper.cpp (97%) rename ClangAstDumper/src/{ => ClavaDataDumper}/ClavaDataDumper.h (99%) rename ClangAstDumper/src/{ => ClavaDataDumper}/ClavaDataDumperAttrs.cpp (96%) rename ClangAstDumper/src/{ => ClavaDataDumper}/ClavaDataDumperDecls.cpp (99%) rename ClangAstDumper/src/{ => ClavaDataDumper}/ClavaDataDumperStmts.cpp (99%) rename ClangAstDumper/src/{ => ClavaDataDumper}/ClavaDataDumperTypes.cpp (99%) rename ClangAstDumper/src/{ => TypeMarker}/TypeMarker.cpp (100%) rename ClangAstDumper/src/{ => TypeMarker}/TypeMarker.h (87%) delete mode 100644 ClangAstDumper/src/enums_AttrKinds_h.cpp delete mode 100644 ClangAstDumper/src/enums_Attr_h.cpp delete mode 100644 ClangAstDumper/src/enums_DeclCXX_h.cpp delete mode 100644 ClangAstDumper/src/enums_Decl_h.cpp delete mode 100644 ClangAstDumper/src/enums_ExceptionSpecificationType_h.cpp delete mode 100644 ClangAstDumper/src/enums_ExprCXX_h.cpp delete mode 100644 ClangAstDumper/src/enums_Expr_h.cpp delete mode 100644 ClangAstDumper/src/enums_Lambda_h.cpp delete mode 100644 ClangAstDumper/src/enums_Linkage_h.cpp delete mode 100644 ClangAstDumper/src/enums_NestedNameSpecifier_h.cpp delete mode 100644 ClangAstDumper/src/enums_OperationKinds_h.cpp delete mode 100644 ClangAstDumper/src/enums_Specifiers_h.cpp delete mode 100644 ClangAstDumper/src/enums_TemplateBase_h.cpp delete mode 100644 ClangAstDumper/src/enums_TemplateName_h.cpp delete mode 100644 ClangAstDumper/src/enums_TypeTraits_h.cpp delete mode 100644 ClangAstDumper/src/enums_Type_h.cpp delete mode 100644 ClangAstDumper/src/enums_Visibility_h.cpp rename ClangAstDumper/src/{newmain.cpp => plugin.cpp} (90%) rename ClangAstDumper/src/{main.cpp => standalone.cpp} (100%) diff --git a/ClangAstDumper/.gitignore b/ClangAstDumper/.gitignore index 247a090e8..2ad53894f 100644 --- a/ClangAstDumper/.gitignore +++ b/ClangAstDumper/.gitignore @@ -11,4 +11,5 @@ testSources *.o *.a +src/ClangEnums/enums_* java_enums/ \ No newline at end of file diff --git a/ClangAstDumper/CMakeLists.txt b/ClangAstDumper/CMakeLists.txt index cd2df2436..8563cefb0 100644 --- a/ClangAstDumper/CMakeLists.txt +++ b/ClangAstDumper/CMakeLists.txt @@ -19,47 +19,47 @@ include_directories("/usr/lib/llvm-${CLANG_VERSION}/include/") set(SOURCE_FILES - src/newmain.cpp - src/ClangAst.cpp - src/ClangNodes.cpp - src/TypeMarker.cpp - src/ClavaDataDumper.cpp - src/ClavaDataDumperAttrs.cpp - src/ClavaDataDumperDecls.cpp - src/ClavaDataDumperStmts.cpp - src/ClavaDataDumperTypes.cpp - src/ClavaConstants.cpp - src/ClavaDecl.cpp - src/ChildrenVisitorAttrs.cpp - src/ChildrenVisitorDecls.cpp - src/ChildrenVisitorExtras.cpp - src/ChildrenVisitorStmts.cpp - src/ChildrenVisitorTypes.cpp - src/ClangAstDumper.cpp - src/ClangAstDumperAttr.cpp - src/ClangAstDumperDecls.cpp - src/ClangAstDumperExprs.cpp - src/ClangAstDumperExtra.cpp - src/ClangAstDumperStmts.cpp - src/ClangAstDumperTypes.cpp - src/ClangEnums.cpp - src/enums_Type_h.cpp - src/enums_OperationKinds_h.cpp - src/enums_AttrKinds_h.cpp - src/enums_Specifiers_h.cpp - src/enums_ExceptionSpecificationType_h.cpp - src/enums_Linkage_h.cpp - src/enums_Visibility_h.cpp - src/enums_TemplateBase_h.cpp - src/enums_Decl_h.cpp - src/enums_ExprCXX_h.cpp - src/enums_TypeTraits_h.cpp - src/enums_NestedNameSpecifier_h.cpp - src/enums_DeclCXX_h.cpp - src/enums_Lambda_h.cpp - src/enums_TemplateName_h.cpp - src/enums_Attr_h.cpp - src/enums_Expr_h.cpp + src/plugin.cpp + src/Clang/ClangAst.cpp + src/Clang/ClangNodes.cpp + src/TypeMarker/TypeMarker.cpp + src/Clava/ClavaConstants.cpp + src/Clava/ClavaDecl.cpp + src/ClavaDataDumper/ClavaDataDumper.cpp + src/ClavaDataDumper/ClavaDataDumperAttrs.cpp + src/ClavaDataDumper/ClavaDataDumperDecls.cpp + src/ClavaDataDumper/ClavaDataDumperStmts.cpp + src/ClavaDataDumper/ClavaDataDumperTypes.cpp + src/ChildrenVisitor/ChildrenVisitorAttrs.cpp + src/ChildrenVisitor/ChildrenVisitorDecls.cpp + src/ChildrenVisitor/ChildrenVisitorExtras.cpp + src/ChildrenVisitor/ChildrenVisitorStmts.cpp + src/ChildrenVisitor/ChildrenVisitorTypes.cpp + src/ClangAstDumper/ClangAstDumper.cpp + src/ClangAstDumper/ClangAstDumperAttr.cpp + src/ClangAstDumper/ClangAstDumperDecls.cpp + src/ClangAstDumper/ClangAstDumperExprs.cpp + src/ClangAstDumper/ClangAstDumperExtra.cpp + src/ClangAstDumper/ClangAstDumperStmts.cpp + src/ClangAstDumper/ClangAstDumperTypes.cpp + src/ClangEnums/ClangEnums.cpp + src/ClangEnums/enums_Type_h.cpp + src/ClangEnums/enums_OperationKinds_h.cpp + src/ClangEnums/enums_AttrKinds_h.cpp + src/ClangEnums/enums_Specifiers_h.cpp + src/ClangEnums/enums_ExceptionSpecificationType_h.cpp + src/ClangEnums/enums_Linkage_h.cpp + src/ClangEnums/enums_Visibility_h.cpp + src/ClangEnums/enums_TemplateBase_h.cpp + src/ClangEnums/enums_Decl_h.cpp + src/ClangEnums/enums_ExprCXX_h.cpp + src/ClangEnums/enums_TypeTraits_h.cpp + src/ClangEnums/enums_NestedNameSpecifier_h.cpp + src/ClangEnums/enums_DeclCXX_h.cpp + src/ClangEnums/enums_Lambda_h.cpp + src/ClangEnums/enums_TemplateName_h.cpp + src/ClangEnums/enums_Attr_h.cpp + src/ClangEnums/enums_Expr_h.cpp ) add_library(MyPlugin SHARED ${SOURCE_FILES}) diff --git a/ClangAstDumper/clang_enums/Main.js b/ClangAstDumper/clang_enums/Main.js index bc16231f7..9f6f2f29b 100755 --- a/ClangAstDumper/clang_enums/Main.js +++ b/ClangAstDumper/clang_enums/Main.js @@ -9,15 +9,17 @@ const outputFolder = process.argv[3]; const compilerCmd = `clang++-${llvmVersion}`; const llvmFolder = `/usr/lib/llvm-${llvmVersion}/lib/cmake/llvm`; +const cppEnumsOutputFolder = path.join(outputFolder, "ClangEnums"); const javaEnumsOutputFolder = path.join(outputFolder, "java_enums"); console.log("Using LLVM folder '" + llvmFolder + "'"); console.log("Generating enums to folder '" + outputFolder + "'"); -fs.mkdirSync(javaEnumsOutputFolder, {recursive: true}); +fs.mkdirSync(cppEnumsOutputFolder, { recursive: true }); +fs.mkdirSync(javaEnumsOutputFolder, { recursive: true }); for (const header of Headers) { header.process(compilerCmd, llvmFolder); - header.generateCode(outputFolder); + header.generateCode(cppEnumsOutputFolder); header.generateJavaEnums(javaEnumsOutputFolder); } diff --git a/ClangAstDumper/src/ChildrenVisitorAttrs.cpp b/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorAttrs.cpp similarity index 93% rename from ClangAstDumper/src/ChildrenVisitorAttrs.cpp rename to ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorAttrs.cpp index 6707d1d9c..17507af2c 100644 --- a/ClangAstDumper/src/ChildrenVisitorAttrs.cpp +++ b/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorAttrs.cpp @@ -2,9 +2,9 @@ // Created by JoaoBispo on 12/04/2018. // -#include "ClangAstDumper.h" -#include "ClangNodes.h" -#include "ClavaConstants.h" +#include "../ClangAstDumper/ClangAstDumper.h" +#include "../Clang/ClangNodes.h" +#include "../Clava/ClavaDecl.h" #include diff --git a/ClangAstDumper/src/ChildrenVisitorDecls.cpp b/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorDecls.cpp similarity index 99% rename from ClangAstDumper/src/ChildrenVisitorDecls.cpp rename to ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorDecls.cpp index e1e9571a8..56198b5fd 100644 --- a/ClangAstDumper/src/ChildrenVisitorDecls.cpp +++ b/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorDecls.cpp @@ -2,10 +2,10 @@ // Created by JoaoBispo on 20/03/2018. // -#include "ClangAstDumper.h" -#include "ClangNodes.h" -#include "ClavaConstants.h" -#include "ClangEnums.h" +#include "../ClangAstDumper/ClangAstDumper.h" +#include "../Clang/ClangNodes.h" +#include "../ClangEnums/ClangEnums.h" +#include "../Clava/ClavaConstants.h" #include diff --git a/ClangAstDumper/src/ChildrenVisitorExtras.cpp b/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorExtras.cpp similarity index 95% rename from ClangAstDumper/src/ChildrenVisitorExtras.cpp rename to ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorExtras.cpp index 45954ee33..cf9b7874e 100644 --- a/ClangAstDumper/src/ChildrenVisitorExtras.cpp +++ b/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorExtras.cpp @@ -2,10 +2,10 @@ * EXTRA Visitors */ -#include "ClangAstDumper.h" -#include "ClavaConstants.h" -#include "ClangNodes.h" -#include "ClangEnums.h" +#include "../ClangEnums/ClangEnums.h" +#include "../Clang/ClangNodes.h" +#include "../ClangAstDumper/ClangAstDumper.h" +#include "../Clava/ClavaConstants.h" #include diff --git a/ClangAstDumper/src/ChildrenVisitorStmts.cpp b/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorStmts.cpp similarity index 99% rename from ClangAstDumper/src/ChildrenVisitorStmts.cpp rename to ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorStmts.cpp index 66d041bf2..77a37aea1 100644 --- a/ClangAstDumper/src/ChildrenVisitorStmts.cpp +++ b/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorStmts.cpp @@ -2,10 +2,10 @@ // Created by JoaoBispo on 01/04/2018. // -#include "ClangAstDumper.h" -#include "ClavaConstants.h" -#include "ClangNodes.h" -#include "ClangEnums.h" +#include "../ClangEnums/ClangEnums.h" +#include "../Clang/ClangNodes.h" +#include "../ClangAstDumper/ClangAstDumper.h" +#include "../Clava/ClavaConstants.h" #include diff --git a/ClangAstDumper/src/ChildrenVisitorTypes.cpp b/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorTypes.cpp similarity index 99% rename from ClangAstDumper/src/ChildrenVisitorTypes.cpp rename to ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorTypes.cpp index 7ea805681..ce63fc03d 100644 --- a/ClangAstDumper/src/ChildrenVisitorTypes.cpp +++ b/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorTypes.cpp @@ -1,9 +1,9 @@ // // Created by JoaoBispo on 05/04/2018. // -#include "ClangAstDumper.h" -#include "ClavaConstants.h" -#include "ClangNodes.h" +#include "../Clang/ClangNodes.h" +#include "../ClangAstDumper/ClangAstDumper.h" +#include "../Clava/ClavaConstants.h" #include diff --git a/ClangAstDumper/src/ClangAst.cpp b/ClangAstDumper/src/Clang/ClangAst.cpp similarity index 99% rename from ClangAstDumper/src/ClangAst.cpp rename to ClangAstDumper/src/Clang/ClangAst.cpp index 299b9f9c0..739e92a86 100644 --- a/ClangAstDumper/src/ClangAst.cpp +++ b/ClangAstDumper/src/Clang/ClangAst.cpp @@ -5,7 +5,7 @@ // Based on public domain code by Eli Bendersky (eliben@gmail.com) - http://eli.thegreenplace.net/ //------------------------------------------------------------------------------ #include "ClangAst.h" -#include "ClangAstDumperConstants.h" +#include "../ClangAstDumper/ClangAstDumperConstants.h" #include "ClangNodes.h" #include "clang/AST/AST.h" diff --git a/ClangAstDumper/src/ClangAst.h b/ClangAstDumper/src/Clang/ClangAst.h similarity index 99% rename from ClangAstDumper/src/ClangAst.h rename to ClangAstDumper/src/Clang/ClangAst.h index 74cd42e3e..6e758ea3a 100644 --- a/ClangAstDumper/src/ClangAst.h +++ b/ClangAstDumper/src/Clang/ClangAst.h @@ -8,7 +8,7 @@ #ifndef CLANGASTDUMPER_CLANGAST_H #define CLANGASTDUMPER_CLANGAST_H -#include "ClangAstDumper.h" +#include "../ClangAstDumper/ClangAstDumper.h" #include "clang/AST/AST.h" #include "clang/AST/RecursiveASTVisitor.h" diff --git a/ClangAstDumper/src/ClangNodes.cpp b/ClangAstDumper/src/Clang/ClangNodes.cpp similarity index 99% rename from ClangAstDumper/src/ClangNodes.cpp rename to ClangAstDumper/src/Clang/ClangNodes.cpp index 83d85c63d..782f01482 100644 --- a/ClangAstDumper/src/ClangNodes.cpp +++ b/ClangAstDumper/src/Clang/ClangNodes.cpp @@ -3,7 +3,7 @@ // #include "ClangNodes.h" -#include "ClangEnums.h" +#include "../ClangEnums/ClangEnums.h" #include "clang/Lex/Lexer.h" #include "clang/AST/Attr.h" diff --git a/ClangAstDumper/src/ClangNodes.h b/ClangAstDumper/src/Clang/ClangNodes.h similarity index 100% rename from ClangAstDumper/src/ClangNodes.h rename to ClangAstDumper/src/Clang/ClangNodes.h diff --git a/ClangAstDumper/src/ClangAstDumper.cpp b/ClangAstDumper/src/ClangAstDumper/ClangAstDumper.cpp similarity index 99% rename from ClangAstDumper/src/ClangAstDumper.cpp rename to ClangAstDumper/src/ClangAstDumper/ClangAstDumper.cpp index 6c4329dc5..1fbe5f3f7 100644 --- a/ClangAstDumper/src/ClangAstDumper.cpp +++ b/ClangAstDumper/src/ClangAstDumper/ClangAstDumper.cpp @@ -4,8 +4,8 @@ #include "ClangAstDumper.h" #include "ClangAstDumperConstants.h" -#include "ClangNodes.h" -#include "ClangEnums.h" +#include "../Clang/ClangNodes.h" +#include "../ClangEnums/ClangEnums.h" //#include "clang/AST/AST.h" #include "clang/Lex/Lexer.h" diff --git a/ClangAstDumper/src/ClangAstDumper.h b/ClangAstDumper/src/ClangAstDumper/ClangAstDumper.h similarity index 99% rename from ClangAstDumper/src/ClangAstDumper.h rename to ClangAstDumper/src/ClangAstDumper/ClangAstDumper.h index 921e81638..62b15b224 100644 --- a/ClangAstDumper/src/ClangAstDumper.h +++ b/ClangAstDumper/src/ClangAstDumper/ClangAstDumper.h @@ -5,7 +5,7 @@ #ifndef CLANGASTDUMPER_CLANGASTDUMPER_H #define CLANGASTDUMPER_CLANGASTDUMPER_H -#include "ClavaDataDumper.h" +#include "../ClavaDataDumper/ClavaDataDumper.h" #include "clang/AST/TypeVisitor.h" #include "clang/AST/StmtVisitor.h" diff --git a/ClangAstDumper/src/ClangAstDumperAttr.cpp b/ClangAstDumper/src/ClangAstDumper/ClangAstDumperAttr.cpp similarity index 97% rename from ClangAstDumper/src/ClangAstDumperAttr.cpp rename to ClangAstDumper/src/ClangAstDumper/ClangAstDumperAttr.cpp index 8118ce4e2..e8928a2fa 100644 --- a/ClangAstDumper/src/ClangAstDumperAttr.cpp +++ b/ClangAstDumper/src/ClangAstDumper/ClangAstDumperAttr.cpp @@ -3,7 +3,7 @@ // #include "ClangAstDumper.h" -#include "ClangNodes.h" +#include "../Clang/ClangNodes.h" #include "clang/AST/Attr.h" diff --git a/ClangAstDumper/src/ClangAstDumperConstants.h b/ClangAstDumper/src/ClangAstDumper/ClangAstDumperConstants.h similarity index 100% rename from ClangAstDumper/src/ClangAstDumperConstants.h rename to ClangAstDumper/src/ClangAstDumper/ClangAstDumperConstants.h diff --git a/ClangAstDumper/src/ClangAstDumperDecls.cpp b/ClangAstDumper/src/ClangAstDumper/ClangAstDumperDecls.cpp similarity index 99% rename from ClangAstDumper/src/ClangAstDumperDecls.cpp rename to ClangAstDumper/src/ClangAstDumper/ClangAstDumperDecls.cpp index d2af8258a..b874d9c48 100644 --- a/ClangAstDumper/src/ClangAstDumperDecls.cpp +++ b/ClangAstDumper/src/ClangAstDumper/ClangAstDumperDecls.cpp @@ -4,7 +4,7 @@ #include "ClangAstDumper.h" #include "ClangAstDumperConstants.h" -#include "ClangNodes.h" +#include "../Clang/ClangNodes.h" //#include "InfoDumperConstants.h" #include "clang/AST/AST.h" diff --git a/ClangAstDumper/src/ClangAstDumperExprs.cpp b/ClangAstDumper/src/ClangAstDumper/ClangAstDumperExprs.cpp similarity index 99% rename from ClangAstDumper/src/ClangAstDumperExprs.cpp rename to ClangAstDumper/src/ClangAstDumper/ClangAstDumperExprs.cpp index 8ae94187a..32fe5b7ca 100644 --- a/ClangAstDumper/src/ClangAstDumperExprs.cpp +++ b/ClangAstDumper/src/ClangAstDumper/ClangAstDumperExprs.cpp @@ -2,9 +2,9 @@ // Created by JoaoBispo on 31/03/2018. // +#include "../Clang/ClangNodes.h" #include "ClangAstDumper.h" #include "ClangAstDumperConstants.h" -#include "ClangNodes.h" #include "clang/AST/AST.h" diff --git a/ClangAstDumper/src/ClangAstDumperExtra.cpp b/ClangAstDumper/src/ClangAstDumper/ClangAstDumperExtra.cpp similarity index 100% rename from ClangAstDumper/src/ClangAstDumperExtra.cpp rename to ClangAstDumper/src/ClangAstDumper/ClangAstDumperExtra.cpp diff --git a/ClangAstDumper/src/ClangAstDumperStmts.cpp b/ClangAstDumper/src/ClangAstDumper/ClangAstDumperStmts.cpp similarity index 98% rename from ClangAstDumper/src/ClangAstDumperStmts.cpp rename to ClangAstDumper/src/ClangAstDumper/ClangAstDumperStmts.cpp index 18bc1a4ef..2705b3d76 100644 --- a/ClangAstDumper/src/ClangAstDumperStmts.cpp +++ b/ClangAstDumper/src/ClangAstDumper/ClangAstDumperStmts.cpp @@ -4,7 +4,7 @@ #include "ClangAstDumper.h" #include "ClangAstDumperConstants.h" -#include "ClangNodes.h" +#include "../Clang/ClangNodes.h" #include "clang/AST/AST.h" diff --git a/ClangAstDumper/src/ClangAstDumperTypes.cpp b/ClangAstDumper/src/ClangAstDumper/ClangAstDumperTypes.cpp similarity index 98% rename from ClangAstDumper/src/ClangAstDumperTypes.cpp rename to ClangAstDumper/src/ClangAstDumper/ClangAstDumperTypes.cpp index d8160b510..3031f0f38 100644 --- a/ClangAstDumper/src/ClangAstDumperTypes.cpp +++ b/ClangAstDumper/src/ClangAstDumper/ClangAstDumperTypes.cpp @@ -4,7 +4,7 @@ #include "ClangAstDumper.h" #include "ClangAstDumperConstants.h" -#include "ClangNodes.h" +#include "../Clang/ClangNodes.h" #include "clang/AST/AST.h" diff --git a/ClangAstDumper/src/ClangEnums.cpp b/ClangAstDumper/src/ClangEnums/ClangEnums.cpp similarity index 100% rename from ClangAstDumper/src/ClangEnums.cpp rename to ClangAstDumper/src/ClangEnums/ClangEnums.cpp diff --git a/ClangAstDumper/src/ClangEnums.h b/ClangAstDumper/src/ClangEnums/ClangEnums.h similarity index 100% rename from ClangAstDumper/src/ClangEnums.h rename to ClangAstDumper/src/ClangEnums/ClangEnums.h diff --git a/ClangAstDumper/src/ClavaConstants.cpp b/ClangAstDumper/src/Clava/ClavaConstants.cpp similarity index 100% rename from ClangAstDumper/src/ClavaConstants.cpp rename to ClangAstDumper/src/Clava/ClavaConstants.cpp diff --git a/ClangAstDumper/src/ClavaConstants.h b/ClangAstDumper/src/Clava/ClavaConstants.h similarity index 100% rename from ClangAstDumper/src/ClavaConstants.h rename to ClangAstDumper/src/Clava/ClavaConstants.h diff --git a/ClangAstDumper/src/ClavaDecl.cpp b/ClangAstDumper/src/Clava/ClavaDecl.cpp similarity index 100% rename from ClangAstDumper/src/ClavaDecl.cpp rename to ClangAstDumper/src/Clava/ClavaDecl.cpp diff --git a/ClangAstDumper/src/ClavaDecl.h b/ClangAstDumper/src/Clava/ClavaDecl.h similarity index 100% rename from ClangAstDumper/src/ClavaDecl.h rename to ClangAstDumper/src/Clava/ClavaDecl.h diff --git a/ClangAstDumper/src/ClavaDataDumper.cpp b/ClangAstDumper/src/ClavaDataDumper/ClavaDataDumper.cpp similarity index 97% rename from ClangAstDumper/src/ClavaDataDumper.cpp rename to ClangAstDumper/src/ClavaDataDumper/ClavaDataDumper.cpp index df2a6bef7..5f49194f1 100644 --- a/ClangAstDumper/src/ClavaDataDumper.cpp +++ b/ClangAstDumper/src/ClavaDataDumper/ClavaDataDumper.cpp @@ -4,8 +4,8 @@ #include "ClavaDataDumper.h" -#include "ClavaConstants.h" -#include "ClangNodes.h" +#include "../Clang/ClangNodes.h" +#include "../Clava/ClavaConstants.h" #include diff --git a/ClangAstDumper/src/ClavaDataDumper.h b/ClangAstDumper/src/ClavaDataDumper/ClavaDataDumper.h similarity index 99% rename from ClangAstDumper/src/ClavaDataDumper.h rename to ClangAstDumper/src/ClavaDataDumper/ClavaDataDumper.h index 967b90e21..0166b4b28 100644 --- a/ClangAstDumper/src/ClavaDataDumper.h +++ b/ClangAstDumper/src/ClavaDataDumper/ClavaDataDumper.h @@ -6,8 +6,8 @@ #ifndef CLANGASTDUMPER_CLAVADATADUMPER_H #define CLANGASTDUMPER_CLAVADATADUMPER_H -#include "ClavaConstants.h" -#include "ClavaDecl.h" +#include "../Clava/ClavaConstants.h" +#include "../Clava/ClavaDecl.h" #include "clang/AST/AST.h" #include "clang/AST/Decl.h" diff --git a/ClangAstDumper/src/ClavaDataDumperAttrs.cpp b/ClangAstDumper/src/ClavaDataDumper/ClavaDataDumperAttrs.cpp similarity index 96% rename from ClangAstDumper/src/ClavaDataDumperAttrs.cpp rename to ClangAstDumper/src/ClavaDataDumper/ClavaDataDumperAttrs.cpp index 1efd82b3f..5de2b0b10 100644 --- a/ClangAstDumper/src/ClavaDataDumperAttrs.cpp +++ b/ClangAstDumper/src/ClavaDataDumper/ClavaDataDumperAttrs.cpp @@ -2,10 +2,10 @@ // Created by JoaoBispo on 12/04/2018. // -#include "ClavaDataDumper.h" -#include "ClangNodes.h" -#include "ClavaConstants.h" -#include "ClangEnums.h" +#include "../ClangEnums/ClangEnums.h" +#include "../Clang/ClangNodes.h" +#include "../Clava/ClavaConstants.h" +#include "../ClavaDataDumper/ClavaDataDumper.h" #include diff --git a/ClangAstDumper/src/ClavaDataDumperDecls.cpp b/ClangAstDumper/src/ClavaDataDumper/ClavaDataDumperDecls.cpp similarity index 99% rename from ClangAstDumper/src/ClavaDataDumperDecls.cpp rename to ClangAstDumper/src/ClavaDataDumper/ClavaDataDumperDecls.cpp index 7257252d0..fc45233d7 100644 --- a/ClangAstDumper/src/ClavaDataDumperDecls.cpp +++ b/ClangAstDumper/src/ClavaDataDumper/ClavaDataDumperDecls.cpp @@ -2,10 +2,9 @@ // Created by JoaoBispo on 18/03/2018. // -#include "ClavaDataDumper.h" -#include "ClangNodes.h" -//#include "ClavaConstants.h" -#include "ClangEnums.h" +#include "../ClavaDataDumper/ClavaDataDumper.h" +#include "../Clang/ClangNodes.h" +#include "../ClangEnums/ClangEnums.h" #include #include diff --git a/ClangAstDumper/src/ClavaDataDumperStmts.cpp b/ClangAstDumper/src/ClavaDataDumper/ClavaDataDumperStmts.cpp similarity index 99% rename from ClangAstDumper/src/ClavaDataDumperStmts.cpp rename to ClangAstDumper/src/ClavaDataDumper/ClavaDataDumperStmts.cpp index a9201e425..587afdbc1 100644 --- a/ClangAstDumper/src/ClavaDataDumperStmts.cpp +++ b/ClangAstDumper/src/ClavaDataDumper/ClavaDataDumperStmts.cpp @@ -2,9 +2,9 @@ // Created by JoaoBispo on 30/03/2018. // -#include "ClavaDataDumper.h" -#include "ClangNodes.h" -#include "ClangEnums.h" +#include "../ClavaDataDumper/ClavaDataDumper.h" +#include "../Clang/ClangNodes.h" +#include "../ClangEnums/ClangEnums.h" #include "clang/Lex/Lexer.h" diff --git a/ClangAstDumper/src/ClavaDataDumperTypes.cpp b/ClangAstDumper/src/ClavaDataDumper/ClavaDataDumperTypes.cpp similarity index 99% rename from ClangAstDumper/src/ClavaDataDumperTypes.cpp rename to ClangAstDumper/src/ClavaDataDumper/ClavaDataDumperTypes.cpp index d974c9344..f9dad1060 100644 --- a/ClangAstDumper/src/ClavaDataDumperTypes.cpp +++ b/ClangAstDumper/src/ClavaDataDumper/ClavaDataDumperTypes.cpp @@ -2,9 +2,9 @@ // Created by JoaoBispo on 30/03/2018. // -#include "ClavaDataDumper.h" -#include "ClangNodes.h" -#include "ClangEnums.h" +#include "../ClavaDataDumper/ClavaDataDumper.h" +#include "../Clang/ClangNodes.h" +#include "../ClangEnums/ClangEnums.h" #include #include diff --git a/ClangAstDumper/src/TypeMarker.cpp b/ClangAstDumper/src/TypeMarker/TypeMarker.cpp similarity index 100% rename from ClangAstDumper/src/TypeMarker.cpp rename to ClangAstDumper/src/TypeMarker/TypeMarker.cpp diff --git a/ClangAstDumper/src/TypeMarker.h b/ClangAstDumper/src/TypeMarker/TypeMarker.h similarity index 87% rename from ClangAstDumper/src/TypeMarker.h rename to ClangAstDumper/src/TypeMarker/TypeMarker.h index 251d4757a..036c4b7f7 100644 --- a/ClangAstDumper/src/TypeMarker.h +++ b/ClangAstDumper/src/TypeMarker/TypeMarker.h @@ -11,9 +11,9 @@ using namespace clang; -class TypeMarker : public TypeVisitor { +class TypeMarker : public clang::TypeVisitor { -private: + private: int id; std::set &seenTypes; void markType(const Type *T); @@ -24,5 +24,4 @@ class TypeMarker : public TypeVisitor { void VisitTypedefType(const TypedefType *T); }; - #endif //CLANGASTDUMPER_TYPEMARKER_H diff --git a/ClangAstDumper/src/enums_AttrKinds_h.cpp b/ClangAstDumper/src/enums_AttrKinds_h.cpp deleted file mode 100644 index 85cff79b1..000000000 --- a/ClangAstDumper/src/enums_AttrKinds_h.cpp +++ /dev/null @@ -1,379 +0,0 @@ -#include "ClangEnums.h" - -extern const std::string clava::ATTRIBUTES[] = { - "AddressSpace", - "AnnotateType", - "ArmMveStrictPolymorphism", - "BTFTypeTag", - "CmseNSCall", - "NoDeref", - "ObjCGC", - "ObjCInertUnsafeUnretained", - "ObjCKindOf", - "OpenCLConstantAddressSpace", - "OpenCLGenericAddressSpace", - "OpenCLGlobalAddressSpace", - "OpenCLGlobalDeviceAddressSpace", - "OpenCLGlobalHostAddressSpace", - "OpenCLLocalAddressSpace", - "OpenCLPrivateAddressSpace", - "Ptr32", - "Ptr64", - "SPtr", - "TypeNonNull", - "TypeNullUnspecified", - "TypeNullable", - "TypeNullableResult", - "UPtr", - "FallThrough", - "Likely", - "MustTail", - "OpenCLUnrollHint", - "Suppress", - "Unlikely", - "AlwaysInline", - "NoInline", - "NoMerge", - "AArch64SVEPcs", - "AArch64VectorPcs", - "AMDGPUKernelCall", - "AcquireHandle", - "AnyX86NoCfCheck", - "CDecl", - "FastCall", - "IntelOclBicc", - "LifetimeBound", - "MSABI", - "NSReturnsRetained", - "ObjCOwnership", - "Pascal", - "Pcs", - "PreserveAll", - "PreserveMost", - "RegCall", - "StdCall", - "SwiftAsyncCall", - "SwiftCall", - "SysVABI", - "ThisCall", - "VectorCall", - "SwiftAsyncContext", - "SwiftContext", - "SwiftErrorResult", - "SwiftIndirectResult", - "Annotate", - "CFConsumed", - "CarriesDependency", - "NSConsumed", - "NonNull", - "OSConsumed", - "PassObjectSize", - "ReleaseHandle", - "UseHandle", - "AMDGPUFlatWorkGroupSize", - "AMDGPUNumSGPR", - "AMDGPUNumVGPR", - "AMDGPUWavesPerEU", - "ARMInterrupt", - "AVRInterrupt", - "AVRSignal", - "AcquireCapability", - "AcquiredAfter", - "AcquiredBefore", - "AlignMac68k", - "AlignNatural", - "Aligned", - "AllocAlign", - "AllocSize", - "AlwaysDestroy", - "AnalyzerNoReturn", - "AnyX86Interrupt", - "AnyX86NoCallerSavedRegisters", - "ArcWeakrefUnavailable", - "ArgumentWithTypeTag", - "ArmBuiltinAlias", - "Artificial", - "AsmLabel", - "AssertCapability", - "AssertExclusiveLock", - "AssertSharedLock", - "AssumeAligned", - "Assumption", - "Availability", - "BPFPreserveAccessIndex", - "BTFDeclTag", - "Blocks", - "Builtin", - "C11NoReturn", - "CFAuditedTransfer", - "CFGuard", - "CFICanonicalJumpTable", - "CFReturnsNotRetained", - "CFReturnsRetained", - "CFUnknownTransfer", - "CPUDispatch", - "CPUSpecific", - "CUDAConstant", - "CUDADevice", - "CUDADeviceBuiltinSurfaceType", - "CUDADeviceBuiltinTextureType", - "CUDAGlobal", - "CUDAHost", - "CUDAInvalidTarget", - "CUDALaunchBounds", - "CUDAShared", - "CXX11NoReturn", - "CallableWhen", - "Callback", - "Capability", - "CapturedRecord", - "Cleanup", - "CmseNSEntry", - "CodeSeg", - "Cold", - "Common", - "Const", - "ConstInit", - "Constructor", - "Consumable", - "ConsumableAutoCast", - "ConsumableSetOnRead", - "Convergent", - "DLLExport", - "DLLExportStaticLocal", - "DLLImport", - "DLLImportStaticLocal", - "Deprecated", - "Destructor", - "DiagnoseAsBuiltin", - "DiagnoseIf", - "DisableSanitizerInstrumentation", - "DisableTailCalls", - "EmptyBases", - "EnableIf", - "EnforceTCB", - "EnforceTCBLeaf", - "EnumExtensibility", - "Error", - "ExcludeFromExplicitInstantiation", - "ExclusiveTrylockFunction", - "ExternalSourceSymbol", - "Final", - "FlagEnum", - "Flatten", - "Format", - "FormatArg", - "FunctionReturnThunks", - "GNUInline", - "GuardedBy", - "GuardedVar", - "HIPManaged", - "HLSLNumThreads", - "HLSLSV_GroupIndex", - "HLSLShader", - "Hot", - "IBAction", - "IBOutlet", - "IBOutletCollection", - "InitPriority", - "InternalLinkage", - "LTOVisibilityPublic", - "LayoutVersion", - "Leaf", - "LockReturned", - "LocksExcluded", - "M68kInterrupt", - "MIGServerRoutine", - "MSAllocator", - "MSInheritance", - "MSNoVTable", - "MSP430Interrupt", - "MSStruct", - "MSVtorDisp", - "MaxFieldAlignment", - "MayAlias", - "MicroMips", - "MinSize", - "MinVectorWidth", - "Mips16", - "MipsInterrupt", - "MipsLongCall", - "MipsShortCall", - "NSConsumesSelf", - "NSErrorDomain", - "NSReturnsAutoreleased", - "NSReturnsNotRetained", - "Naked", - "NoAlias", - "NoCommon", - "NoDebug", - "NoDestroy", - "NoDuplicate", - "NoInstrumentFunction", - "NoMicroMips", - "NoMips16", - "NoProfileFunction", - "NoRandomizeLayout", - "NoReturn", - "NoSanitize", - "NoSpeculativeLoadHardening", - "NoSplitStack", - "NoStackProtector", - "NoThreadSafetyAnalysis", - "NoThrow", - "NoUniqueAddress", - "NotTailCalled", - "OMPAllocateDecl", - "OMPCaptureNoInit", - "OMPDeclareTargetDecl", - "OMPDeclareVariant", - "OMPThreadPrivateDecl", - "OSConsumesThis", - "OSReturnsNotRetained", - "OSReturnsRetained", - "OSReturnsRetainedOnNonZero", - "OSReturnsRetainedOnZero", - "ObjCBridge", - "ObjCBridgeMutable", - "ObjCBridgeRelated", - "ObjCException", - "ObjCExplicitProtocolImpl", - "ObjCExternallyRetained", - "ObjCIndependentClass", - "ObjCMethodFamily", - "ObjCNSObject", - "ObjCPreciseLifetime", - "ObjCRequiresPropertyDefs", - "ObjCRequiresSuper", - "ObjCReturnsInnerPointer", - "ObjCRootClass", - "ObjCSubclassingRestricted", - "OpenCLIntelReqdSubGroupSize", - "OpenCLKernel", - "OptimizeNone", - "Override", - "Owner", - "Ownership", - "Packed", - "ParamTypestate", - "PatchableFunctionEntry", - "Pointer", - "PragmaClangBSSSection", - "PragmaClangDataSection", - "PragmaClangRelroSection", - "PragmaClangRodataSection", - "PragmaClangTextSection", - "PreferredName", - "PtGuardedBy", - "PtGuardedVar", - "Pure", - "RISCVInterrupt", - "RandomizeLayout", - "Reinitializes", - "ReleaseCapability", - "ReqdWorkGroupSize", - "RequiresCapability", - "Restrict", - "Retain", - "ReturnTypestate", - "ReturnsNonNull", - "ReturnsTwice", - "SYCLKernel", - "SYCLSpecialClass", - "ScopedLockable", - "Section", - "SelectAny", - "Sentinel", - "SetTypestate", - "SharedTrylockFunction", - "SpeculativeLoadHardening", - "StandaloneDebug", - "StrictFP", - "SwiftAsync", - "SwiftAsyncError", - "SwiftAsyncName", - "SwiftAttr", - "SwiftBridge", - "SwiftBridgedTypedef", - "SwiftError", - "SwiftName", - "SwiftNewType", - "SwiftPrivate", - "TLSModel", - "Target", - "TargetClones", - "TestTypestate", - "TransparentUnion", - "TrivialABI", - "TryAcquireCapability", - "TypeTagForDatatype", - "TypeVisibility", - "Unavailable", - "Uninitialized", - "Unused", - "Used", - "UsingIfExists", - "Uuid", - "VecReturn", - "VecTypeHint", - "Visibility", - "WarnUnused", - "WarnUnusedResult", - "Weak", - "WeakImport", - "WeakRef", - "WebAssemblyExportName", - "WebAssemblyImportModule", - "WebAssemblyImportName", - "WorkGroupSizeHint", - "X86ForceAlignArgPointer", - "XRayInstrument", - "XRayLogArgs", - "ZeroCallUsedRegs", - "AbiTag", - "Alias", - "AlignValue", - "BuiltinAlias", - "CalledOnce", - "IFunc", - "InitSeg", - "LoaderUninitialized", - "LoopHint", - "Mode", - "NoBuiltin", - "NoEscape", - "OMPCaptureKind", - "OMPDeclareSimdDecl", - "OMPReferencedVar", - "ObjCBoxable", - "ObjCClassStub", - "ObjCDesignatedInitializer", - "ObjCDirect", - "ObjCDirectMembers", - "ObjCNonLazyClass", - "ObjCNonRuntimeProtocol", - "ObjCRuntimeName", - "ObjCRuntimeVisible", - "OpenCLAccess", - "Overloadable", - "RenderScriptKernel", - "SwiftObjCMembers", - "Thread", - "FirstAttr", - "LastAttr", - "FirstTypeAttr", - "LastTypeAttr", - "FirstStmtAttr", - "LastStmtAttr", - "FirstDeclOrStmtAttr", - "LastDeclOrStmtAttr", - "FirstInheritableAttr", - "LastInheritableAttr", - "FirstDeclOrTypeAttr", - "LastDeclOrTypeAttr", - "FirstInheritableParamAttr", - "LastInheritableParamAttr", - "FirstParameterABIAttr", - "LastParameterABIAttr", -}; - diff --git a/ClangAstDumper/src/enums_Attr_h.cpp b/ClangAstDumper/src/enums_Attr_h.cpp deleted file mode 100644 index 607130f7d..000000000 --- a/ClangAstDumper/src/enums_Attr_h.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "ClangEnums.h" - -extern const std::string clava::VISIBILITY_ATTR_TYPE[] = { - "Default", - "Hidden", - "Protected", -}; - diff --git a/ClangAstDumper/src/enums_DeclCXX_h.cpp b/ClangAstDumper/src/enums_DeclCXX_h.cpp deleted file mode 100644 index 97b9a0eb6..000000000 --- a/ClangAstDumper/src/enums_DeclCXX_h.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "ClangEnums.h" - -extern const std::string clava::LINKAGE_LANGUAGE[] = { - "C", - "CXX", -}; - diff --git a/ClangAstDumper/src/enums_Decl_h.cpp b/ClangAstDumper/src/enums_Decl_h.cpp deleted file mode 100644 index aef031507..000000000 --- a/ClangAstDumper/src/enums_Decl_h.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "ClangEnums.h" - -extern const std::string clava::INIT_STYLE[] = { - "CINIT", - "CALL_INIT", - "LIST_INIT", -}; - -extern const std::string clava::TLS_KIND[] = { - "NONE", - "STATIC", - "DYNAMIC", -}; - diff --git a/ClangAstDumper/src/enums_ExceptionSpecificationType_h.cpp b/ClangAstDumper/src/enums_ExceptionSpecificationType_h.cpp deleted file mode 100644 index 50ebbb551..000000000 --- a/ClangAstDumper/src/enums_ExceptionSpecificationType_h.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "ClangEnums.h" - -extern const std::string clava::EXCEPTION_SPECIFICATION_TYPE[] = { - "None", - "DynamicNone", - "Dynamic", - "MSAny", - "NoThrow", - "BasicNoexcept", - "DependentNoexcept", - "NoexceptFalse", - "NoexceptTrue", - "Unevaluated", - "Uninstantiated", - "Unparsed", -}; - diff --git a/ClangAstDumper/src/enums_ExprCXX_h.cpp b/ClangAstDumper/src/enums_ExprCXX_h.cpp deleted file mode 100644 index 63f233362..000000000 --- a/ClangAstDumper/src/enums_ExprCXX_h.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "ClangEnums.h" - -extern const std::string clava::NEW_INIT_STYLE[] = { - "NO_INIT", - "CALL_INIT", - "LIST_INIT", -}; - -extern const std::string clava::CONSTRUCTION_KIND[] = { - "Complete", - "NonVirtualBase", - "VirtualBase", - "Delegating", -}; - diff --git a/ClangAstDumper/src/enums_Expr_h.cpp b/ClangAstDumper/src/enums_Expr_h.cpp deleted file mode 100644 index 3ec6a7480..000000000 --- a/ClangAstDumper/src/enums_Expr_h.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "ClangEnums.h" - -extern const std::string clava::OFFSET_OF_NODE_KIND[] = { - "ARRAY", - "FIELD", - "IDENTIFIER", - "BASE", -}; - -extern const std::string clava::PREDEFINED_ID_TYPE[] = { - "Func", - "Function", - "LFunction", - "FuncDName", - "FuncSig", - "LFuncSig", - "PrettyFunction", - "PrettyFunctionNoVirtual", -}; - -extern const std::string clava::STRING_KIND[] = { - "ORDINARY", - "WIDE", - "UTF8", - "UTF16", - "UTF32", -}; - diff --git a/ClangAstDumper/src/enums_Lambda_h.cpp b/ClangAstDumper/src/enums_Lambda_h.cpp deleted file mode 100644 index c422ed474..000000000 --- a/ClangAstDumper/src/enums_Lambda_h.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "ClangEnums.h" - -extern const std::string clava::LAMBDA_CAPTURE_DEFAULT[] = { - "None", - "ByCopy", - "ByRef", -}; - -extern const std::string clava::LAMBDA_CAPTURE_KIND[] = { - "This", - "StarThis", - "ByCopy", - "ByRef", - "VLAType", -}; - diff --git a/ClangAstDumper/src/enums_Linkage_h.cpp b/ClangAstDumper/src/enums_Linkage_h.cpp deleted file mode 100644 index 63c90398c..000000000 --- a/ClangAstDumper/src/enums_Linkage_h.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "ClangEnums.h" - -extern const std::string clava::LINKAGE[] = { - "NoLinkage", - "InternalLinkage", - "UniqueExternalLinkage", - "VisibleNoLinkage", - "ModuleInternalLinkage", - "ModuleLinkage", - "ExternalLinkage", -}; - diff --git a/ClangAstDumper/src/enums_NestedNameSpecifier_h.cpp b/ClangAstDumper/src/enums_NestedNameSpecifier_h.cpp deleted file mode 100644 index eebd59b75..000000000 --- a/ClangAstDumper/src/enums_NestedNameSpecifier_h.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "ClangEnums.h" - -extern const std::string clava::NESTED_NAMED_SPECIFIER[] = { - "Identifier", - "Namespace", - "NamespaceAlias", - "TypeSpec", - "TypeSpecWithTemplate", - "Global", - "Super", -}; - diff --git a/ClangAstDumper/src/enums_OperationKinds_h.cpp b/ClangAstDumper/src/enums_OperationKinds_h.cpp deleted file mode 100644 index bd50d2f85..000000000 --- a/ClangAstDumper/src/enums_OperationKinds_h.cpp +++ /dev/null @@ -1,123 +0,0 @@ -#include "ClangEnums.h" - -extern const std::string clava::CAST_KIND[] = { - "Dependent", - "BitCast", - "LValueBitCast", - "LValueToRValueBitCast", - "LValueToRValue", - "NoOp", - "BaseToDerived", - "DerivedToBase", - "UncheckedDerivedToBase", - "Dynamic", - "ToUnion", - "ArrayToPointerDecay", - "FunctionToPointerDecay", - "NullToPointer", - "NullToMemberPointer", - "BaseToDerivedMemberPointer", - "DerivedToBaseMemberPointer", - "MemberPointerToBoolean", - "ReinterpretMemberPointer", - "UserDefinedConversion", - "ConstructorConversion", - "IntegralToPointer", - "PointerToIntegral", - "PointerToBoolean", - "ToVoid", - "MatrixCast", - "VectorSplat", - "IntegralCast", - "IntegralToBoolean", - "IntegralToFloating", - "FloatingToFixedPoint", - "FixedPointToFloating", - "FixedPointCast", - "FixedPointToIntegral", - "IntegralToFixedPoint", - "FixedPointToBoolean", - "FloatingToIntegral", - "FloatingToBoolean", - "BooleanToSignedIntegral", - "FloatingCast", - "CPointerToObjCPointerCast", - "BlockPointerToObjCPointerCast", - "AnyPointerToBlockPointerCast", - "ObjCObjectLValueCast", - "FloatingRealToComplex", - "FloatingComplexToReal", - "FloatingComplexToBoolean", - "FloatingComplexCast", - "FloatingComplexToIntegralComplex", - "IntegralRealToComplex", - "IntegralComplexToReal", - "IntegralComplexToBoolean", - "IntegralComplexCast", - "IntegralComplexToFloatingComplex", - "ARCProduceObject", - "ARCConsumeObject", - "ARCReclaimReturnedObject", - "ARCExtendBlockObject", - "AtomicToNonAtomic", - "NonAtomicToAtomic", - "CopyAndAutoreleaseBlockObject", - "BuiltinFnToFnPtr", - "ZeroToOCLOpaqueType", - "AddressSpaceConversion", - "IntToOCLSampler", -}; - -extern const std::string clava::BINARY_OPERATOR_KIND[] = { - "PtrMemD", - "PtrMemI", - "Mul", - "Div", - "Rem", - "Add", - "Sub", - "Shl", - "Shr", - "Cmp", - "LT", - "GT", - "LE", - "GE", - "EQ", - "NE", - "And", - "Xor", - "Or", - "LAnd", - "LOr", - "Assign", - "MulAssign", - "DivAssign", - "RemAssign", - "AddAssign", - "SubAssign", - "ShlAssign", - "ShrAssign", - "AndAssign", - "XorAssign", - "OrAssign", - "Comma", -}; - -extern const std::string clava::UNARY_OPERATOR_KIND[] = { - "PostInc", - "PostDec", - "PreInc", - "PreDec", - "AddrOf", - "Deref", - "Plus", - "Minus", - "Not", - "LNot", - "Real", - "Imag", - "Extension", - "Coawait", -}; - diff --git a/ClangAstDumper/src/enums_Specifiers_h.cpp b/ClangAstDumper/src/enums_Specifiers_h.cpp deleted file mode 100644 index 4c5003a27..000000000 --- a/ClangAstDumper/src/enums_Specifiers_h.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "ClangEnums.h" - -extern const std::string clava::CALLING_CONVENTION[] = { - "C", - "X86StdCall", - "X86FastCall", - "X86ThisCall", - "X86VectorCall", - "X86Pascal", - "Win64", - "X86_64SysV", - "X86RegCall", - "AAPCS", - "AAPCS_VFP", - "IntelOclBicc", - "SpirFunction", - "OpenCLKernel", - "Swift", - "SwiftAsync", - "PreserveMost", - "PreserveAll", - "AArch64VectorCall", - "AArch64SVEPCS", - "AMDGPUKernelCall", -}; - -extern const std::string clava::ACCESS_SPECIFIER[] = { - "PUBLIC", - "PROTECTED", - "PRIVATE", - "NONE", -}; - -extern const std::string clava::STORAGE_CLASS[] = { - "None", - "Extern", - "Static", - "PrivateExtern", - "Auto", - "Register", -}; - -extern const std::string clava::EXPLICIT_SPEC_KIND[] = { - "ResolvedFalse", - "ResolvedTrue", - "Unresolved", -}; - -extern const std::string clava::TEMPLATE_SPECIALIZATION_KIND[] = { - "Undeclared", - "ImplicitInstantiation", - "ExplicitSpecialization", - "ExplicitInstantiationDeclaration", - "ExplicitInstantiationDefinition", -}; - diff --git a/ClangAstDumper/src/enums_TemplateBase_h.cpp b/ClangAstDumper/src/enums_TemplateBase_h.cpp deleted file mode 100644 index ab9412355..000000000 --- a/ClangAstDumper/src/enums_TemplateBase_h.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "ClangEnums.h" - -extern const std::string clava::TEMPLATE_ARG_KIND[] = { - "Null", - "Type", - "Declaration", - "NullPtr", - "Integral", - "Template", - "TemplateExpansion", - "Expression", - "Pack", -}; - diff --git a/ClangAstDumper/src/enums_TemplateName_h.cpp b/ClangAstDumper/src/enums_TemplateName_h.cpp deleted file mode 100644 index d184dd6fb..000000000 --- a/ClangAstDumper/src/enums_TemplateName_h.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "ClangEnums.h" - -extern const std::string clava::TEMPLATE_NAME_KIND[] = { - "Template", - "OverloadedTemplate", - "AssumedTemplate", - "QualifiedTemplate", - "DependentTemplate", - "SubstTemplateTemplateParm", - "SubstTemplateTemplateParmPack", - "UsingTemplate", -}; - diff --git a/ClangAstDumper/src/enums_TypeTraits_h.cpp b/ClangAstDumper/src/enums_TypeTraits_h.cpp deleted file mode 100644 index 2b8bda141..000000000 --- a/ClangAstDumper/src/enums_TypeTraits_h.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "ClangEnums.h" - -extern const std::string clava::UETT_KIND[] = { - "SizeOf", - "AlignOf", - "PreferredAlignOf", - "VecStep", - "OpenMPRequiredSimdAlign", -}; - diff --git a/ClangAstDumper/src/enums_Type_h.cpp b/ClangAstDumper/src/enums_Type_h.cpp deleted file mode 100644 index b00e7d182..000000000 --- a/ClangAstDumper/src/enums_Type_h.cpp +++ /dev/null @@ -1,277 +0,0 @@ -#include "ClangEnums.h" - -extern const std::string clava::BUILTIN_KIND[] = { - "OCLImage1dRO", - "OCLImage1dArrayRO", - "OCLImage1dBufferRO", - "OCLImage2dRO", - "OCLImage2dArrayRO", - "OCLImage2dDepthRO", - "OCLImage2dArrayDepthRO", - "OCLImage2dMSAARO", - "OCLImage2dArrayMSAARO", - "OCLImage2dMSAADepthRO", - "OCLImage2dArrayMSAADepthRO", - "OCLImage3dRO", - "OCLImage1dWO", - "OCLImage1dArrayWO", - "OCLImage1dBufferWO", - "OCLImage2dWO", - "OCLImage2dArrayWO", - "OCLImage2dDepthWO", - "OCLImage2dArrayDepthWO", - "OCLImage2dMSAAWO", - "OCLImage2dArrayMSAAWO", - "OCLImage2dMSAADepthWO", - "OCLImage2dArrayMSAADepthWO", - "OCLImage3dWO", - "OCLImage1dRW", - "OCLImage1dArrayRW", - "OCLImage1dBufferRW", - "OCLImage2dRW", - "OCLImage2dArrayRW", - "OCLImage2dDepthRW", - "OCLImage2dArrayDepthRW", - "OCLImage2dMSAARW", - "OCLImage2dArrayMSAARW", - "OCLImage2dMSAADepthRW", - "OCLImage2dArrayMSAADepthRW", - "OCLImage3dRW", - "OCLIntelSubgroupAVCMcePayload", - "OCLIntelSubgroupAVCImePayload", - "OCLIntelSubgroupAVCRefPayload", - "OCLIntelSubgroupAVCSicPayload", - "OCLIntelSubgroupAVCMceResult", - "OCLIntelSubgroupAVCImeResult", - "OCLIntelSubgroupAVCRefResult", - "OCLIntelSubgroupAVCSicResult", - "OCLIntelSubgroupAVCImeResultSingleRefStreamout", - "OCLIntelSubgroupAVCImeResultDualRefStreamout", - "OCLIntelSubgroupAVCImeSingleRefStreamin", - "OCLIntelSubgroupAVCImeDualRefStreamin", - "SveInt8", - "SveInt16", - "SveInt32", - "SveInt64", - "SveUint8", - "SveUint16", - "SveUint32", - "SveUint64", - "SveFloat16", - "SveFloat32", - "SveFloat64", - "SveBFloat16", - "SveInt8x2", - "SveInt16x2", - "SveInt32x2", - "SveInt64x2", - "SveUint8x2", - "SveUint16x2", - "SveUint32x2", - "SveUint64x2", - "SveFloat16x2", - "SveFloat32x2", - "SveFloat64x2", - "SveBFloat16x2", - "SveInt8x3", - "SveInt16x3", - "SveInt32x3", - "SveInt64x3", - "SveUint8x3", - "SveUint16x3", - "SveUint32x3", - "SveUint64x3", - "SveFloat16x3", - "SveFloat32x3", - "SveFloat64x3", - "SveBFloat16x3", - "SveInt8x4", - "SveInt16x4", - "SveInt32x4", - "SveInt64x4", - "SveUint8x4", - "SveUint16x4", - "SveUint32x4", - "SveUint64x4", - "SveFloat16x4", - "SveFloat32x4", - "SveFloat64x4", - "SveBFloat16x4", - "SveBool", - "VectorQuad", - "VectorPair", - "RvvInt8mf8", - "RvvInt8mf4", - "RvvInt8mf2", - "RvvInt8m1", - "RvvInt8m2", - "RvvInt8m4", - "RvvInt8m8", - "RvvUint8mf8", - "RvvUint8mf4", - "RvvUint8mf2", - "RvvUint8m1", - "RvvUint8m2", - "RvvUint8m4", - "RvvUint8m8", - "RvvInt16mf4", - "RvvInt16mf2", - "RvvInt16m1", - "RvvInt16m2", - "RvvInt16m4", - "RvvInt16m8", - "RvvUint16mf4", - "RvvUint16mf2", - "RvvUint16m1", - "RvvUint16m2", - "RvvUint16m4", - "RvvUint16m8", - "RvvInt32mf2", - "RvvInt32m1", - "RvvInt32m2", - "RvvInt32m4", - "RvvInt32m8", - "RvvUint32mf2", - "RvvUint32m1", - "RvvUint32m2", - "RvvUint32m4", - "RvvUint32m8", - "RvvInt64m1", - "RvvInt64m2", - "RvvInt64m4", - "RvvInt64m8", - "RvvUint64m1", - "RvvUint64m2", - "RvvUint64m4", - "RvvUint64m8", - "RvvFloat16mf4", - "RvvFloat16mf2", - "RvvFloat16m1", - "RvvFloat16m2", - "RvvFloat16m4", - "RvvFloat16m8", - "RvvFloat32mf2", - "RvvFloat32m1", - "RvvFloat32m2", - "RvvFloat32m4", - "RvvFloat32m8", - "RvvFloat64m1", - "RvvFloat64m2", - "RvvFloat64m4", - "RvvFloat64m8", - "RvvBool1", - "RvvBool2", - "RvvBool4", - "RvvBool8", - "RvvBool16", - "RvvBool32", - "RvvBool64", - "Void", - "Bool", - "Char_U", - "UChar", - "WChar_U", - "Char8", - "Char16", - "Char32", - "UShort", - "UInt", - "ULong", - "ULongLong", - "UInt128", - "Char_S", - "SChar", - "WChar_S", - "Short", - "Int", - "Long", - "LongLong", - "Int128", - "ShortAccum", - "Accum", - "LongAccum", - "UShortAccum", - "UAccum", - "ULongAccum", - "ShortFract", - "Fract", - "LongFract", - "UShortFract", - "UFract", - "ULongFract", - "SatShortAccum", - "SatAccum", - "SatLongAccum", - "SatUShortAccum", - "SatUAccum", - "SatULongAccum", - "SatShortFract", - "SatFract", - "SatLongFract", - "SatUShortFract", - "SatUFract", - "SatULongFract", - "Half", - "Float", - "Double", - "LongDouble", - "Float16", - "BFloat16", - "Float128", - "Ibm128", - "NullPtr", - "ObjCId", - "ObjCClass", - "ObjCSel", - "OCLSampler", - "OCLEvent", - "OCLClkEvent", - "OCLQueue", - "OCLReserveID", - "Dependent", - "Overload", - "BoundMember", - "PseudoObject", - "UnknownAny", - "BuiltinFn", - "ARCUnbridgedCast", - "IncompleteMatrixIdx", - "OMPArraySection", - "OMPArrayShaping", - "OMPIterator", -}; - -extern const std::string clava::REFERENCE_QUALIFIER[] = { - "None", - "LValue", - "RValue", -}; - -extern const std::string clava::ARRAY_SIZE_MODIFIER[] = { - "Normal", - "Static", - "Star", -}; - -extern const std::string clava::UTT_KIND[] = { - "EnumUnderlyingType", -}; - -extern const std::string clava::ELABORATED_TYPE_KEYWORD[] = { - "Struct", - "Interface", - "Union", - "Class", - "Enum", - "Typename", - "None", -}; - -extern const std::string clava::TAG_KIND[] = { - "Struct", - "Interface", - "Union", - "Class", - "Enum", -}; - diff --git a/ClangAstDumper/src/enums_Visibility_h.cpp b/ClangAstDumper/src/enums_Visibility_h.cpp deleted file mode 100644 index cede92ecc..000000000 --- a/ClangAstDumper/src/enums_Visibility_h.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "ClangEnums.h" - -extern const std::string clava::VISIBILITY[] = { - "Hidden", - "Protected", - "Default", -}; - diff --git a/ClangAstDumper/src/newmain.cpp b/ClangAstDumper/src/plugin.cpp similarity index 90% rename from ClangAstDumper/src/newmain.cpp rename to ClangAstDumper/src/plugin.cpp index 9ba8f2fd1..425293817 100644 --- a/ClangAstDumper/src/newmain.cpp +++ b/ClangAstDumper/src/plugin.cpp @@ -5,7 +5,7 @@ #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendPluginRegistry.h" -#include "ClangAst.h" +#include "Clang/ClangAst.h" using namespace clang; @@ -18,9 +18,8 @@ class MyASTVisitor : public RecursiveASTVisitor { explicit MyASTVisitor(ASTContext *context) : context_(context) {} bool VisitCallExpr(CallExpr *call) { - FunctionDecl *funcDecl = call->getDirectCallee(); - if (funcDecl && funcDecl->getNameAsString() == "myFunction") { - SourceManager &SM = context_->getSourceManager(); + if (FunctionDecl const *funcDecl = call->getDirectCallee(); funcDecl && funcDecl->getNameAsString() == "myFunction") { + SourceManager const &SM = context_->getSourceManager(); SourceLocation loc = call->getBeginLoc(); llvm::outs() << "Found call to myFunction at " << SM.getFilename(loc) << ":" diff --git a/ClangAstDumper/src/main.cpp b/ClangAstDumper/src/standalone.cpp similarity index 100% rename from ClangAstDumper/src/main.cpp rename to ClangAstDumper/src/standalone.cpp From 660ed7b440aed7133f12b8d2ba9846a7cf826d7e Mon Sep 17 00:00:00 2001 From: "L. Sousa" Date: Thu, 2 May 2024 20:49:46 +0100 Subject: [PATCH 41/68] Remove commented code from source files --- .../ChildrenVisitor/ChildrenVisitorAttrs.cpp | 41 +- .../ChildrenVisitor/ChildrenVisitorDecls.cpp | 581 ++++------- .../ChildrenVisitor/ChildrenVisitorExtras.cpp | 134 +-- .../ChildrenVisitor/ChildrenVisitorStmts.cpp | 617 ++++++------ .../ChildrenVisitor/ChildrenVisitorTypes.cpp | 393 ++++---- ClangAstDumper/src/Clang/ClangAst.cpp | 533 +++++----- ClangAstDumper/src/Clang/ClangAst.h | 16 - ClangAstDumper/src/Clang/ClangNodes.cpp | 610 +++++------- ClangAstDumper/src/Clang/ClangNodes.h | 269 +++-- .../src/ClangAstDumper/ClangAstDumper.cpp | 818 ++++++--------- .../src/ClangAstDumper/ClangAstDumper.h | 675 ++++++------- .../src/ClangAstDumper/ClangAstDumperAttr.cpp | 58 +- .../ClangAstDumper/ClangAstDumperConstants.h | 33 +- .../ClangAstDumper/ClangAstDumperDecls.cpp | 392 +------- .../ClangAstDumper/ClangAstDumperExprs.cpp | 347 +------ .../ClangAstDumper/ClangAstDumperExtra.cpp | 1 - .../ClangAstDumper/ClangAstDumperStmts.cpp | 152 +-- .../ClangAstDumper/ClangAstDumperTypes.cpp | 173 +--- ClangAstDumper/src/ClangEnums/ClangEnums.cpp | 120 +-- ClangAstDumper/src/ClangEnums/ClangEnums.h | 78 +- ClangAstDumper/src/Clava/ClavaConstants.cpp | 379 ++++--- ClangAstDumper/src/Clava/ClavaConstants.h | 283 +++--- ClangAstDumper/src/Clava/ClavaDecl.cpp | 136 ++- ClangAstDumper/src/Clava/ClavaDecl.h | 97 +- .../src/ClavaDataDumper/ClavaDataDumper.cpp | 113 +-- .../src/ClavaDataDumper/ClavaDataDumper.h | 407 ++++---- .../ClavaDataDumper/ClavaDataDumperAttrs.cpp | 95 +- .../ClavaDataDumper/ClavaDataDumperDecls.cpp | 626 +++++------- .../ClavaDataDumper/ClavaDataDumperStmts.cpp | 760 ++++++-------- .../ClavaDataDumper/ClavaDataDumperTypes.cpp | 932 ++++++++---------- ClangAstDumper/src/TypeMarker/TypeMarker.cpp | 13 +- ClangAstDumper/src/TypeMarker/TypeMarker.h | 8 +- ClangAstDumper/src/plugin.cpp | 3 +- ClangAstDumper/src/standalone.cpp | 57 +- 34 files changed, 3967 insertions(+), 5983 deletions(-) diff --git a/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorAttrs.cpp b/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorAttrs.cpp index 17507af2c..46f663b7b 100644 --- a/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorAttrs.cpp +++ b/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorAttrs.cpp @@ -2,58 +2,55 @@ // Created by JoaoBispo on 12/04/2018. // -#include "../ClangAstDumper/ClangAstDumper.h" #include "../Clang/ClangNodes.h" +#include "../ClangAstDumper/ClangAstDumper.h" #include "../Clava/ClavaDecl.h" #include -const std::map ClangAstDumper::ATTR_CHILDREN_MAP = { +const std::map + ClangAstDumper::ATTR_CHILDREN_MAP = { {"AlignedAttr", clava::AttrNode::ALIGNED} }; -void ClangAstDumper::visitChildren(const Attr* A) { +void ClangAstDumper::visitChildren(const Attr *A) { // Get classname const std::string classname = clava::getClassName(A); // Get corresponding Attribute - clava::AttrNode attrNode = ATTR_CHILDREN_MAP.count(classname) == 1 ? ATTR_CHILDREN_MAP.find(classname)->second : - clava::AttrNode::ATTR; + clava::AttrNode attrNode = ATTR_CHILDREN_MAP.count(classname) == 1 + ? ATTR_CHILDREN_MAP.find(classname)->second + : clava::AttrNode::ATTR; visitChildren(attrNode, A); } -void ClangAstDumper::visitChildren(clava::AttrNode attrNode, const Attr* A) { +void ClangAstDumper::visitChildren(clava::AttrNode attrNode, const Attr *A) { std::vector visitedChildren; - switch(attrNode) { - //case clava::AttrNode::ATTR: - // By default, do nothing - // break; - case clava::AttrNode::ALIGNED: - VisitAlignedAttrChildren(static_cast(A), visitedChildren); break; -// default: throw std::invalid_argument("ChildrenVisitorAttrs::visitChildren: Case not implemented, '"+clava::getName(attrNode)+"'"); - default: - // By default, do nothing - break; + switch (attrNode) { + case clava::AttrNode::ALIGNED: + VisitAlignedAttrChildren(static_cast(A), + visitedChildren); + break; + default: + // By default, do nothing + break; } dumpVisitedChildren(A, visitedChildren); } -void ClangAstDumper::VisitAlignedAttrChildren(const AlignedAttr * A, std::vector &children) { +void ClangAstDumper::VisitAlignedAttrChildren( + const AlignedAttr *A, std::vector &children) { // No hierarchy - if(A->isAlignmentExpr()) { + if (A->isAlignmentExpr()) { addChild(A->getAlignmentExpr(), children); - //VisitStmtTop(A->getAlignmentExpr()); - //children.push_back(clava::getId(A->getAlignmentExpr(), id)); } else { VisitTypeTop(A->getAlignmentType()->getType()); dumpTopLevelType(A->getAlignmentType()->getType()); } - } - diff --git a/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorDecls.cpp b/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorDecls.cpp index 56198b5fd..cdbd57174 100644 --- a/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorDecls.cpp +++ b/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorDecls.cpp @@ -2,15 +2,15 @@ // Created by JoaoBispo on 20/03/2018. // -#include "../ClangAstDumper/ClangAstDumper.h" #include "../Clang/ClangNodes.h" +#include "../ClangAstDumper/ClangAstDumper.h" #include "../ClangEnums/ClangEnums.h" #include "../Clava/ClavaConstants.h" #include - -const std::map ClangAstDumper::DECL_CHILDREN_MAP = { +const std::map + ClangAstDumper::DECL_CHILDREN_MAP = { {"CXXConstructorDecl", clava::DeclNode::CXX_CONSTRUCTOR_DECL}, {"CXXConversionDecl", clava::DeclNode::CXX_CONVERSION_DECL}, {"CXXDestructorDecl", clava::DeclNode::CXX_METHOD_DECL}, @@ -18,8 +18,10 @@ const std::map ClangAstDumper::DECL_CHILDRE {"EnumDecl", clava::DeclNode::ENUM_DECL}, {"RecordDecl", clava::DeclNode::RECORD_DECL}, {"CXXRecordDecl", clava::DeclNode::CXX_RECORD_DECL}, - {"ClassTemplateSpecializationDecl", clava::DeclNode::CLASS_TEMPLATE_SPECIALIZATION_DECL}, - {"ClassTemplatePartialSpecializationDecl", clava::DeclNode::CLASS_TEMPLATE_SPECIALIZATION_DECL}, + {"ClassTemplateSpecializationDecl", + clava::DeclNode::CLASS_TEMPLATE_SPECIALIZATION_DECL}, + {"ClassTemplatePartialSpecializationDecl", + clava::DeclNode::CLASS_TEMPLATE_SPECIALIZATION_DECL}, {"FunctionDecl", clava::DeclNode::FUNCTION_DECL}, {"VarDecl", clava::DeclNode::VAR_DECL}, {"ParmVarDecl", clava::DeclNode::VAR_DECL}, @@ -29,7 +31,8 @@ const std::map ClangAstDumper::DECL_CHILDRE {"FunctionTemplateDecl", clava::DeclNode::TEMPLATE_DECL}, {"TypeAliasTemplateDecl", clava::DeclNode::TEMPLATE_DECL}, {"VarTemplateDecl", clava::DeclNode::TEMPLATE_DECL}, - {"TemplateTemplateParmDecl", clava::DeclNode::TEMPLATE_TEMPLATE_PARM_DECL}, + {"TemplateTemplateParmDecl", + clava::DeclNode::TEMPLATE_TEMPLATE_PARM_DECL}, {"TemplateTypeParmDecl", clava::DeclNode::TEMPLATE_TYPE_PARM_DECL}, {"EnumConstantDecl", clava::DeclNode::ENUM_CONSTANT_DECL}, {"TypeAliasDecl", clava::DeclNode::TYPEDEF_NAME_DECL}, @@ -40,256 +43,205 @@ const std::map ClangAstDumper::DECL_CHILDRE {"NamespaceAliasDecl", clava::DeclNode::NAMESPACE_ALIAS_DECL}, {"LinkageSpecDecl", clava::DeclNode::LINKAGE_SPEC_DECL}, {"StaticAssertDecl", clava::DeclNode::STATIC_ASSERT_DECL}, - {"NonTypeTemplateParmDecl", clava::DeclNode::NON_TYPE_TEMPLATE_PARM_DECL}, + {"NonTypeTemplateParmDecl", + clava::DeclNode::NON_TYPE_TEMPLATE_PARM_DECL}, // TODO: Check if needs more data to dump {"VarTemplateSpecializationDecl", clava::DeclNode::VAR_DECL}, {"UsingDecl", clava::DeclNode::USING_DECL}, }; - -void ClangAstDumper::visitChildren(const Decl* D) { +void ClangAstDumper::visitChildren(const Decl *D) { // Get classname const std::string classname = clava::getClassName(D); // Get corresponding DeclNode - clava::DeclNode declNode = DECL_CHILDREN_MAP.count(classname) == 1 ? DECL_CHILDREN_MAP.find(classname)->second : - clava::DeclNode::DECL; + clava::DeclNode declNode = DECL_CHILDREN_MAP.count(classname) == 1 + ? DECL_CHILDREN_MAP.find(classname)->second + : clava::DeclNode::DECL; visitChildren(declNode, D); } - -void ClangAstDumper::visitChildren(clava::DeclNode declNode, const Decl* D) { +void ClangAstDumper::visitChildren(clava::DeclNode declNode, const Decl *D) { std::vector visitedChildren; - switch(declNode) { - case clava::DeclNode::DECL: - VisitDeclChildren(D, visitedChildren); break; - case clava::DeclNode::NAMED_DECL: - VisitNamedDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::TYPE_DECL: - VisitTypeDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::TAG_DECL: - VisitTagDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::ENUM_DECL: - VisitEnumDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::RECORD_DECL: - VisitRecordDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::VALUE_DECL: - VisitValueDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::FIELD_DECL: - VisitFieldDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::FUNCTION_DECL: - VisitFunctionDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::CXX_METHOD_DECL: - VisitCXXMethodDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::CXX_CONSTRUCTOR_DECL: - VisitCXXConstructorDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::CXX_CONVERSION_DECL: - VisitCXXConversionDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::CXX_RECORD_DECL: - VisitCXXRecordDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::CLASS_TEMPLATE_SPECIALIZATION_DECL: - VisitClassTemplateSpecializationDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::VAR_DECL: - VisitVarDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::TEMPLATE_DECL: - VisitTemplateDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::TEMPLATE_TEMPLATE_PARM_DECL: - VisitTemplateTemplateParmDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::TEMPLATE_TYPE_PARM_DECL: - VisitTemplateTypeParmDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::ENUM_CONSTANT_DECL: - VisitEnumConstantDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::TYPEDEF_NAME_DECL: - VisitTypedefNameDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::USING_DIRECTIVE_DECL: - VisitUsingDirectiveDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::NAMESPACE_DECL: - VisitNamespaceDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::FRIEND_DECL: - VisitFriendDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::NAMESPACE_ALIAS_DECL: - VisitNamespaceAliasDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::LINKAGE_SPEC_DECL: - VisitLinkageSpecDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::STATIC_ASSERT_DECL: - VisitStaticAssertDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::NON_TYPE_TEMPLATE_PARM_DECL: - VisitNonTypeTemplateParmDeclChildren(static_cast(D), visitedChildren); break; - case clava::DeclNode::USING_DECL: - VisitUsingDeclChildren(static_cast(D), visitedChildren); break; - - - // case clava::DeclNode::PARM_VAR_DECL: -// visitedChildren = VisitParmVarDeclChildren(static_cast(D)); break; - default: throw std::invalid_argument("ChildrenVisitorDecls::visitChildren: Case not implemented, '"+clava::getName(declNode)+"'"); + switch (declNode) { + case clava::DeclNode::DECL: + VisitDeclChildren(D, visitedChildren); + break; + case clava::DeclNode::NAMED_DECL: + VisitNamedDeclChildren(static_cast(D), + visitedChildren); + break; + case clava::DeclNode::TYPE_DECL: + VisitTypeDeclChildren(static_cast(D), + visitedChildren); + break; + case clava::DeclNode::TAG_DECL: + VisitTagDeclChildren(static_cast(D), visitedChildren); + break; + case clava::DeclNode::ENUM_DECL: + VisitEnumDeclChildren(static_cast(D), + visitedChildren); + break; + case clava::DeclNode::RECORD_DECL: + VisitRecordDeclChildren(static_cast(D), + visitedChildren); + break; + case clava::DeclNode::VALUE_DECL: + VisitValueDeclChildren(static_cast(D), + visitedChildren); + break; + case clava::DeclNode::FIELD_DECL: + VisitFieldDeclChildren(static_cast(D), + visitedChildren); + break; + case clava::DeclNode::FUNCTION_DECL: + VisitFunctionDeclChildren(static_cast(D), + visitedChildren); + break; + case clava::DeclNode::CXX_METHOD_DECL: + VisitCXXMethodDeclChildren(static_cast(D), + visitedChildren); + break; + case clava::DeclNode::CXX_CONSTRUCTOR_DECL: + VisitCXXConstructorDeclChildren( + static_cast(D), visitedChildren); + break; + case clava::DeclNode::CXX_CONVERSION_DECL: + VisitCXXConversionDeclChildren( + static_cast(D), visitedChildren); + break; + case clava::DeclNode::CXX_RECORD_DECL: + VisitCXXRecordDeclChildren(static_cast(D), + visitedChildren); + break; + case clava::DeclNode::CLASS_TEMPLATE_SPECIALIZATION_DECL: + VisitClassTemplateSpecializationDeclChildren( + static_cast(D), + visitedChildren); + break; + case clava::DeclNode::VAR_DECL: + VisitVarDeclChildren(static_cast(D), visitedChildren); + break; + case clava::DeclNode::TEMPLATE_DECL: + VisitTemplateDeclChildren(static_cast(D), + visitedChildren); + break; + case clava::DeclNode::TEMPLATE_TEMPLATE_PARM_DECL: + VisitTemplateTemplateParmDeclChildren( + static_cast(D), visitedChildren); + break; + case clava::DeclNode::TEMPLATE_TYPE_PARM_DECL: + VisitTemplateTypeParmDeclChildren( + static_cast(D), visitedChildren); + break; + case clava::DeclNode::ENUM_CONSTANT_DECL: + VisitEnumConstantDeclChildren(static_cast(D), + visitedChildren); + break; + case clava::DeclNode::TYPEDEF_NAME_DECL: + VisitTypedefNameDeclChildren(static_cast(D), + visitedChildren); + break; + case clava::DeclNode::USING_DIRECTIVE_DECL: + VisitUsingDirectiveDeclChildren( + static_cast(D), visitedChildren); + break; + case clava::DeclNode::NAMESPACE_DECL: + VisitNamespaceDeclChildren(static_cast(D), + visitedChildren); + break; + case clava::DeclNode::FRIEND_DECL: + VisitFriendDeclChildren(static_cast(D), + visitedChildren); + break; + case clava::DeclNode::NAMESPACE_ALIAS_DECL: + VisitNamespaceAliasDeclChildren( + static_cast(D), visitedChildren); + break; + case clava::DeclNode::LINKAGE_SPEC_DECL: + VisitLinkageSpecDeclChildren(static_cast(D), + visitedChildren); + break; + case clava::DeclNode::STATIC_ASSERT_DECL: + VisitStaticAssertDeclChildren(static_cast(D), + visitedChildren); + break; + case clava::DeclNode::NON_TYPE_TEMPLATE_PARM_DECL: + VisitNonTypeTemplateParmDeclChildren( + static_cast(D), visitedChildren); + break; + case clava::DeclNode::USING_DECL: + VisitUsingDeclChildren(static_cast(D), + visitedChildren); + break; + default: + throw std::invalid_argument( + "ChildrenVisitorDecls::visitChildren: Case not implemented, '" + + clava::getName(declNode) + "'"); } dumpVisitedChildren(D, visitedChildren); } - -void ClangAstDumper::VisitDeclChildren(const Decl *D, std::vector &children) { +void ClangAstDumper::VisitDeclChildren(const Decl *D, + std::vector &children) { // Visit attributes for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E; ++I) { - Attr* attr = *I; + const Attr *attr = *I; VisitAttrTop(attr); dumpTopLevelAttr(attr); } - - /* - if(D->getDeclContext() != nullptr) { - VisitDeclTop(cast(D->getDeclContext())); - } - */ - - - // Visit decls in DeclContext - /* - for (auto I = D->getDeclContext()->decls().begin(), E = D->getDeclContext()->decls().end(); I != E; - ++I) { - Decl* decl = *I; - VisitDeclTop(decl); - //dumpTopLevelDecl(decl); - } - */ - - - - /* - // Visit decls - //DeclContext::decl_range - if (auto decls = dyn_cast(D)) { - - for (auto decl = decls->begin(), endDecl = decls->end(); decl != endDecl; ++decl) { - - -// for (auto decl : decls->decl) { - // If CXXRecordDecl without definition, skip - if (const CXXRecordDecl *recordDecl = dyn_cast(*decl)) { - if (!recordDecl->hasDefinition()) { - continue; - } - } - - if (*decl == nullptr) { - continue; - } - - - addChild(*decl, children); - } - } -*/ - - } -void ClangAstDumper::VisitNamedDeclChildren(const NamedDecl *D, std::vector &children) { +void ClangAstDumper::VisitNamedDeclChildren( + const NamedDecl *D, std::vector &children) { // Hierarchy VisitDeclChildren(D, children); - - // Just visit underlying decl - //VisitDeclTop(D->getUnderlyingDecl()); - //llvm::errs() << "VISITING " << clava::getId(D->getUnderlyingDecl(), id) << " -> " << clava::getClassName(D->getUnderlyingDecl()) << "\n"; - //llvm::errs() << "ORIGINAL " << clava::getId(D, id) << "\n"; } -void ClangAstDumper::VisitTypeDeclChildren(const TypeDecl *D, std::vector &children) { +void ClangAstDumper::VisitTypeDeclChildren(const TypeDecl *D, + std::vector &children) { // Hierarchy VisitNamedDeclChildren(D, children); // Visit type VisitTypeTop(D->getTypeForDecl()); dumpType(D->getTypeForDecl()); - } -void ClangAstDumper::VisitTagDeclChildren(const TagDecl *D, std::vector &children) { +void ClangAstDumper::VisitTagDeclChildren(const TagDecl *D, + std::vector &children) { // Hierarchy VisitTypeDeclChildren(D, children); - //std::string cxxRecordName = "CXXRecord"; - - //for (auto I = D->getFirstDecl(), E = D->getDecl; I != E; ++I) { - //llvm::errs() << "TagDecl id: " << clava::getId(D, id) << "\n"; - //int declCounter = 0; -//DeclContext::decl_range - addChildren(D->decls(), children); -/* - for(auto decl : D->decls()) { - //for(auto decl : D->noload_decls()) { - // If CXXRecordDecl without definition, skip - if (const CXXRecordDecl *recordDecl = dyn_cast(decl)) { - if(!recordDecl->hasDefinition()) { - continue; - } - } - - if(decl == nullptr) { - continue; - } - - - //VisitDecl(decl); - addChild(decl, children); - //VisitDeclTop(decl); - //children.push_back(clava::getId(decl, id)); - - // Skip if the first child, and if current TagDecl is a CXXRecord, and - - //llvm::errs() << "TagDecl child: " << decl->getDeclKindName() << " " << clava::getId(decl, id) << "\n"; - - - //if(cxxRecordName.compare(decl->getDeclKindName()) == 0) { - // llvm::errs() << "Is record\n"; - // llvm::errs() << "Has def? " << static_cast(decl)->hasDefinition() << "\n"; - //} - //VisitDeclTop(decl); - //children.push_back(clava::getId(decl, id)); - //declCounter++; - } -*/ - - - /* - for(auto decl : D->noload_decls()) { - llvm::errs() << "No load TagDecl child: " << decl->getDeclKindName() << " " << clava::getId(decl, id) << "\n"; - - //VisitDeclTop(decl); - //children.push_back(clava::getId(decl, id)); - } - */ - } - -void ClangAstDumper::VisitEnumDeclChildren(const EnumDecl *D, std::vector &children) { +void ClangAstDumper::VisitEnumDeclChildren(const EnumDecl *D, + std::vector &children) { // Hierarchy VisitTagDeclChildren(D, children); // Visit type VisitTypeTop(D->getIntegerType()); - //dumpTopLevelType(D->getType()); - - } -void ClangAstDumper::VisitValueDeclChildren(const ValueDecl *D, std::vector &children) { +void ClangAstDumper::VisitValueDeclChildren( + const ValueDecl *D, std::vector &children) { // Hierarchy VisitNamedDeclChildren(D, children); // Visit type VisitTypeTop(D->getType()); dumpTopLevelType(D->getType()); - } -void ClangAstDumper::VisitFieldDeclChildren(const FieldDecl *D, std::vector &children) { +void ClangAstDumper::VisitFieldDeclChildren( + const FieldDecl *D, std::vector &children) { // Hierarchy VisitValueDeclChildren(D, children); @@ -300,7 +252,8 @@ void ClangAstDumper::VisitFieldDeclChildren(const FieldDecl *D, std::vectorgetInClassInitializer(), children); } -void ClangAstDumper::VisitFunctionDeclChildren(const FunctionDecl *D, std::vector &children) { +void ClangAstDumper::VisitFunctionDeclChildren( + const FunctionDecl *D, std::vector &children) { // Hierarchy VisitValueDeclChildren(D, children); @@ -309,89 +262,58 @@ void ClangAstDumper::VisitFunctionDeclChildren(const FunctionDecl *D, std::vecto VisitDeclTop(D->getPreviousDecl()); VisitDeclTop(D->getCanonicalDecl()); - FunctionTemplateDecl* primaryTemplate = D->getPrimaryTemplate(); - if(primaryTemplate != nullptr) { + if (FunctionTemplateDecl const *primaryTemplate = D->getPrimaryTemplate(); + primaryTemplate != nullptr) { VisitDeclTop(primaryTemplate->getTemplatedDecl()); } // Visit template arguments - auto templateSpecializationArgs = D->getTemplateSpecializationArgs(); - if(templateSpecializationArgs != nullptr) { - for(auto templateArg : templateSpecializationArgs->asArray()) { + if (auto templateSpecializationArgs = D->getTemplateSpecializationArgs(); + templateSpecializationArgs != nullptr) { + for (auto const &templateArg : templateSpecializationArgs->asArray()) { VisitTemplateArgument(templateArg); } } - - //addChildren(D->decls(), children); - // Visit parameters - for(auto param : D->parameters()) { + for (auto param : D->parameters()) { addChild(param, children); - //VisitDeclTop(param); - //children.push_back(clava::getId(param, id)); } // Visit body - //if(D->hasBody()) { if (D->doesThisDeclarationHaveABody()) { - //llvm::errs() << "BODY: " << getId(D->getBody()) << "\n"; addChild(D->getBody(), children); - //VisitStmtTop(D->getBody()); - //children.push_back(clava::getId(D->getBody(), id)); - } - - /* -for (auto I = D->param_begin(), E = D->param_end(); I != E; ++I) { - llvm::errs() << "PARAM: " << getId(I) << "\n"; - llvm::errs() << "PARAM CLASS: " << clava::getClassName(I) << "\n"; - - VisitDeclTop(*I); - children.push_back(getId(I)); -} - */ - - // Visit decls in prototype scope -/* - for (ArrayRef::iterator I = D->getDeclsInPrototypeScope().begin(), - E = D->getDeclsInPrototypeScope().end(); I != E; ++I) { - - addChild(*I, children); - //VisitDeclTop(*I); - //children.push_back(clava::getId(*I, id)); } -*/ - } - -void ClangAstDumper::VisitCXXMethodDeclChildren(const CXXMethodDecl *D, std::vector &children) { +void ClangAstDumper::VisitCXXMethodDeclChildren( + const CXXMethodDecl *D, std::vector &children) { // Hierarchy VisitFunctionDeclChildren(D, children); - // Visit record decl VisitDeclTop(D->getParent()); // Visit overridden methods - for(auto overriddenMethod : D->overridden_methods()) { + for (auto overriddenMethod : D->overridden_methods()) { VisitDeclTop(overriddenMethod); } // Types related to "this" - if(D->isInstance()) { + if (D->isInstance()) { VisitTypeTop(D->getThisType()); VisitTypeTop(D->getThisObjectType()); } } -void ClangAstDumper::VisitCXXConstructorDeclChildren(const CXXConstructorDecl *D, std::vector &children) { +void ClangAstDumper::VisitCXXConstructorDeclChildren( + const CXXConstructorDecl *D, std::vector &children) { // Hierarchy VisitCXXMethodDeclChildren(D, children); - // Visit CXXCtorInitializers - for (auto init = D->init_begin(), init_last = D->init_end(); init != init_last; ++init) { + for (auto init = D->init_begin(), init_last = D->init_end(); + init != init_last; ++init) { // Init expr VisitStmtTop((*init)->getInit()); @@ -411,14 +333,16 @@ void ClangAstDumper::VisitCXXConstructorDeclChildren(const CXXConstructorDecl *D } throw std::invalid_argument( - "ClangDataDumper::VisitCXXConstructorDeclChildren():: CXXCtorInitializer case not implemented"); + "ClangDataDumper::VisitCXXConstructorDeclChildren():: " + "CXXCtorInitializer case not implemented"); } // Visit ExplicitSpecifier Expression VisitExpr(D->getExplicitSpecifier().getExpr()); } -void ClangAstDumper::VisitCXXConversionDeclChildren(const CXXConversionDecl *D, std::vector &children) { +void ClangAstDumper::VisitCXXConversionDeclChildren( + const CXXConversionDecl *D, std::vector &children) { // Hierarchy VisitCXXMethodDeclChildren(D, children); @@ -426,25 +350,14 @@ void ClangAstDumper::VisitCXXConversionDeclChildren(const CXXConversionDecl *D, VisitTypeTop(D->getConversionType()); } -void ClangAstDumper::VisitRecordDeclChildren(const RecordDecl *D, std::vector &children) { +void ClangAstDumper::VisitRecordDeclChildren( + const RecordDecl *D, std::vector &children) { // Hierarchy VisitTagDeclChildren(D, children); - - //D->decls_begin() - - // Visit fields - /* - for (auto field : D->fields()) { - addChild(field, children); - //VisitDeclTop(field); - //children.push_back(clava::getId(field, id)); - } -*/ - - } -void ClangAstDumper::VisitCXXRecordDeclChildren(const CXXRecordDecl *D, std::vector &children) { +void ClangAstDumper::VisitCXXRecordDeclChildren( + const CXXRecordDecl *D, std::vector &children) { // Hierarchy VisitRecordDeclChildren(D, children); @@ -455,118 +368,52 @@ void ClangAstDumper::VisitCXXRecordDeclChildren(const CXXRecordDecl *D, std::vec } VisitDeclTop(D->getDefinition()); } - - //llvm::errs() << "CXX RECORD HAS DEF: " << D->hasDefinition() << "\n"; - - - - /* - llvm::errs() << "CXXRECORDDECL CANONICAL: " << clava::getId(D->getCanonicalDecl(), id) << "\n"; - llvm::errs() << "CXXRECORDDECL PREVIOUS: " << clava::getId(D->getPreviousDecl(), id) << "\n"; - llvm::errs() << "CXXRECORDDECL MOST RECENT: " << clava::getId(D->getMostRecentDecl(), id) << "\n"; - llvm::errs() << "CXXRECORDDECL INSTANTIATED: " << clava::getId(D->getInstantiatedFromMemberClass(), id) << "\n"; - llvm::errs() << "CXXRECORDDECL TEMPLATE: " << clava::getId(D->getTemplateInstantiationPattern(), id) << "\n"; -*/ - - //llvm::errs() << "CXXRECORDDECL DEF: " << clava::getId(D->getDefinition(), id) << "\n"; - - // Visit constructors - /* - for (auto ctor : D->ctors()) { - VisitDeclTop(ctor); - children.push_back(clava::getId(ctor, id)); - } - */ - - - // Visit methods - // This makes the program explode -/* - for(auto method = D->method_begin(); method != D->method_end(); method++) { - VisitDeclTop(*method); - children.push_back(clava::getId(*method, id)); - } - */ -/* - for (auto method : D->methods()) { - VisitDeclTop(method); - children.push_back(clava::getId(method, id)); - } -*/ - - - } -void ClangAstDumper::VisitClassTemplateSpecializationDeclChildren(const ClassTemplateSpecializationDecl *D, std::vector &children) { +void ClangAstDumper::VisitClassTemplateSpecializationDeclChildren( + const ClassTemplateSpecializationDecl *D, + std::vector &children) { // Hierarchy VisitCXXRecordDeclChildren(D, children); VisitDeclTop(D->getSpecializedTemplate()); // Visit template arguments - auto& templateArgs = D->getTemplateArgs(); - //clava::dump(templateArgs.size()); - for (auto& templateArg : templateArgs.asArray()) { + auto &templateArgs = D->getTemplateArgs(); + for (auto &templateArg : templateArgs.asArray()) { VisitTemplateArgument(templateArg); } - } - - - -/* -void ClangAstDumper::VisitCXXConstructorDeclChildren(const CXXConstructorDecl *D) { - // Hierarchy - VisitFunctionDeclChildren(D); - - -} - */ - - -void ClangAstDumper::VisitVarDeclChildren(const VarDecl *D, std::vector &children) { +void ClangAstDumper::VisitVarDeclChildren(const VarDecl *D, + std::vector &children) { // Hierarchy VisitValueDeclChildren(D, children); if (D->hasInit()) { addChild(D->getInit(), children); - //VisitStmtTop(D->getInit()); - //children.push_back(clava::getId(D->getInit(), id)); } - } -/* -std::vector ClangAstDumper::VisitParmVarDeclChildren(const ParmVarDecl *D) { - - // Hierarchy - std::vector children = VisitVarDeclChildren(D); - //children.push_back(getId(D)); - - return children; -} - */ - -void ClangAstDumper::VisitTemplateDeclChildren(const TemplateDecl *D, std::vector &children) { +void ClangAstDumper::VisitTemplateDeclChildren( + const TemplateDecl *D, std::vector &children) { // Hierarchy VisitNamedDeclChildren(D, children); - auto templateParams = D->getTemplateParameters(); - if(templateParams) { - for (auto I = templateParams->begin(), E = templateParams->end(); I != E; ++I) { + if (auto templateParams = D->getTemplateParameters()) { + for (auto I = templateParams->begin(), E = templateParams->end(); + I != E; ++I) { addChild(*I, children); VisitDeclTop(*I); } - } addChild(D->getTemplatedDecl(), children); VisitDeclTop(D->getTemplatedDecl()); } -void ClangAstDumper::VisitTemplateTemplateParmDeclChildren(const TemplateTemplateParmDecl *D, std::vector &children) { +void ClangAstDumper::VisitTemplateTemplateParmDeclChildren( + const TemplateTemplateParmDecl *D, std::vector &children) { // Hierarchy VisitTemplateDeclChildren(D, children); @@ -575,21 +422,19 @@ void ClangAstDumper::VisitTemplateTemplateParmDeclChildren(const TemplateTemplat } } - - -void ClangAstDumper::VisitTemplateTypeParmDeclChildren(const TemplateTypeParmDecl *D, std::vector &children) { +void ClangAstDumper::VisitTemplateTypeParmDeclChildren( + const TemplateTypeParmDecl *D, std::vector &children) { // Hierarchy VisitTypeDeclChildren(D, children); - //addChild(D->getDefaultArgument(), children); - if(D->hasDefaultArgument()) { + if (D->hasDefaultArgument()) { VisitTypeTop(D->getDefaultArgument()); } - } -void ClangAstDumper::VisitEnumConstantDeclChildren(const EnumConstantDecl *D, std::vector &children) { +void ClangAstDumper::VisitEnumConstantDeclChildren( + const EnumConstantDecl *D, std::vector &children) { // Hierarchy VisitValueDeclChildren(D, children); @@ -597,7 +442,8 @@ void ClangAstDumper::VisitEnumConstantDeclChildren(const EnumConstantDecl *D, st addChild(D->getInitExpr(), children); } -void ClangAstDumper::VisitTypedefNameDeclChildren(const TypedefNameDecl *D, std::vector &children) { +void ClangAstDumper::VisitTypedefNameDeclChildren( + const TypedefNameDecl *D, std::vector &children) { // Hierarchy VisitTypeDeclChildren(D, children); @@ -605,7 +451,8 @@ void ClangAstDumper::VisitTypedefNameDeclChildren(const TypedefNameDecl *D, std: VisitTypeTop(D->getUnderlyingType()); } -void ClangAstDumper::VisitUsingDirectiveDeclChildren(const UsingDirectiveDecl *D, std::vector &children) { +void ClangAstDumper::VisitUsingDirectiveDeclChildren( + const UsingDirectiveDecl *D, std::vector &children) { // Hierarchy VisitNamedDeclChildren(D, children); @@ -614,36 +461,33 @@ void ClangAstDumper::VisitUsingDirectiveDeclChildren(const UsingDirectiveDecl *D VisitDeclTop(D->getNominatedNamespaceAsWritten()); } -void ClangAstDumper::VisitNamespaceDeclChildren(const NamespaceDecl *D, std::vector &children) { +void ClangAstDumper::VisitNamespaceDeclChildren( + const NamespaceDecl *D, std::vector &children) { // Hierarchy VisitNamedDeclChildren(D, children); addChildren(D->decls(), children); - - //llvm::errs() << "IS OROGINAL NAMESPACE? " << D->isOriginalNamespace() << "\n"; } -void ClangAstDumper::VisitFriendDeclChildren(const FriendDecl *D, std::vector &children) { +void ClangAstDumper::VisitFriendDeclChildren( + const FriendDecl *D, std::vector &children) { // Hierarchy VisitDeclChildren(D, children); - if(D->getFriendDecl() != nullptr) { + if (D->getFriendDecl() != nullptr) { addChild(D->getFriendDecl(), children); } else if (D->getFriendType() != nullptr) { addChild(D->getFriendType()->getType(), children); } else { // Add a null node - addChild((const Decl*) nullptr, children); + addChild((const Decl *)nullptr, children); } - - //addChildren(D->decls(), children); - - //llvm::errs() << "IS ORIGINAL NAMESPACE? " << D->isOriginalNamespace() << "\n"; } -void ClangAstDumper::VisitNamespaceAliasDeclChildren(const NamespaceAliasDecl *D, std::vector &children) { +void ClangAstDumper::VisitNamespaceAliasDeclChildren( + const NamespaceAliasDecl *D, std::vector &children) { // Hierarchy VisitNamedDeclChildren(D, children); @@ -651,24 +495,21 @@ void ClangAstDumper::VisitNamespaceAliasDeclChildren(const NamespaceAliasDecl *D VisitDeclTop(D->getAliasedNamespace()); } -void ClangAstDumper::VisitLinkageSpecDeclChildren(const LinkageSpecDecl *D, std::vector &children) { - - // Hierarchy - //VisitDeclChildren(D, children); +void ClangAstDumper::VisitLinkageSpecDeclChildren( + const LinkageSpecDecl *D, std::vector &children) { addChildren(D->decls(), children); } -void ClangAstDumper::VisitStaticAssertDeclChildren(const StaticAssertDecl *D, std::vector &children) { - // Hierarchy - //VisitDeclChildren(D, children); +void ClangAstDumper::VisitStaticAssertDeclChildren( + const StaticAssertDecl *D, std::vector &children) { addChild(D->getAssertExpr(), children); addChild(D->getMessage(), children); - //VisitStmtTop(D->getAssertExpr()); } -void ClangAstDumper::VisitNonTypeTemplateParmDeclChildren(const NonTypeTemplateParmDecl *D, std::vector &children) { +void ClangAstDumper::VisitNonTypeTemplateParmDeclChildren( + const NonTypeTemplateParmDecl *D, std::vector &children) { // Hierarchy VisitValueDeclChildren(D, children); @@ -676,15 +517,15 @@ void ClangAstDumper::VisitNonTypeTemplateParmDeclChildren(const NonTypeTemplateP VisitStmtTop(D->getDefaultArgument()); } - if(D->isExpandedParameterPack()) { - for(unsigned int i=0; igetNumExpansionTypes(); i++) { + if (D->isExpandedParameterPack()) { + for (unsigned int i = 0; i < D->getNumExpansionTypes(); i++) { VisitTypeTop(D->getExpansionType(i)); } } - } -void ClangAstDumper::VisitUsingDeclChildren(const UsingDecl *D, std::vector &children) { +void ClangAstDumper::VisitUsingDeclChildren( + const UsingDecl *D, std::vector &children) { // Hierarchy VisitNamedDeclChildren(D, children); diff --git a/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorExtras.cpp b/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorExtras.cpp index cf9b7874e..e8a9e35e4 100644 --- a/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorExtras.cpp +++ b/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorExtras.cpp @@ -2,80 +2,94 @@ * EXTRA Visitors */ -#include "../ClangEnums/ClangEnums.h" #include "../Clang/ClangNodes.h" #include "../ClangAstDumper/ClangAstDumper.h" +#include "../ClangEnums/ClangEnums.h" #include "../Clava/ClavaConstants.h" #include -void ClangAstDumper::VisitTemplateArgChildren(const TemplateArgument& templateArg) { - switch(templateArg.getKind()) { - case TemplateArgument::ArgKind::Type: - VisitTypeTop(templateArg.getAsType()); - break; - case TemplateArgument::ArgKind::Expression: - VisitStmtTop(templateArg.getAsExpr()); - break; - case TemplateArgument::ArgKind::Pack: - for (auto currentArg = templateArg.pack_begin(), endArg = templateArg.pack_end(); currentArg != endArg; ++currentArg) { - VisitTemplateArgChildren(*currentArg); - } - break; - case TemplateArgument::ArgKind::Integral: - // Do nothing - break; - case TemplateArgument::ArgKind::Template: - VisitTemplateNameChildren(templateArg.getAsTemplate()); - break; - default: throw std::invalid_argument("ClangAstDumper::VisitTemplateArgChildren(const TemplateArgument&): Case not implemented, '"+clava::TEMPLATE_ARG_KIND[templateArg.getKind()]+"'"); +void ClangAstDumper::VisitTemplateArgChildren( + const TemplateArgument &templateArg) { + switch (templateArg.getKind()) { + case TemplateArgument::ArgKind::Type: + VisitTypeTop(templateArg.getAsType()); + break; + case TemplateArgument::ArgKind::Expression: + VisitStmtTop(templateArg.getAsExpr()); + break; + case TemplateArgument::ArgKind::Pack: + for (auto currentArg = templateArg.pack_begin(), + endArg = templateArg.pack_end(); + currentArg != endArg; ++currentArg) { + VisitTemplateArgChildren(*currentArg); + } + break; + case TemplateArgument::ArgKind::Integral: + // Do nothing + break; + case TemplateArgument::ArgKind::Template: + VisitTemplateNameChildren(templateArg.getAsTemplate()); + break; + default: + throw std::invalid_argument( + "ClangAstDumper::VisitTemplateArgChildren(const " + "TemplateArgument&): Case not implemented, '" + + clava::TEMPLATE_ARG_KIND[templateArg.getKind()] + "'"); } } -void ClangAstDumper::VisitTemplateNameChildren(const TemplateName& templateName) { - switch(templateName.getKind()) { - case TemplateName::NameKind::Template: - VisitDeclTop(templateName.getAsTemplateDecl()); - break; - case TemplateName::NameKind::QualifiedTemplate: - VisitDeclTop(templateName.getAsQualifiedTemplateName()->getTemplateDecl()); - break; - case TemplateName::NameKind::SubstTemplateTemplateParm: - VisitDeclTop(templateName.getAsSubstTemplateTemplateParm()->getParameter()); - VisitTemplateNameChildren(templateName.getAsSubstTemplateTemplateParm()->getReplacement()); - break; - default: - throw std::invalid_argument("ClangAstDumper::VisitTemplateNameChildren(TemplateName&): TemplateName case in kind 'Template' not implemented, '" + - clava::TEMPLATE_NAME_KIND[templateName.getKind()] + "'"); +void ClangAstDumper::VisitTemplateNameChildren( + const TemplateName &templateName) { + switch (templateName.getKind()) { + case TemplateName::NameKind::Template: + VisitDeclTop(templateName.getAsTemplateDecl()); + break; + case TemplateName::NameKind::QualifiedTemplate: + VisitDeclTop( + templateName.getAsQualifiedTemplateName()->getTemplateDecl()); + break; + case TemplateName::NameKind::SubstTemplateTemplateParm: + VisitDeclTop( + templateName.getAsSubstTemplateTemplateParm()->getParameter()); + VisitTemplateNameChildren( + templateName.getAsSubstTemplateTemplateParm()->getReplacement()); + break; + default: + throw std::invalid_argument( + "ClangAstDumper::VisitTemplateNameChildren(TemplateName&): " + "TemplateName case in kind 'Template' not implemented, '" + + clava::TEMPLATE_NAME_KIND[templateName.getKind()] + "'"); } } -void ClangAstDumper::VisitNestedNameSpecifierChildren(NestedNameSpecifier* qualifier) { +void ClangAstDumper::VisitNestedNameSpecifierChildren( + NestedNameSpecifier *qualifier) { auto qualifierKind = qualifier->getKind(); - switch(qualifierKind) { -// case clang::NestedNameSpecifier::Identifier: -// break; - case clang::NestedNameSpecifier::Namespace: - VisitDeclTop(qualifier->getAsNamespace()); - break; - case clang::NestedNameSpecifier::NamespaceAlias: - VisitDeclTop(qualifier->getAsNamespaceAlias()); - break; - case clang::NestedNameSpecifier::TypeSpec: - VisitTypeTop(qualifier->getAsType()); - break; - case clang::NestedNameSpecifier::TypeSpecWithTemplate: - VisitTypeTop(qualifier->getAsType()); - break; - case clang::NestedNameSpecifier::Global: - break; - case clang::NestedNameSpecifier::Super: - VisitDeclTop(qualifier->getAsRecordDecl()); - break; - default: - throw std::invalid_argument( - "ClangAstDumper::VisitNestedNameSpecifierChildren(NestedNameSpecifier):: Case not implemented, '" + clava::NESTED_NAMED_SPECIFIER[qualifier->getKind()] + "'"); + switch (qualifierKind) { + case clang::NestedNameSpecifier::Namespace: + VisitDeclTop(qualifier->getAsNamespace()); + break; + case clang::NestedNameSpecifier::NamespaceAlias: + VisitDeclTop(qualifier->getAsNamespaceAlias()); + break; + case clang::NestedNameSpecifier::TypeSpec: + VisitTypeTop(qualifier->getAsType()); + break; + case clang::NestedNameSpecifier::TypeSpecWithTemplate: + VisitTypeTop(qualifier->getAsType()); + break; + case clang::NestedNameSpecifier::Global: + break; + case clang::NestedNameSpecifier::Super: + VisitDeclTop(qualifier->getAsRecordDecl()); + break; + default: + throw std::invalid_argument( + "ClangAstDumper::VisitNestedNameSpecifierChildren(" + "NestedNameSpecifier):: Case not implemented, '" + + clava::NESTED_NAMED_SPECIFIER[qualifier->getKind()] + "'"); } } \ No newline at end of file diff --git a/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorStmts.cpp b/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorStmts.cpp index 77a37aea1..4f16368ff 100644 --- a/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorStmts.cpp +++ b/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorStmts.cpp @@ -2,15 +2,15 @@ // Created by JoaoBispo on 01/04/2018. // -#include "../ClangEnums/ClangEnums.h" #include "../Clang/ClangNodes.h" #include "../ClangAstDumper/ClangAstDumper.h" +#include "../ClangEnums/ClangEnums.h" #include "../Clava/ClavaConstants.h" #include - -const std::map ClangAstDumper::STMT_CHILDREN_MAP = { +const std::map + ClangAstDumper::STMT_CHILDREN_MAP = { {"DeclStmt", clava::StmtNode::DECL_STMT}, {"IfStmt", clava::StmtNode::IF_STMT}, {"ForStmt", clava::StmtNode::FOR_STMT}, @@ -27,13 +27,16 @@ const std::map ClangAstDumper::STMT_CHILDRE {"CapturedStmt", clava::StmtNode::CAPTURED_STMT}, }; -const std::map ClangAstDumper::EXPR_CHILDREN_MAP = { +const std::map + ClangAstDumper::EXPR_CHILDREN_MAP = { {"InitListExpr", clava::StmtNode::INIT_LIST_EXPR}, {"DeclRefExpr", clava::StmtNode::DECL_REF_EXPR}, - {"DependentScopeDeclRefExpr", clava::StmtNode::DEPENDENT_SCOPE_DECL_REF_EXPR}, + {"DependentScopeDeclRefExpr", + clava::StmtNode::DEPENDENT_SCOPE_DECL_REF_EXPR}, {"OffsetOfExpr", clava::StmtNode::OFFSET_OF_EXPR}, {"MemberExpr", clava::StmtNode::MEMBER_EXPR}, - {"MaterializeTemporaryExpr", clava::StmtNode::MATERIALIZE_TEMPORARY_EXPR}, + {"MaterializeTemporaryExpr", + clava::StmtNode::MATERIALIZE_TEMPORARY_EXPR}, {"UnresolvedLookupExpr", clava::StmtNode::OVERLOAD_EXPR}, {"UnresolvedMemberExpr", clava::StmtNode::OVERLOAD_EXPR}, {"CallExpr", clava::StmtNode::CALL_EXPR}, @@ -50,206 +53,245 @@ const std::map ClangAstDumper::EXPR_CHILDRE {"CXXDeleteExpr", clava::StmtNode::CXX_DELETE_EXPR}, {"LambdaExpr", clava::StmtNode::LAMBDA_EXPR}, {"SizeOfPackExpr", clava::StmtNode::SIZE_OF_PACK_EXPR}, - {"UnaryExprOrTypeTraitExpr", clava::StmtNode::UNARY_EXPR_OR_TYPE_TRAIT_EXPR}, + {"UnaryExprOrTypeTraitExpr", + clava::StmtNode::UNARY_EXPR_OR_TYPE_TRAIT_EXPR}, {"DesignatedInitExpr", clava::StmtNode::DESIGNATED_INIT_EXPR}, {"CXXConstructExpr", clava::StmtNode::CXX_CONSTRUCT_EXPR}, {"CXXTemporaryObjectExpr", clava::StmtNode::CXX_TEMPORARY_OBJECT_EXPR}, - {"CXXDependentScopeMemberExpr", clava::StmtNode::CXX_DEPENDENT_SCOPE_MEMBER_EXPR}, - {"CXXPseudoDestructorExpr", clava::StmtNode::CXX_PSEUDO_DESTRUCTOR_EXPR}, + {"CXXDependentScopeMemberExpr", + clava::StmtNode::CXX_DEPENDENT_SCOPE_MEMBER_EXPR}, + {"CXXPseudoDestructorExpr", + clava::StmtNode::CXX_PSEUDO_DESTRUCTOR_EXPR}, {"MSPropertyRefExpr", clava::StmtNode::MS_PROPERTY_REF_EXPR}, - - //{"ConstantExpr", clava::StmtNode::FULL_EXPR}, - //{"ExprWithCleanups", clava::StmtNode::FULL_EXPR}, - //{"CXXNoexceptExpr", clava::StmtNode::CXX_NOEXCEPT_EXPR}, - - //{"SubstNonTypeTemplateParmExpr", clava::StmtNode::SUBST_NON_TYPE_TEMPLATE_PARM_EXPR}, }; -void ClangAstDumper::visitChildren(const Stmt* S) { +void ClangAstDumper::visitChildren(const Stmt *S) { // Get classname const std::string classname = clava::getClassName(S); // Get corresponding StmtNode - clava::StmtNode stmtNode = STMT_CHILDREN_MAP.count(classname) == 1 ? STMT_CHILDREN_MAP.find(classname)->second : - clava::StmtNode::STMT; + clava::StmtNode stmtNode = STMT_CHILDREN_MAP.count(classname) == 1 + ? STMT_CHILDREN_MAP.find(classname)->second + : clava::StmtNode::STMT; visitChildren(stmtNode, S); } -void ClangAstDumper::visitChildren(const Expr* E) { +void ClangAstDumper::visitChildren(const Expr *E) { // Get classname const std::string classname = clava::getClassName(E); // Get corresponding ExprNode - clava::StmtNode exprNode = EXPR_CHILDREN_MAP.count(classname) == 1 ? EXPR_CHILDREN_MAP.find(classname)->second : - clava::StmtNode::EXPR; + clava::StmtNode exprNode = EXPR_CHILDREN_MAP.count(classname) == 1 + ? EXPR_CHILDREN_MAP.find(classname)->second + : clava::StmtNode::EXPR; visitChildren(exprNode, E); } -void ClangAstDumper::visitChildren(clava::StmtNode stmtNode, const Stmt* S) { +void ClangAstDumper::visitChildren(clava::StmtNode stmtNode, const Stmt *S) { std::vector visitedChildren; - switch(stmtNode) { - case clava::StmtNode::STMT: - VisitStmtChildren(S, visitedChildren); break; -// case clava::StmtNode::COMPOUND_STMT: -// VisitCompoundStmtChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::DECL_STMT: - VisitDeclStmtChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::IF_STMT: - VisitIfStmtChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::FOR_STMT: - VisitForStmtChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::WHILE_STMT: - VisitWhileStmtChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::DO_STMT: - VisitDoStmtChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::CXX_FOR_RANGE_STMT: - VisitCXXForRangeStmtChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::CXX_CATCH_STMT: - VisitCXXCatchStmtChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::CXX_TRY_STMT: - VisitCXXTryStmtChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::CASE_STMT: - VisitCaseStmtChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::DEFAULT_STMT: - VisitDefaultStmtChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::GOTO_STMT: - VisitGotoStmtChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::LABEL_STMT: - VisitLabelStmtChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::ATTRIBUTED_STMT: - VisitAttributedStmtChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::CAPTURED_STMT: - VisitCapturedStmtChildren(static_cast(S), visitedChildren); break; - - - - - case clava::StmtNode::EXPR: - VisitExprChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::INIT_LIST_EXPR: - VisitInitListExprChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::DECL_REF_EXPR: - VisitDeclRefExprChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::DEPENDENT_SCOPE_DECL_REF_EXPR: - VisitDependentScopeDeclRefExprChildren(static_cast(S), visitedChildren); break; -// case clava::StmtNode::CAST_EXPR: -// VisitCastExprChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::OFFSET_OF_EXPR: - VisitOffsetOfExprChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::MEMBER_EXPR: - VisitMemberExprChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::MATERIALIZE_TEMPORARY_EXPR: - VisitMaterializeTemporaryExprChildren(static_cast(S), visitedChildren); break; -// case clava::StmtNode::UNRESOLVED_LOOKUP_EXPR: -// VisitUnresolvedLookupExprChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::OVERLOAD_EXPR: - VisitOverloadExprChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::CALL_EXPR: - VisitCallExprChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::CXX_MEMBER_CALL_EXPR: - VisitCXXMemberCallExprChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::CXX_TYPEID_EXPR: - VisitCXXTypeidExprChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::EXPLICIT_CAST_EXPR: - VisitExplicitCastExprChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::OPAQUE_VALUE_EXPR: - VisitOpaqueValueExprChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::UNARY_EXPR_OR_TYPE_TRAIT_EXPR: - VisitUnaryExprOrTypeTraitExprChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::CXX_NEW_EXPR: - VisitCXXNewExprChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::CXX_DELETE_EXPR: - VisitCXXDeleteExprChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::LAMBDA_EXPR: - VisitLambdaExprChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::SIZE_OF_PACK_EXPR: - VisitSizeOfPackExprChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::DESIGNATED_INIT_EXPR: - VisitDesignatedInitExprChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::CXX_CONSTRUCT_EXPR: - VisitCXXConstructExprChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::CXX_TEMPORARY_OBJECT_EXPR: - VisitCXXTemporaryObjectExprChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::CXX_DEPENDENT_SCOPE_MEMBER_EXPR: - VisitCXXDependentScopeMemberExprChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::CXX_PSEUDO_DESTRUCTOR_EXPR: - VisitCXXPseudoDestructorExprChildren(static_cast(S), visitedChildren); break; - case clava::StmtNode::MS_PROPERTY_REF_EXPR: - VisitMSPropertyRefExprChildren(static_cast(S), visitedChildren); break; - - //case clava::StmtNode::FULL_EXPR: - // VisitFullExprChildren(static_cast(S), visitedChildren); break; -// case clava::StmtNode::CXX_NOEXCEPT_EXPR: -// VisitCXXNoexceptExprChildren(static_cast(S), visitedChildren); break; - - - // case clava::StmtNode::SUBST_NON_TYPE_TEMPLATE_PARM_EXPR: -// VisitSubstNonTypeTemplateParmExprChildren(static_cast(S), visitedChildren); break; - - - default: throw std::invalid_argument("ChildrenVisitorStmts::visitChildren(StmtNode): Case not implemented, '"+clava::getName(stmtNode)+"'"); - + switch (stmtNode) { + case clava::StmtNode::STMT: + VisitStmtChildren(S, visitedChildren); + break; + case clava::StmtNode::DECL_STMT: + VisitDeclStmtChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::IF_STMT: + VisitIfStmtChildren(static_cast(S), visitedChildren); + break; + case clava::StmtNode::FOR_STMT: + VisitForStmtChildren(static_cast(S), visitedChildren); + break; + case clava::StmtNode::WHILE_STMT: + VisitWhileStmtChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::DO_STMT: + VisitDoStmtChildren(static_cast(S), visitedChildren); + break; + case clava::StmtNode::CXX_FOR_RANGE_STMT: + VisitCXXForRangeStmtChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::CXX_CATCH_STMT: + VisitCXXCatchStmtChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::CXX_TRY_STMT: + VisitCXXTryStmtChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::CASE_STMT: + VisitCaseStmtChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::DEFAULT_STMT: + VisitDefaultStmtChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::GOTO_STMT: + VisitGotoStmtChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::LABEL_STMT: + VisitLabelStmtChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::ATTRIBUTED_STMT: + VisitAttributedStmtChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::CAPTURED_STMT: + VisitCapturedStmtChildren(static_cast(S), + visitedChildren); + break; + + case clava::StmtNode::EXPR: + VisitExprChildren(static_cast(S), visitedChildren); + break; + case clava::StmtNode::INIT_LIST_EXPR: + VisitInitListExprChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::DECL_REF_EXPR: + VisitDeclRefExprChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::DEPENDENT_SCOPE_DECL_REF_EXPR: + VisitDependentScopeDeclRefExprChildren( + static_cast(S), visitedChildren); + break; + case clava::StmtNode::OFFSET_OF_EXPR: + VisitOffsetOfExprChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::MEMBER_EXPR: + VisitMemberExprChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::MATERIALIZE_TEMPORARY_EXPR: + VisitMaterializeTemporaryExprChildren( + static_cast(S), visitedChildren); + break; + case clava::StmtNode::OVERLOAD_EXPR: + VisitOverloadExprChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::CALL_EXPR: + VisitCallExprChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::CXX_MEMBER_CALL_EXPR: + VisitCXXMemberCallExprChildren( + static_cast(S), visitedChildren); + break; + case clava::StmtNode::CXX_TYPEID_EXPR: + VisitCXXTypeidExprChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::EXPLICIT_CAST_EXPR: + VisitExplicitCastExprChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::OPAQUE_VALUE_EXPR: + VisitOpaqueValueExprChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::UNARY_EXPR_OR_TYPE_TRAIT_EXPR: + VisitUnaryExprOrTypeTraitExprChildren( + static_cast(S), visitedChildren); + break; + case clava::StmtNode::CXX_NEW_EXPR: + VisitCXXNewExprChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::CXX_DELETE_EXPR: + VisitCXXDeleteExprChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::LAMBDA_EXPR: + VisitLambdaExprChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::SIZE_OF_PACK_EXPR: + VisitSizeOfPackExprChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::DESIGNATED_INIT_EXPR: + VisitDesignatedInitExprChildren( + static_cast(S), visitedChildren); + break; + case clava::StmtNode::CXX_CONSTRUCT_EXPR: + VisitCXXConstructExprChildren(static_cast(S), + visitedChildren); + break; + case clava::StmtNode::CXX_TEMPORARY_OBJECT_EXPR: + VisitCXXTemporaryObjectExprChildren( + static_cast(S), visitedChildren); + break; + case clava::StmtNode::CXX_DEPENDENT_SCOPE_MEMBER_EXPR: + VisitCXXDependentScopeMemberExprChildren( + static_cast(S), + visitedChildren); + break; + case clava::StmtNode::CXX_PSEUDO_DESTRUCTOR_EXPR: + VisitCXXPseudoDestructorExprChildren( + static_cast(S), visitedChildren); + break; + case clava::StmtNode::MS_PROPERTY_REF_EXPR: + VisitMSPropertyRefExprChildren( + static_cast(S), visitedChildren); + break; + default: + throw std::invalid_argument("ChildrenVisitorStmts::visitChildren(" + "StmtNode): Case not implemented, '" + + clava::getName(stmtNode) + "'"); } dumpVisitedChildren(S, visitedChildren); } -void ClangAstDumper::VisitStmtChildren(const Stmt *S, std::vector &children) { +void ClangAstDumper::VisitStmtChildren(const Stmt *S, + std::vector &children) { // Visit Stmt children for (const Stmt *SubStmt : S->children()) { if (SubStmt) { addChild(SubStmt, children); - //VisitStmtTop(SubStmt); - //children.push_back(clava::getId(SubStmt, id)); } } } - -/* -void ClangAstDumper::VisitCompoundStmtChildren(const CompoundStmt *S, std::vector &children) { - - // Visit sub-statements - for (auto &Arg : S->body()) { - VisitStmtTop(Arg); - children.push_back(getId(Arg)); - } -} - */ - - -void ClangAstDumper::VisitDeclStmtChildren(const DeclStmt *S, std::vector &children) { +void ClangAstDumper::VisitDeclStmtChildren(const DeclStmt *S, + std::vector &children) { // Do not visit sub-statements, only decls - //VisitStmtChildren(S, children); // Visit decls - for (DeclStmt::const_decl_iterator I = S->decl_begin(), E = S->decl_end(); I != E; ++I) { + for (DeclStmt::const_decl_iterator I = S->decl_begin(), E = S->decl_end(); + I != E; ++I) { addChild(*I, children); - //VisitDeclTop(*I); - //children.push_back(clava::getId(*I, id)); } - } -void ClangAstDumper::VisitIfStmtChildren(const IfStmt *S, std::vector &children) { - // Do not visit sub-statements automatically, visit the if stmts in a controlled manner - //VisitStmtChildren(S, children); +void ClangAstDumper::VisitIfStmtChildren(const IfStmt *S, + std::vector &children) { + // Do not visit sub-statements automatically, visit the if stmts in a + // controlled manner - //addChild(S->getConditionVariableDeclStmt(), children); addChild(S->getConditionVariable(), children); addChild(S->getCond(), children); addChild(S->getThen(), children); addChild(S->getElse(), children); } -void ClangAstDumper::VisitForStmtChildren(const ForStmt *S, std::vector &children) { - // Do not visit sub-statements automatically, visit the for stmts in a controlled manner - //VisitStmtChildren(S, children); - +void ClangAstDumper::VisitForStmtChildren(const ForStmt *S, + std::vector &children) { + // Do not visit sub-statements automatically, visit the for stmts in a + // controlled manner addChild(S->getInit(), children); addChild(S->getCond(), children); @@ -258,29 +300,31 @@ void ClangAstDumper::VisitForStmtChildren(const ForStmt *S, std::vectorgetConditionVariable(), children); } -void ClangAstDumper::VisitWhileStmtChildren(const WhileStmt *S, std::vector &children) { - // Do not visit sub-statements automatically, visit the if stmts in a controlled manner - //VisitStmtChildren(S, children); +void ClangAstDumper::VisitWhileStmtChildren( + const WhileStmt *S, std::vector &children) { + // Do not visit sub-statements automatically, visit the if stmts in a + // controlled manner addChild(S->getConditionVariable(), children); addChild(S->getCond(), children); addChild(S->getBody(), children); } -void ClangAstDumper::VisitDoStmtChildren(const DoStmt *S, std::vector &children) { - // Do not visit sub-statements automatically, visit the if stmts in a controlled manner - //VisitStmtChildren(S, children); +void ClangAstDumper::VisitDoStmtChildren(const DoStmt *S, + std::vector &children) { + // Do not visit sub-statements automatically, visit the if stmts in a + // controlled manner addChild(S->getBody(), children); addChild(S->getCond(), children); } -void ClangAstDumper::VisitCXXForRangeStmtChildren(const CXXForRangeStmt *S, std::vector &children) { - // Do not visit sub-statements automatically, visit the if stmts in a controlled manner - //VisitStmtChildren(S, children); +void ClangAstDumper::VisitCXXForRangeStmtChildren( + const CXXForRangeStmt *S, std::vector &children) { + // Do not visit sub-statements automatically, visit the if stmts in a + // controlled manner addChild(S->getRangeStmt(), children); - //addChild(S->getBeginEndStmt(), children); LLVM3.8 addChild(S->getBeginStmt(), children); addChild(S->getEndStmt(), children); addChild(S->getCond(), children); @@ -289,63 +333,66 @@ void ClangAstDumper::VisitCXXForRangeStmtChildren(const CXXForRangeStmt *S, std: addChild(S->getBody(), children); } -void ClangAstDumper::VisitCXXCatchStmtChildren(const CXXCatchStmt *S, std::vector &children) { - // Do not visit sub-statements automatically, visit the if stmts in a controlled manner - //VisitStmtChildren(S, children); +void ClangAstDumper::VisitCXXCatchStmtChildren( + const CXXCatchStmt *S, std::vector &children) { + // Do not visit sub-statements automatically, visit the if stmts in a + // controlled manner addChild(S->getExceptionDecl(), children); addChild(S->getHandlerBlock(), children); } -void ClangAstDumper::VisitCXXTryStmtChildren(const CXXTryStmt *S, std::vector &children) { - // Do not visit sub-statements automatically, visit the if stmts in a controlled manner - //VisitStmtChildren(S, children); +void ClangAstDumper::VisitCXXTryStmtChildren( + const CXXTryStmt *S, std::vector &children) { + // Do not visit sub-statements automatically, visit the if stmts in a + // controlled manner addChild(S->getTryBlock(), children); - for(unsigned i=0; igetNumHandlers();i++) { + for (unsigned i = 0; i < S->getNumHandlers(); i++) { addChild(S->getHandler(i), children); } - - //llvm::errs() << "TRY STMT: " << S << "\n"; - //llvm::errs() << "TRY BLOCK: " << S->getTryBlock() << "\n"; } -void ClangAstDumper::VisitCaseStmtChildren(const CaseStmt *S, std::vector &children) { - // Do not visit sub-statements automatically, visit the if stmts in a controlled manner - //VisitStmtChildren(S, children); +void ClangAstDumper::VisitCaseStmtChildren(const CaseStmt *S, + std::vector &children) { + // Do not visit sub-statements automatically, visit the if stmts in a + // controlled manner addChild(S->getLHS(), children); addChild(S->getRHS(), children); addChild(S->getSubStmt(), children); } -void ClangAstDumper::VisitDefaultStmtChildren(const DefaultStmt *S, std::vector &children) { - // Do not visit sub-statements automatically, visit the if stmts in a controlled manner - //VisitStmtChildren(S, children); +void ClangAstDumper::VisitDefaultStmtChildren( + const DefaultStmt *S, std::vector &children) { + // Do not visit sub-statements automatically, visit the if stmts in a + // controlled manner addChild(S->getSubStmt(), children); } - -void ClangAstDumper::VisitGotoStmtChildren(const GotoStmt *S, std::vector &children) { - // Do not visit sub-statements automatically, visit the if stmts in a controlled manner - //VisitStmtChildren(S, children); +void ClangAstDumper::VisitGotoStmtChildren(const GotoStmt *S, + std::vector &children) { + // Do not visit sub-statements automatically, visit the if stmts in a + // controlled manner VisitDeclTop(S->getLabel()); } -void ClangAstDumper::VisitLabelStmtChildren(const LabelStmt *S, std::vector &children) { - // Do not visit sub-statements automatically, visit the if stmts in a controlled manner - //VisitStmtChildren(S, children); +void ClangAstDumper::VisitLabelStmtChildren( + const LabelStmt *S, std::vector &children) { + // Do not visit sub-statements automatically, visit the if stmts in a + // controlled manner addChild(S->getSubStmt(), children); VisitDeclTop(S->getDecl()); } -void ClangAstDumper::VisitAttributedStmtChildren(const AttributedStmt *S, std::vector &children) { - // Do not visit sub-statements automatically, visit the if stmts in a controlled manner - //VisitStmtChildren(S, children); +void ClangAstDumper::VisitAttributedStmtChildren( + const AttributedStmt *S, std::vector &children) { + // Do not visit sub-statements automatically, visit the if stmts in a + // controlled manner // Visit attributes for (auto attr : S->getAttrs()) { @@ -356,19 +403,16 @@ void ClangAstDumper::VisitAttributedStmtChildren(const AttributedStmt *S, std::v addChild(S->getSubStmt(), children); } -void ClangAstDumper::VisitCapturedStmtChildren(const CapturedStmt *S, std::vector &children) { - // Do not visit sub-statements automatically, visit the if stmts in a controlled manner - //VisitStmtChildren(S, children); +void ClangAstDumper::VisitCapturedStmtChildren( + const CapturedStmt *S, std::vector &children) { + // Do not visit sub-statements automatically, visit the if stmts in a + // controlled manner addChild(S->getCapturedStmt(), children); } - - - - - -void ClangAstDumper::VisitExprChildren(const Expr *E, std::vector &children) { +void ClangAstDumper::VisitExprChildren(const Expr *E, + std::vector &children) { // Visit sub-statements VisitStmtChildren(E, children); @@ -377,34 +421,21 @@ void ClangAstDumper::VisitExprChildren(const Expr *E, std::vector & dumpTopLevelType(E->getType()); } -void ClangAstDumper::VisitInitListExprChildren(const InitListExpr *E, std::vector &children) { +void ClangAstDumper::VisitInitListExprChildren( + const InitListExpr *E, std::vector &children) { // Hierarchy VisitExprChildren(E, children); // Visit array filler VisitStmtTop(E->getArrayFiller()); - // Visit field - //VisitDeclTop(E->getInitializedFieldInUnion()); - // Visit syntatic form VisitStmtTop(E->getSyntacticForm()); VisitStmtTop(E->getSemanticForm()); } - -/* -void ClangAstDumper::VisitCastExprChildren(const CastExpr *S, std::vector &children) { - - // Sub-expression - auto subExprAsWritten = S->getSubExprAsWritten(); - VisitStmtTop(subExprAsWritten); - children.push_back(getId(subExprAsWritten)); -} - */ - - -void ClangAstDumper::VisitDeclRefExprChildren(const DeclRefExpr *E, std::vector &children) { +void ClangAstDumper::VisitDeclRefExprChildren( + const DeclRefExpr *E, std::vector &children) { // Hierarchy VisitExprChildren(E, children); @@ -415,17 +446,10 @@ void ClangAstDumper::VisitDeclRefExprChildren(const DeclRefExpr *E, std::vector< auto templateArg = templateArgs + i; VisitTemplateArgument(templateArg->getArgument()); } - - // Visit decl - //VisitDeclTop(E->getDecl()); - //children.push_back(clava::getId(E->getDecl(), id)); - - // Visit found decl as child - //VisitDeclTop(E->getFoundDecl()); - //children.push_back(clava::getId(E->getFoundDecl(), id)); } -void ClangAstDumper::VisitDependentScopeDeclRefExprChildren(const DependentScopeDeclRefExpr *E, std::vector &children) { +void ClangAstDumper::VisitDependentScopeDeclRefExprChildren( + const DependentScopeDeclRefExpr *E, std::vector &children) { // Hierarchy VisitExprChildren(E, children); @@ -434,37 +458,38 @@ void ClangAstDumper::VisitDependentScopeDeclRefExprChildren(const DependentScope auto templateArg = templateArgs + i; VisitTemplateArgument(templateArg->getArgument()); } - } - -void ClangAstDumper::VisitOffsetOfExprChildren(const OffsetOfExpr *E, std::vector &children) { +void ClangAstDumper::VisitOffsetOfExprChildren( + const OffsetOfExpr *E, std::vector &children) { // Hierarchy VisitExprChildren(E, children); // Visit type VisitTypeTop(E->getTypeSourceInfo()->getType().getTypePtr()); - for(unsigned i = 0; i < E->getNumComponents(); i++) { + for (unsigned i = 0; i < E->getNumComponents(); i++) { // Dump each component OffsetOfNode node = E->getComponent(i); switch (node.getKind()) { - case OffsetOfNode::Kind::Array: - VisitStmtTop(E->getIndexExpr(node.getArrayExprIndex())); - break; - case OffsetOfNode::Kind::Identifier: - case OffsetOfNode::Kind::Field: - // Nothing to visit - break; - default: - clava::throwNotImplemented("ClangDataDumper::VisitOffsetOfExprChildren()", clava::OFFSET_OF_NODE_KIND[node.getKind()], Context, E->getSourceRange()); -// throw std::invalid_argument("ClangDataDumper::DumpOffsetOfExprData(): Case not implemented, '" + -// clava::OFFSET_OF_NODE_KIND[node.getKind()] + "'"); + case OffsetOfNode::Kind::Array: + VisitStmtTop(E->getIndexExpr(node.getArrayExprIndex())); + break; + case OffsetOfNode::Kind::Identifier: + case OffsetOfNode::Kind::Field: + // Nothing to visit + break; + default: + clava::throwNotImplemented( + "ClangDataDumper::VisitOffsetOfExprChildren()", + clava::OFFSET_OF_NODE_KIND[node.getKind()], Context, + E->getSourceRange()); } } } -void ClangAstDumper::VisitMemberExprChildren(const MemberExpr *E, std::vector &children) { +void ClangAstDumper::VisitMemberExprChildren( + const MemberExpr *E, std::vector &children) { // Hierarchy VisitExprChildren(E, children); @@ -473,7 +498,8 @@ void ClangAstDumper::VisitMemberExprChildren(const MemberExpr *E, std::vectorgetFoundDecl().getDecl()); } -void ClangAstDumper::VisitMaterializeTemporaryExprChildren(const MaterializeTemporaryExpr *E, std::vector &children) { +void ClangAstDumper::VisitMaterializeTemporaryExprChildren( + const MaterializeTemporaryExpr *E, std::vector &children) { // Hierarchy VisitExprChildren(E, children); @@ -481,8 +507,8 @@ void ClangAstDumper::VisitMaterializeTemporaryExprChildren(const MaterializeTemp VisitDeclTop(E->getExtendingDecl()); } -//void ClangAstDumper::VisitUnresolvedLookupExprChildren(const UnresolvedLookupExpr *E, std::vector &children) { -void ClangAstDumper::VisitOverloadExprChildren(const OverloadExpr *E, std::vector &children) { +void ClangAstDumper::VisitOverloadExprChildren( + const OverloadExpr *E, std::vector &children) { // Hierarchy - direct parent is OverloadExpr VisitExprChildren(E, children); @@ -498,125 +524,123 @@ void ClangAstDumper::VisitOverloadExprChildren(const OverloadExpr *E, std::vecto auto templateArg = templateArgs + i; VisitTemplateArgument(templateArg->getArgument()); } - } -void ClangAstDumper::VisitCallExprChildren(const CallExpr *E, std::vector &children) { +void ClangAstDumper::VisitCallExprChildren(const CallExpr *E, + std::vector &children) { // Hierarchy VisitExprChildren(E, children); VisitDeclTop(E->getDirectCallee()); - } -void ClangAstDumper::VisitCXXMemberCallExprChildren(const CXXMemberCallExpr *E, std::vector &children) { +void ClangAstDumper::VisitCXXMemberCallExprChildren( + const CXXMemberCallExpr *E, std::vector &children) { // Hierarchy VisitCallExprChildren(E, children); VisitDeclTop(E->getMethodDecl()); - } -void ClangAstDumper::VisitCXXTypeidExprChildren(const CXXTypeidExpr *E, std::vector &children) { +void ClangAstDumper::VisitCXXTypeidExprChildren( + const CXXTypeidExpr *E, std::vector &children) { // Hierarchy VisitExprChildren(E, children); - if(E->isTypeOperand()) { + if (E->isTypeOperand()) { VisitTypeTop(E->getTypeOperand(*Context)); } else { VisitStmtTop(E->getExprOperand()); } - } -void ClangAstDumper::VisitExplicitCastExprChildren(const ExplicitCastExpr *E, std::vector &children) { +void ClangAstDumper::VisitExplicitCastExprChildren( + const ExplicitCastExpr *E, std::vector &children) { // Hierarchy - direct parent is CastExpr VisitExprChildren(E, children); - VisitTypeTop(E->getTypeAsWritten()); } -void ClangAstDumper::VisitOpaqueValueExprChildren(const OpaqueValueExpr *E, std::vector &children) { +void ClangAstDumper::VisitOpaqueValueExprChildren( + const OpaqueValueExpr *E, std::vector &children) { // Hierarchy VisitExprChildren(E, children); addChild(E->getSourceExpr(), children); - } -void ClangAstDumper::VisitUnaryExprOrTypeTraitExprChildren(const UnaryExprOrTypeTraitExpr *E, std::vector &children) { +void ClangAstDumper::VisitUnaryExprOrTypeTraitExprChildren( + const UnaryExprOrTypeTraitExpr *E, std::vector &children) { // Hierarchy VisitExprChildren(E, children); - if(E->isArgumentType()) { + if (E->isArgumentType()) { VisitTypeTop(E->getArgumentType()); - //llvm::errs() << "UNARY ARG TYPE: " << clava::getId(E->getArgumentType(), id) << "\n"; } - } -void ClangAstDumper::VisitCXXNewExprChildren(const CXXNewExpr *E, std::vector &children) { +void ClangAstDumper::VisitCXXNewExprChildren( + const CXXNewExpr *E, std::vector &children) { // Hierarchy VisitExprChildren(E, children); VisitStmtTop(E->getInitializer()); VisitStmtTop(E->getArraySize().getValueOr(nullptr)); VisitDeclTop(E->getOperatorNew()); - } -void ClangAstDumper::VisitCXXDeleteExprChildren(const CXXDeleteExpr *E, std::vector &children) { +void ClangAstDumper::VisitCXXDeleteExprChildren( + const CXXDeleteExpr *E, std::vector &children) { // Hierarchy VisitExprChildren(E, children); addChild(E->getArgument(), children); - //VisitStmtTop(E->getArgument()); } -void ClangAstDumper::VisitLambdaExprChildren(const LambdaExpr *E, std::vector &children) { +void ClangAstDumper::VisitLambdaExprChildren( + const LambdaExpr *E, std::vector &children) { // Hierarchy VisitExprChildren(E, children); VisitDeclTop(E->getLambdaClass()); } -void ClangAstDumper::VisitSizeOfPackExprChildren(const SizeOfPackExpr *E, std::vector &children) { +void ClangAstDumper::VisitSizeOfPackExprChildren( + const SizeOfPackExpr *E, std::vector &children) { // Hierarchy VisitExprChildren(E, children); VisitDeclTop(E->getPack()); - if(E->isPartiallySubstituted()) { + if (E->isPartiallySubstituted()) { for (auto templateArg : E->getPartialArguments()) { VisitTemplateArgument(templateArg); } } } -void ClangAstDumper::VisitDesignatedInitExprChildren(const DesignatedInitExpr *E, std::vector &children) { +void ClangAstDumper::VisitDesignatedInitExprChildren( + const DesignatedInitExpr *E, std::vector &children) { // Hierarchy VisitExprChildren(E, children); - - //for(unsigned int i=0; igetNumSubExprs(); i++) { - // addChild(E->getSubExpr(i), children); - //} - } -void ClangAstDumper::VisitCXXConstructExprChildren(const CXXConstructExpr *E, std::vector &children) { +void ClangAstDumper::VisitCXXConstructExprChildren( + const CXXConstructExpr *E, std::vector &children) { // Hierarchy VisitExprChildren(E, children); - VisitDeclTop(E->getConstructor()); } -void ClangAstDumper::VisitCXXTemporaryObjectExprChildren(const CXXTemporaryObjectExpr *E, std::vector &children) { +void ClangAstDumper::VisitCXXTemporaryObjectExprChildren( + const CXXTemporaryObjectExpr *E, std::vector &children) { // Hierarchy VisitCXXConstructExprChildren(E, children); } -void ClangAstDumper::VisitCXXDependentScopeMemberExprChildren(const CXXDependentScopeMemberExpr *E, std::vector &children) { +void ClangAstDumper::VisitCXXDependentScopeMemberExprChildren( + const CXXDependentScopeMemberExpr *E, std::vector &children) { // Hierarchy VisitExprChildren(E, children); @@ -627,50 +651,19 @@ void ClangAstDumper::VisitCXXDependentScopeMemberExprChildren(const CXXDependent } } -void ClangAstDumper::VisitCXXPseudoDestructorExprChildren(const CXXPseudoDestructorExpr *E, std::vector &children) { +void ClangAstDumper::VisitCXXPseudoDestructorExprChildren( + const CXXPseudoDestructorExpr *E, std::vector &children) { // Hierarchy VisitExprChildren(E, children); VisitTypeTop(E->getDestroyedType()); } -void ClangAstDumper::VisitMSPropertyRefExprChildren(const MSPropertyRefExpr *E, std::vector &children) { +void ClangAstDumper::VisitMSPropertyRefExprChildren( + const MSPropertyRefExpr *E, std::vector &children) { // Hierarchy VisitExprChildren(E, children); VisitExpr(E->getBaseExpr()); VisitDeclTop(E->getPropertyDecl()); } - - -/* -void ClangAstDumper::VisitFullExprChildren(const FullExpr *E, std::vector &children) { - // Hierarchy - VisitExprChildren(E, children); - - VisitExpr(E->getSubExpr()); -} - */ - - -/* -void ClangAstDumper::VisitCXXNoexceptExprChildren(const CXXNoexceptExpr *E, std::vector &children) { - // Hierarchy - VisitExprChildren(E, children); - -// VisitExpr(E->getOperand()); -} - */ - - - -/* -void ClangAstDumper::VisitSubstNonTypeTemplateParmExprChildren(const SubstNonTypeTemplateParmExpr *E, std::vector &children) { - // Hierarchy - VisitExprChildren(E, children); - - - addChild(E->getReplacement(), children); - //VisitStmtTop(E->getArgument()); -} -*/ \ No newline at end of file diff --git a/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorTypes.cpp b/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorTypes.cpp index ce63fc03d..5d262c4ce 100644 --- a/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorTypes.cpp +++ b/ClangAstDumper/src/ChildrenVisitor/ChildrenVisitorTypes.cpp @@ -7,26 +7,27 @@ #include -const std::map ClangAstDumper::TYPE_CHILDREN_MAP = { +const std::map + ClangAstDumper::TYPE_CHILDREN_MAP = { {"FunctionProtoType", clava::TypeNode::FUNCTION_PROTO_TYPE}, {"FunctionNoProtoType", clava::TypeNode::FUNCTION_TYPE}, {"ConstantArrayType", clava::TypeNode::ARRAY_TYPE}, - {"DependentSizedArrayType", clava::TypeNode::DEPENDENT_SIZED_ARRAY_TYPE}, + {"DependentSizedArrayType", + clava::TypeNode::DEPENDENT_SIZED_ARRAY_TYPE}, {"IncompleteArrayType", clava::TypeNode::ARRAY_TYPE}, {"VariableArrayType", clava::TypeNode::VARIABLE_ARRAY_TYPE}, {"PointerType", clava::TypeNode::POINTER_TYPE}, - //{"TagType", clava::TypeNode::TAG_TYPE}, {"EnumType", clava::TypeNode::TAG_TYPE}, - //{"EnumType", clava::TypeNode::ENUM_TYPE}, {"RecordType", clava::TypeNode::TAG_TYPE}, {"ElaboratedType", clava::TypeNode::ELABORATED_TYPE}, - //{"ReferenceType", clava::TypeNode::REFERENCE_TYPE}, {"LValueReferenceType", clava::TypeNode::REFERENCE_TYPE}, {"RValueReferenceType", clava::TypeNode::REFERENCE_TYPE}, {"InjectedClassNameType", clava::TypeNode::INJECTED_CLASS_NAME_TYPE}, {"TemplateTypeParmType", clava::TypeNode::TEMPLATE_TYPE_PARM_TYPE}, - {"SubstTemplateTypeParmType", clava::TypeNode::SUBST_TEMPLATE_TYPE_PARM_TYPE}, - {"TemplateSpecializationType", clava::TypeNode::TEMPLATE_SPECIALIZATION_TYPE}, + {"SubstTemplateTypeParmType", + clava::TypeNode::SUBST_TEMPLATE_TYPE_PARM_TYPE}, + {"TemplateSpecializationType", + clava::TypeNode::TEMPLATE_SPECIALIZATION_TYPE}, {"TypedefType", clava::TypeNode::TYPEDEF_TYPE}, {"DecayedType", clava::TypeNode::DECAYED_TYPE}, {"DecltypeType", clava::TypeNode::DECLTYPE_TYPE}, @@ -38,155 +39,178 @@ const std::map ClangAstDumper::TYPE_CHILDRE {"ComplexType", clava::TypeNode::COMPLEX_TYPE}, }; -void ClangAstDumper::visitChildren(const Type* T) { +void ClangAstDumper::visitChildren(const Type *T) { // Get classname const std::string classname = clava::getClassName(T); // Get corresponding ExprNode - clava::TypeNode typeNode = TYPE_CHILDREN_MAP.count(classname) == 1 ? TYPE_CHILDREN_MAP.find(classname)->second : - clava::TypeNode::TYPE; + clava::TypeNode typeNode = TYPE_CHILDREN_MAP.count(classname) == 1 + ? TYPE_CHILDREN_MAP.find(classname)->second + : clava::TypeNode::TYPE; visitChildren(typeNode, T); } -void ClangAstDumper::visitChildren(clava::TypeNode typeNode, const Type* T) { +void ClangAstDumper::visitChildren(clava::TypeNode typeNode, const Type *T) { std::vector visitedChildren; - switch(typeNode) { - case clava::TypeNode::TYPE: - VisitTypeChildren(T, visitedChildren); break; - case clava::TypeNode::FUNCTION_TYPE: - VisitFunctionTypeChildren(static_cast(T), visitedChildren); break; - case clava::TypeNode::FUNCTION_PROTO_TYPE: - VisitFunctionProtoTypeChildren(static_cast(T), visitedChildren); break; - case clava::TypeNode::ARRAY_TYPE: - VisitArrayTypeChildren(static_cast(T), visitedChildren); break; - case clava::TypeNode::VARIABLE_ARRAY_TYPE: - VisitVariableArrayTypeChildren(static_cast(T), visitedChildren); break; - case clava::TypeNode::DEPENDENT_SIZED_ARRAY_TYPE: - VisitDependentSizedArrayTypeChildren(static_cast(T), visitedChildren); break; - case clava::TypeNode::POINTER_TYPE: - VisitPointerTypeChildren(static_cast(T), visitedChildren); break; - case clava::TypeNode::TAG_TYPE: - VisitTagTypeChildren(static_cast(T), visitedChildren); break; - //case clava::TypeNode::ENUM_TYPE: - // VisitEnumTypeChildren(static_cast(T), visitedChildren); break; - case clava::TypeNode::ELABORATED_TYPE: - VisitElaboratedTypeChildren(static_cast(T), visitedChildren); break; - case clava::TypeNode::REFERENCE_TYPE: - VisitReferenceTypeChildren(static_cast(T), visitedChildren); break; - case clava::TypeNode::INJECTED_CLASS_NAME_TYPE: - VisitInjectedClassNameTypeChildren(static_cast(T), visitedChildren); break; - case clava::TypeNode::TEMPLATE_TYPE_PARM_TYPE: - VisitTemplateTypeParmTypeChildren(static_cast(T), visitedChildren); break; - case clava::TypeNode::SUBST_TEMPLATE_TYPE_PARM_TYPE: - VisitSubstTemplateTypeParmTypeChildren(static_cast(T), visitedChildren); break; - case clava::TypeNode::TEMPLATE_SPECIALIZATION_TYPE: - VisitTemplateSpecializationTypeChildren(static_cast(T), visitedChildren); break; - case clava::TypeNode::TYPEDEF_TYPE: - VisitTypedefTypeChildren(static_cast(T), visitedChildren); break; - case clava::TypeNode::ADJUSTED_TYPE: - VisitAdjustedTypeChildren(static_cast(T), visitedChildren); break; - case clava::TypeNode::DECAYED_TYPE: - VisitDecayedTypeChildren(static_cast(T), visitedChildren); break; - case clava::TypeNode::DECLTYPE_TYPE: - VisitDecltypeTypeChildren(static_cast(T), visitedChildren); break; - case clava::TypeNode::AUTO_TYPE: - VisitAutoTypeChildren(static_cast(T), visitedChildren); break; - case clava::TypeNode::PACK_EXPANSION_TYPE: - VisitPackExpansionTypeChildren(static_cast(T), visitedChildren); break; - case clava::TypeNode::TYPE_OF_EXPR_TYPE: - VisitTypeOfExprTypeChildren(static_cast(T), visitedChildren); break; - case clava::TypeNode::ATTRIBUTED_TYPE: - VisitAttributedTypeChildren(static_cast(T), visitedChildren); break; - case clava::TypeNode::UNARY_TRANSFORM_TYPE: - VisitUnaryTransformTypeChildren(static_cast(T), visitedChildren); break; - case clava::TypeNode::COMPLEX_TYPE: - VisitComplexTypeChildren(static_cast(T), visitedChildren); break; - - default: throw std::invalid_argument("ChildrenVisitorTypes::visitChildren(TypeNode): Case not implemented, '"+clava::getName(typeNode)+"'"); - + switch (typeNode) { + case clava::TypeNode::TYPE: + VisitTypeChildren(T, visitedChildren); + break; + case clava::TypeNode::FUNCTION_TYPE: + VisitFunctionTypeChildren(static_cast(T), + visitedChildren); + break; + case clava::TypeNode::FUNCTION_PROTO_TYPE: + VisitFunctionProtoTypeChildren( + static_cast(T), visitedChildren); + break; + case clava::TypeNode::ARRAY_TYPE: + VisitArrayTypeChildren(static_cast(T), + visitedChildren); + break; + case clava::TypeNode::VARIABLE_ARRAY_TYPE: + VisitVariableArrayTypeChildren( + static_cast(T), visitedChildren); + break; + case clava::TypeNode::DEPENDENT_SIZED_ARRAY_TYPE: + VisitDependentSizedArrayTypeChildren( + static_cast(T), visitedChildren); + break; + case clava::TypeNode::POINTER_TYPE: + VisitPointerTypeChildren(static_cast(T), + visitedChildren); + break; + case clava::TypeNode::TAG_TYPE: + VisitTagTypeChildren(static_cast(T), visitedChildren); + break; + case clava::TypeNode::ELABORATED_TYPE: + VisitElaboratedTypeChildren(static_cast(T), + visitedChildren); + break; + case clava::TypeNode::REFERENCE_TYPE: + VisitReferenceTypeChildren(static_cast(T), + visitedChildren); + break; + case clava::TypeNode::INJECTED_CLASS_NAME_TYPE: + VisitInjectedClassNameTypeChildren( + static_cast(T), visitedChildren); + break; + case clava::TypeNode::TEMPLATE_TYPE_PARM_TYPE: + VisitTemplateTypeParmTypeChildren( + static_cast(T), visitedChildren); + break; + case clava::TypeNode::SUBST_TEMPLATE_TYPE_PARM_TYPE: + VisitSubstTemplateTypeParmTypeChildren( + static_cast(T), visitedChildren); + break; + case clava::TypeNode::TEMPLATE_SPECIALIZATION_TYPE: + VisitTemplateSpecializationTypeChildren( + static_cast(T), + visitedChildren); + break; + case clava::TypeNode::TYPEDEF_TYPE: + VisitTypedefTypeChildren(static_cast(T), + visitedChildren); + break; + case clava::TypeNode::ADJUSTED_TYPE: + VisitAdjustedTypeChildren(static_cast(T), + visitedChildren); + break; + case clava::TypeNode::DECAYED_TYPE: + VisitDecayedTypeChildren(static_cast(T), + visitedChildren); + break; + case clava::TypeNode::DECLTYPE_TYPE: + VisitDecltypeTypeChildren(static_cast(T), + visitedChildren); + break; + case clava::TypeNode::AUTO_TYPE: + VisitAutoTypeChildren(static_cast(T), + visitedChildren); + break; + case clava::TypeNode::PACK_EXPANSION_TYPE: + VisitPackExpansionTypeChildren( + static_cast(T), visitedChildren); + break; + case clava::TypeNode::TYPE_OF_EXPR_TYPE: + VisitTypeOfExprTypeChildren(static_cast(T), + visitedChildren); + break; + case clava::TypeNode::ATTRIBUTED_TYPE: + VisitAttributedTypeChildren(static_cast(T), + visitedChildren); + break; + case clava::TypeNode::UNARY_TRANSFORM_TYPE: + VisitUnaryTransformTypeChildren( + static_cast(T), visitedChildren); + break; + case clava::TypeNode::COMPLEX_TYPE: + VisitComplexTypeChildren(static_cast(T), + visitedChildren); + break; + + default: + throw std::invalid_argument("ChildrenVisitorTypes::visitChildren(" + "TypeNode): Case not implemented, '" + + clava::getName(typeNode) + "'"); } - //llvm::errs() << "Dumping visited children for " << clava::getId(T, id) << "\n"; dumpVisitedChildren(T, visitedChildren); } - void ClangAstDumper::visitChildren(const QualType &T) { std::vector visitedChildren; - // Visit underlying (unqualified) type - //TypeVisitor::Visit(T.getTypePtr()); - - //addChild(T.getTypePtr(), visitedChildren); - - // QualType might associate with any type node, do not add type pointer as child - - //llvm::errs() << "QUAL TYPE: " << T.getAsOpaquePtr() << " -> " << T.getTypePtr() << "\n"; VisitTypeTop(T.getTypePtr()); // Visit unqualified type - - VisitTypeTop(T.getSingleStepDesugaredType(*const_cast(Context))); - - //VisitTypeTop(T.getTypePtr()); - //visitedChildren.push_back(clava::getId(T.getTypePtr(), id)); + VisitTypeTop( + T.getSingleStepDesugaredType(*const_cast(Context))); dumpVisitedChildren(T.getAsOpaquePtr(), visitedChildren); } - -void ClangAstDumper::VisitTypeChildren(const Type *T, std::vector &visitedChildren) { +void ClangAstDumper::VisitTypeChildren( + const Type *T, std::vector &visitedChildren) { // If has sugar, visit desugared type - //const Type *singleStepDesugar = T->getUnqualifiedDesugaredType(); - QualType singleStepDesugar = T->getLocallyUnqualifiedSingleStepDesugaredType(); + QualType singleStepDesugar = + T->getLocallyUnqualifiedSingleStepDesugaredType(); - //if(singleStepDesugar != T) { - if(singleStepDesugar != QualType(T, 0)) { + if (singleStepDesugar != QualType(T, 0)) { VisitTypeTop(singleStepDesugar); - //addChild(singleStepDesugar, visitedChildren); - //VisitTypeTop(singleStepDesugar); - //visitedChildren.push_back(clava::getId(singleStepDesugar, id)); } - } -// TypeVisitor::Visit(T.getTypePtr()); - -void ClangAstDumper::VisitFunctionTypeChildren(const FunctionType *T, std::vector &visitedChildren) { +void ClangAstDumper::VisitFunctionTypeChildren( + const FunctionType *T, std::vector &visitedChildren) { // Hierarchy VisitTypeChildren(T, visitedChildren); // Return type - //addChild(T->getReturnType(), visitedChildren); VisitTypeTop(T->getReturnType()); - //visitedChildren.push_back(clava::getId(T->getReturnType(), id)); } -void ClangAstDumper::VisitFunctionProtoTypeChildren(const FunctionProtoType *T, std::vector &visitedChildren) { +void ClangAstDumper::VisitFunctionProtoTypeChildren( + const FunctionProtoType *T, std::vector &visitedChildren) { // Hierarchy VisitFunctionTypeChildren(T, visitedChildren); // Parameters types for (QualType paramType : T->getParamTypes()) { VisitTypeTop(paramType); - //addChild(paramType, visitedChildren); -// VisitTypeTop(paramType); -// visitedChildren.push_back(clava::getId(paramType, id)); } - const auto& exptSpec = T->getExtProtoInfo().ExceptionSpec; + const auto &exptSpec = T->getExtProtoInfo().ExceptionSpec; // Visit exception types - for(auto& exceptType : exptSpec.Exceptions) { + for (auto &exceptType : exptSpec.Exceptions) { VisitTypeTop(exceptType); } - - // Visit noexcept expression, if present VisitStmtTop(exptSpec.NoexceptExpr); @@ -195,125 +219,73 @@ void ClangAstDumper::VisitFunctionProtoTypeChildren(const FunctionProtoType *T, // Visit source template, if present VisitDeclTop(exptSpec.SourceTemplate); - - - - //llvm::errs() << "TEST:" << clava::getClassName(T->getExtProtoInfo().ExceptionSpec.NoexceptExpr); } -void ClangAstDumper::VisitTagTypeChildren(const TagType *T, std::vector &visitedChildren) { +void ClangAstDumper::VisitTagTypeChildren( + const TagType *T, std::vector &visitedChildren) { // Hierarchy VisitTypeChildren(T, visitedChildren); // Just visit decl - //llvm::errs() << "VISITING DECL: " << clava::getId(T->getDecl(), id) << "\n"; - VisitDeclTop(T->getDecl()); - //VisitDeclTop(T->getDecl()->getCanonicalDecl()); - /* - TagDecl* tagDecl = T->getDecl()->getDefinition(); - if(tagDecl != nullptr) { - VisitDeclTop(tagDecl); - } else { - VisitDeclTop(T->getDecl()); - } - */ - -} - -/* -void ClangAstDumper::VisitEnumTypeChildren(const EnumType *T, std::vector &visitedChildren) { - // Hierarchy - VisitTagTypeChildren(T, visitedChildren); - VisitDeclTop(T->getDecl()); } - */ - - -void ClangAstDumper::VisitArrayTypeChildren(const ArrayType *T, std::vector &visitedChildren) { +void ClangAstDumper::VisitArrayTypeChildren( + const ArrayType *T, std::vector &visitedChildren) { // Hierarchy VisitTypeChildren(T, visitedChildren); // Element type - //addChild(T->getElementType(), visitedChildren); VisitTypeTop(T->getElementType()); - - //VisitTypeTop(T->getElementType()); - //visitedChildren.push_back(clava::getId(T->getElementType(), id)); - - //llvm::errs() << "ARRAY TYPE: " << T << "\n"; - //llvm::errs() << "ELEMENT TYPE: " <getElementType().getTypePtr() << "\n"; } -void ClangAstDumper::VisitVariableArrayTypeChildren(const VariableArrayType *T, std::vector &visitedChildren) { +void ClangAstDumper::VisitVariableArrayTypeChildren( + const VariableArrayType *T, std::vector &visitedChildren) { // Hierarchy VisitArrayTypeChildren(T, visitedChildren); - // Visit and add size expression - //addChild(T->getSizeExpr(), visitedChildren); VisitStmtTop(T->getSizeExpr()); - - //VisitStmtTop(T->getSizeExpr()); - //visitedChildren.push_back(clava::getId(T->getSizeExpr(), id)); } -void ClangAstDumper::VisitDependentSizedArrayTypeChildren(const DependentSizedArrayType *T, std::vector &visitedChildren) { +void ClangAstDumper::VisitDependentSizedArrayTypeChildren( + const DependentSizedArrayType *T, + std::vector &visitedChildren) { // Hierarchy VisitArrayTypeChildren(T, visitedChildren); - // Visit and add size expression VisitStmtTop(T->getSizeExpr()); } -void ClangAstDumper::VisitPointerTypeChildren(const PointerType *T, std::vector &visitedChildren) { +void ClangAstDumper::VisitPointerTypeChildren( + const PointerType *T, std::vector &visitedChildren) { // Hierarchy VisitTypeChildren(T, visitedChildren); - - //llvm::errs() << "POINTER TYPE ADDING " << clava::getId(T->getPointeeType(), id) << "\n"; - // Visit pointee - //VisitTypeTop(T->getPointeeType()); - //addChild(T->getPointeeType(), visitedChildren); VisitTypeTop(T->getPointeeType()); - - //VisitTypeTop(T->getPointeeType()); - //visitedChildren.push_back(clava::getId(T->getPointeeType(), id)); } -void ClangAstDumper::VisitElaboratedTypeChildren(const ElaboratedType *T, std::vector &visitedChildren) { +void ClangAstDumper::VisitElaboratedTypeChildren( + const ElaboratedType *T, std::vector &visitedChildren) { // Hierarchy VisitTypeChildren(T, visitedChildren); // Visit named type - //addChild(T->getNamedType(), visitedChildren); VisitTypeTop(T->getNamedType()); -// visitedChildren.push_back(clava::getId(T->getNamedType(), id)); } -void ClangAstDumper::VisitReferenceTypeChildren(const ReferenceType *T, std::vector &visitedChildren) { +void ClangAstDumper::VisitReferenceTypeChildren( + const ReferenceType *T, std::vector &visitedChildren) { // Hierarchy VisitTypeChildren(T, visitedChildren); - //addChild(T->getPointeeTypeAsWritten(), visitedChildren); VisitTypeTop(T->getPointeeTypeAsWritten()); - - - //llvm::errs() << "REFERENCE TYPE POINTEE TYPE AS WRITTEN: " << clava::getId(T->getPointeeTypeAsWritten(), id) << "\n"; -//llvm::errs() << "REFERENCE TYPE POINTEE TYPE: " << clava::getId(T->getPointeeType(), id) << "\n"; - // Visit pointee and pointee as written type - -// VisitTypeTop(T->getPointeeTypeAsWritten()); -// visitedChildren.push_back(clava::getId(T->getPointeeTypeAsWritten(), id)); - -// VisitTypeTop(T->getPointeeType()); -// visitedChildren.push_back(clava::getId(T->getPointeeType(), id)); } -void ClangAstDumper::VisitInjectedClassNameTypeChildren(const InjectedClassNameType *T, std::vector &visitedChildren) { +void ClangAstDumper::VisitInjectedClassNameTypeChildren( + const InjectedClassNameType *T, std::vector &visitedChildren) { // Hierarchy VisitTypeChildren(T, visitedChildren); @@ -321,8 +293,8 @@ void ClangAstDumper::VisitInjectedClassNameTypeChildren(const InjectedClassNameT VisitDeclTop(T->getDecl()); } - -void ClangAstDumper::VisitTemplateTypeParmTypeChildren(const TemplateTypeParmType *T, std::vector &visitedChildren) { +void ClangAstDumper::VisitTemplateTypeParmTypeChildren( + const TemplateTypeParmType *T, std::vector &visitedChildren) { // Hierarchy VisitTypeChildren(T, visitedChildren); @@ -330,56 +302,48 @@ void ClangAstDumper::VisitTemplateTypeParmTypeChildren(const TemplateTypeParmTyp VisitDeclTop(T->getDecl()); } -/* -void ClangAstDumper::VisitTypedefTypeChildren(const TypedefType *T, std::vector &visitedChildren) { +void ClangAstDumper::VisitSubstTemplateTypeParmTypeChildren( + const SubstTemplateTypeParmType *T, + std::vector &visitedChildren) { // Hierarchy VisitTypeChildren(T, visitedChildren); - -}; -*/ - -void ClangAstDumper::VisitSubstTemplateTypeParmTypeChildren(const SubstTemplateTypeParmType *T, std::vector &visitedChildren){ - // Hierarchy - VisitTypeChildren(T, visitedChildren); - - //addChild(T->getReplacedParameter(), visitedChildren); - //addChild(T->getReplacementType(), visitedChildren); VisitTypeTop(T->getReplacedParameter()); VisitTypeTop(T->getReplacementType()); }; -void ClangAstDumper::VisitTemplateSpecializationTypeChildren(const TemplateSpecializationType *T, std::vector &visitedChildren){ +void ClangAstDumper::VisitTemplateSpecializationTypeChildren( + const TemplateSpecializationType *T, + std::vector &visitedChildren) { // Hierarchy VisitTypeChildren(T, visitedChildren); // Visit each argument - for(unsigned i=0; igetNumArgs(); i++) { + for (unsigned i = 0; i < T->getNumArgs(); i++) { VisitTemplateArgChildren(T->getArg(i)); } // Visit type alias - if(T->isTypeAlias()) { + if (T->isTypeAlias()) { VisitTypeTop(T->getAliasedType()); } // Visit template delc, if present VisitDeclTop(T->getTemplateName().getAsTemplateDecl()); - }; -void ClangAstDumper::VisitTypedefTypeChildren(const TypedefType *T, std::vector &visitedChildren){ +void ClangAstDumper::VisitTypedefTypeChildren( + const TypedefType *T, std::vector &visitedChildren) { // Hierarchy VisitTypeChildren(T, visitedChildren); - VisitDeclTop(T->getDecl()); VisitTypeTop(T->getPointeeType()); }; - -void ClangAstDumper::VisitAdjustedTypeChildren(const AdjustedType *T, std::vector &visitedChildren){ +void ClangAstDumper::VisitAdjustedTypeChildren( + const AdjustedType *T, std::vector &visitedChildren) { // Hierarchy VisitTypeChildren(T, visitedChildren); @@ -390,7 +354,8 @@ void ClangAstDumper::VisitAdjustedTypeChildren(const AdjustedType *T, std::vecto VisitTypeTop(T->getAdjustedType()); }; -void ClangAstDumper::VisitDecayedTypeChildren(const DecayedType *T, std::vector &visitedChildren){ +void ClangAstDumper::VisitDecayedTypeChildren( + const DecayedType *T, std::vector &visitedChildren) { // Hierarchy VisitAdjustedTypeChildren(T, visitedChildren); @@ -399,52 +364,51 @@ void ClangAstDumper::VisitDecayedTypeChildren(const DecayedType *T, std::vector< VisitTypeTop(T->getPointeeType()); }; -void ClangAstDumper::VisitDecltypeTypeChildren(const DecltypeType *T, std::vector &visitedChildren){ +void ClangAstDumper::VisitDecltypeTypeChildren( + const DecltypeType *T, std::vector &visitedChildren) { // Hierarchy VisitTypeChildren(T, visitedChildren); VisitStmtTop(T->getUnderlyingExpr()); }; -void ClangAstDumper::VisitAutoTypeChildren(const AutoType *T, std::vector &visitedChildren){ +void ClangAstDumper::VisitAutoTypeChildren( + const AutoType *T, std::vector &visitedChildren) { // Hierarchy VisitTypeChildren(T, visitedChildren); VisitTypeTop(T->getDeducedType()); }; - - -void ClangAstDumper::VisitPackExpansionTypeChildren(const PackExpansionType *T, std::vector &visitedChildren){ +void ClangAstDumper::VisitPackExpansionTypeChildren( + const PackExpansionType *T, std::vector &visitedChildren) { // Hierarchy VisitTypeChildren(T, visitedChildren); - if(!T->isSugared()) { + if (!T->isSugared()) { VisitTypeTop(T->getPattern()); } - }; -void ClangAstDumper::VisitTypeOfExprTypeChildren(const TypeOfExprType *T, std::vector &visitedChildren){ +void ClangAstDumper::VisitTypeOfExprTypeChildren( + const TypeOfExprType *T, std::vector &visitedChildren) { // Hierarchy VisitTypeChildren(T, visitedChildren); - VisitStmtTop(T->getUnderlyingExpr()); - }; - -void ClangAstDumper::VisitAttributedTypeChildren(const AttributedType *T, std::vector &visitedChildren){ +void ClangAstDumper::VisitAttributedTypeChildren( + const AttributedType *T, std::vector &visitedChildren) { // Hierarchy VisitTypeChildren(T, visitedChildren); VisitTypeTop(T->getModifiedType()); VisitTypeTop(T->getEquivalentType()); - }; -void ClangAstDumper::VisitUnaryTransformTypeChildren(const UnaryTransformType *T, std::vector &visitedChildren){ +void ClangAstDumper::VisitUnaryTransformTypeChildren( + const UnaryTransformType *T, std::vector &visitedChildren) { // Hierarchy VisitTypeChildren(T, visitedChildren); @@ -452,17 +416,10 @@ void ClangAstDumper::VisitUnaryTransformTypeChildren(const UnaryTransformType *T VisitTypeTop(T->getBaseType()); }; -void ClangAstDumper::VisitComplexTypeChildren(const ComplexType *T, std::vector &visitedChildren){ +void ClangAstDumper::VisitComplexTypeChildren( + const ComplexType *T, std::vector &visitedChildren) { // Hierarchy VisitTypeChildren(T, visitedChildren); VisitTypeTop(T->getElementType()); }; - - - - - - - - diff --git a/ClangAstDumper/src/Clang/ClangAst.cpp b/ClangAstDumper/src/Clang/ClangAst.cpp index 739e92a86..d8cc00d37 100644 --- a/ClangAstDumper/src/Clang/ClangAst.cpp +++ b/ClangAstDumper/src/Clang/ClangAst.cpp @@ -2,7 +2,8 @@ // // Created by JoaoBispo // -// Based on public domain code by Eli Bendersky (eliben@gmail.com) - http://eli.thegreenplace.net/ +// Based on public domain code by Eli Bendersky (eliben@gmail.com) - +// http://eli.thegreenplace.net/ //------------------------------------------------------------------------------ #include "ClangAst.h" #include "../ClangAstDumper/ClangAstDumperConstants.h" @@ -10,33 +11,27 @@ #include "clang/AST/AST.h" #include "clang/AST/ASTConsumer.h" +#include "clang/AST/Comment.h" #include "clang/AST/RecursiveASTVisitor.h" +#include "clang/AST/Stmt.h" #include "clang/Basic/TargetInfo.h" #include "clang/Frontend/ASTConsumers.h" -#include "clang/Frontend/FrontendActions.h" #include "clang/Frontend/CompilerInstance.h" -#include "clang/AST/Comment.h" -#include "clang/AST/Stmt.h" +#include "clang/Frontend/FrontendActions.h" #include "clang/Lex/Lexer.h" #include "clang/Lex/Preprocessor.h" - -#include -#include #include +#include +#include #include #include - - using namespace clang; - static llvm::cl::OptionCategory ToolingSampleCategory("Tooling Sample"); - -static constexpr const char* const PREFIX = "COUNTER"; - +static constexpr const char *const PREFIX = "COUNTER"; /* DumpAstVisitor implementation */ @@ -47,160 +42,158 @@ bool DumpAstVisitor::TraverseDecl(Decl *D) { // Top-level Node llvm::errs() << TOP_LEVEL_NODES << "\n"; llvm::errs() << D << "_" << id << "\n"; - } return false; - } +PrintNodesTypesRelationsVisitor::PrintNodesTypesRelationsVisitor( + ASTContext *Context, int id, ClangAstDumper dumper) + : Context(Context), id(id), dumper(dumper){}; - - - - -PrintNodesTypesRelationsVisitor::PrintNodesTypesRelationsVisitor(ASTContext *Context, int id, ClangAstDumper dumper) : Context(Context), id(id), dumper(dumper) {}; - -static std::string stmt2str(clang::Stmt *d, clang::SourceManager *sm, clang::LangOptions lopt) { +static std::string stmt2str(clang::Stmt *d, clang::SourceManager *sm, + clang::LangOptions lopt) { clang::SourceLocation b(d->getBeginLoc()), _e(d->getEndLoc()); - clang::SourceLocation e(clang::Lexer::getLocForEndOfToken(_e, 0, *sm, lopt)); + clang::SourceLocation e( + clang::Lexer::getLocForEndOfToken(_e, 0, *sm, lopt)); return std::string(sm->getCharacterData(b), - sm->getCharacterData(e)-sm->getCharacterData(b)); + sm->getCharacterData(e) - sm->getCharacterData(b)); } - static std::string loc2str(SourceLocation locStart, SourceLocation locEnd, ASTContext *Context) { - clang::SourceManager *sm = &Context->getSourceManager(); - clang::LangOptions lopt = Context->getLangOpts(); - - clang::SourceLocation b(locStart), _e(locEnd); - clang::SourceLocation e(clang::Lexer::getLocForEndOfToken(_e, 0, *sm, lopt)); - return std::string(sm->getCharacterData(b), sm->getCharacterData(e)-sm->getCharacterData(b)); - } +static std::string loc2str(SourceLocation locStart, SourceLocation locEnd, + ASTContext *Context) { + clang::SourceManager *sm = &Context->getSourceManager(); + clang::LangOptions lopt = Context->getLangOpts(); - bool PrintNodesTypesRelationsVisitor::VisitCXXConstructExpr(CXXConstructExpr * D) { + clang::SourceLocation b(locStart), _e(locEnd); + clang::SourceLocation e( + clang::Lexer::getLocForEndOfToken(_e, 0, *sm, lopt)); + return std::string(sm->getCharacterData(b), + sm->getCharacterData(e) - sm->getCharacterData(b)); +} - FullSourceLoc fullLocation = Context->getFullLoc(D->getBeginLoc()); - if (fullLocation.isValid() && !fullLocation.isInSystemHeader()) { +bool PrintNodesTypesRelationsVisitor::VisitCXXConstructExpr( + CXXConstructExpr *D) { - // Check if temporary object - if(D->isTemporaryObject(D->getConstructor()->getASTContext(), D->getConstructor()->getParent())) { - DumpResources::is_temporary << D << "_" << id << "\n"; - } + FullSourceLoc fullLocation = Context->getFullLoc(D->getBeginLoc()); + if (fullLocation.isValid() && !fullLocation.isInSystemHeader()) { + // Check if temporary object + if (D->isTemporaryObject(D->getConstructor()->getASTContext(), + D->getConstructor()->getParent())) { + DumpResources::is_temporary << D << "_" << id << "\n"; } - - - return true; } - // Dump types for Expr, TypeDecl and ValueDecl, as well as the connection between them - bool PrintNodesTypesRelationsVisitor::VisitExpr(Expr *D) { - return true; - } - - bool PrintNodesTypesRelationsVisitor::VisitTypeDecl(TypeDecl *D) { - return true; - } - - /** - * Typedefs will be visited by 'VisitTypeDecl' but will null, this override extracts the correct information for typedefs - * @param D - * @return - */ - bool PrintNodesTypesRelationsVisitor::VisitTypedefNameDecl(TypedefNameDecl *D) { - return true; - } + return true; +} +// Dump types for Expr, TypeDecl and ValueDecl, as well as the connection +// between them +bool PrintNodesTypesRelationsVisitor::VisitExpr(Expr *D) { return true; } - bool PrintNodesTypesRelationsVisitor::VisitEnumDecl(EnumDecl *D) { - FullSourceLoc fullLocation = Context->getFullLoc(D->getBeginLoc()); - if (fullLocation.isValid() && !fullLocation.isInSystemHeader()) { - //if(D->getIntegerType().isNull()) { - // llvm::errs() << "VisitEnum null type\n"; - //} - dumpNodeToType(DumpResources::enum_integer_type, D,D->getIntegerType(), false); +bool PrintNodesTypesRelationsVisitor::VisitTypeDecl(TypeDecl *D) { + return true; +} - } +/** + * Typedefs will be visited by 'VisitTypeDecl' but will null, this override + * extracts the correct information for typedefs + * @param D + * @return + */ +bool PrintNodesTypesRelationsVisitor::VisitTypedefNameDecl(TypedefNameDecl *D) { + return true; +} - return true; +bool PrintNodesTypesRelationsVisitor::VisitEnumDecl(EnumDecl *D) { + FullSourceLoc fullLocation = Context->getFullLoc(D->getBeginLoc()); + if (fullLocation.isValid() && !fullLocation.isInSystemHeader()) { + dumpNodeToType(DumpResources::enum_integer_type, D, D->getIntegerType(), + false); } + return true; +} +bool PrintNodesTypesRelationsVisitor::VisitValueDecl(ValueDecl *D) { + return true; +} - bool PrintNodesTypesRelationsVisitor::VisitValueDecl(ValueDecl *D) { - return true; - } - - // Visit only nodes from the source code, ignore system headers - bool PrintNodesTypesRelationsVisitor::VisitDecl(Decl *D) { - FullSourceLoc fullLocation = Context->getFullLoc(D->getBeginLoc()); - - if (fullLocation.isValid() && !fullLocation.isInSystemHeader()) { - dumper.VisitDeclTop(D); - //dumper->VisitDeclTop(D); - return true; - } +// Visit only nodes from the source code, ignore system headers +bool PrintNodesTypesRelationsVisitor::VisitDecl(Decl *D) { + FullSourceLoc fullLocation = Context->getFullLoc(D->getBeginLoc()); + if (fullLocation.isValid() && !fullLocation.isInSystemHeader()) { + dumper.VisitDeclTop(D); return true; } - bool PrintNodesTypesRelationsVisitor::VisitStmt(Stmt *D) { - FullSourceLoc fullLocation = Context->getFullLoc(D->getBeginLoc()); + return true; +} - if (fullLocation.isValid() && !fullLocation.isInSystemHeader()) { - dumper.VisitStmtTop(D); - //dumper->VisitStmtTop(D); - return true; - } +bool PrintNodesTypesRelationsVisitor::VisitStmt(Stmt *D) { + FullSourceLoc fullLocation = Context->getFullLoc(D->getBeginLoc()); + if (fullLocation.isValid() && !fullLocation.isInSystemHeader()) { + dumper.VisitStmtTop(D); return true; } - bool PrintNodesTypesRelationsVisitor::VisitLambdaExpr(LambdaExpr *D) { - return true; - } + return true; +} +bool PrintNodesTypesRelationsVisitor::VisitLambdaExpr(LambdaExpr *D) { + return true; +} -void PrintNodesTypesRelationsVisitor::dumpNodeToType(std::ofstream &stream, void* nodeAddr, const QualType& type, bool checkDuplicates) { +void PrintNodesTypesRelationsVisitor::dumpNodeToType(std::ofstream &stream, + void *nodeAddr, + const QualType &type, + bool checkDuplicates) { // Opaque pointer, so that we can obtain the qualifiers - void* typeAddr = !type.isNull() ? type.getAsOpaquePtr() : nullptr; + void *typeAddr = !type.isNull() ? type.getAsOpaquePtr() : nullptr; - if(checkDuplicates) { - if(seenNodes.count(nodeAddr) == 0) { - stream << nodeAddr << "_" << id << "->" << typeAddr << "_" << id << "\n"; + if (checkDuplicates) { + if (seenNodes.count(nodeAddr) == 0) { + stream << nodeAddr << "_" << id << "->" << typeAddr << "_" << id + << "\n"; seenNodes.insert(nodeAddr); } } else { - stream << nodeAddr << "_" << id << "->" << typeAddr << "_" << id << "\n"; + stream << nodeAddr << "_" << id << "->" << typeAddr << "_" << id + << "\n"; } - dumper.VisitTypeTop(type); } +void PrintNodesTypesRelationsVisitor::dumpNodeToType(std::ofstream &stream, + void *nodeAddr, + const Type *typeAddr, + bool checkDuplicates) { - void PrintNodesTypesRelationsVisitor::dumpNodeToType(std::ofstream &stream, void* nodeAddr, const Type* typeAddr, bool checkDuplicates) { - - if(!typeAddr) { + if (!typeAddr) { return; } - - if(checkDuplicates) { - if(seenNodes.count(nodeAddr) == 0) { - stream << nodeAddr << "_" << id << "->" << typeAddr << "_" << id << "\n"; + if (checkDuplicates) { + if (seenNodes.count(nodeAddr) == 0) { + stream << nodeAddr << "_" << id << "->" << typeAddr << "_" << id + << "\n"; seenNodes.insert(nodeAddr); } } else { - stream << nodeAddr << "_" << id << "->" << typeAddr << "_" << id << "\n"; + stream << nodeAddr << "_" << id << "->" << typeAddr << "_" << id + << "\n"; } dumper.VisitTypeTop(typeAddr); } -MyASTConsumer::MyASTConsumer(ASTContext *C, int id, ClangAstDumper dumper) : id(id) - ,topLevelDeclVisitor(C, id), printRelationsVisitor(C, id, dumper) { +MyASTConsumer::MyASTConsumer(ASTContext *C, int id, ClangAstDumper dumper) + : id(id), topLevelDeclVisitor(C, id), printRelationsVisitor(C, id, dumper) { std::ofstream consumer; consumer.open("consumer_order.txt", std::ofstream::app); @@ -208,202 +201,195 @@ MyASTConsumer::MyASTConsumer(ASTContext *C, int id, ClangAstDumper dumper) : id( consumer.close(); } - MyASTConsumer::~MyASTConsumer() { - std::ofstream consumer; - consumer.open("consumer_order.txt", std::ofstream::app); - consumer << "ASTConsumer destroyed " << id << "\n"; - consumer.close(); - } - - - - - // Override the method that gets called for each parsed top-level declaration. - bool MyASTConsumer::HandleTopLevelDecl(DeclGroupRef DR) { - - for (DeclGroupRef::iterator b = DR.begin(), e = DR.end(); b != e; ++b) { - // Traverse the declaration using our AST visitor. - topLevelDeclVisitor.TraverseDecl(*b); - } - +MyASTConsumer::~MyASTConsumer() { + std::ofstream consumer; + consumer.open("consumer_order.txt", std::ofstream::app); + consumer << "ASTConsumer destroyed " << id << "\n"; + consumer.close(); +} - for (DeclGroupRef::iterator b = DR.begin(), e = DR.end(); b != e; ++b) { - printRelationsVisitor.TraverseDecl(*b); - } +// Override the method that gets called for each parsed top-level declaration. +bool MyASTConsumer::HandleTopLevelDecl(DeclGroupRef DR) { - return true; + for (DeclGroupRef::iterator b = DR.begin(), e = DR.end(); b != e; ++b) { + // Traverse the declaration using our AST visitor. + topLevelDeclVisitor.TraverseDecl(*b); } - void MyASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { - + for (DeclGroupRef::iterator b = DR.begin(), e = DR.end(); b != e; ++b) { + printRelationsVisitor.TraverseDecl(*b); } + return true; +} +void MyASTConsumer::HandleTranslationUnit(ASTContext &Ctx) {} +// Not sure if Clang performs compilation of different translation units in +// parallel, using atomic just in case. +std::atomic GLOBAL_COUNTER(1); - // Not sure if Clang performs compilation of different translation units in parallel, using atomic just in case. - std::atomic GLOBAL_COUNTER(1); - - - - /*** DumpAstAction ***/ - - // For each source file provided to the tool, a new FrontendAction is created. - std::unique_ptr DumpAstAction::CreateASTConsumer(CompilerInstance &CI, StringRef file) { - int counter = GLOBAL_COUNTER.fetch_add(1); - - // If runId greater than 0, use it instead of global counter - if(DumpResources::runId > 0) { - counter = DumpResources::runId; - } - - - dumpCompilerInstanceData(CI, file); - - // Dump id->file data - llvm::errs() << ID_FILE_MAP << "\n"; - llvm::errs() << counter << "\n"; - llvm::errs() << file << "\n"; - - ASTContext *Context = &CI.getASTContext(); - - ClangAstDumper dumper(Context, counter, DumpResources::systemHeaderThreshold); - - return std::make_unique(Context, counter, dumper); - } - - - void DumpAstAction::dumpCompilerInstanceData(CompilerInstance &CI, StringRef file) { - clava::dump(COMPILER_INSTANCE_DATA); - - clava::dump(file.str()); - - clava::dump(CI.getInvocation().getLangOpts()->LineComment); - // Derived from Std.isC89 in Clang 3.8 - clava::dump(CI.getInvocation().getLangOpts()->GNUInline); - clava::dump(CI.getInvocation().getLangOpts()->C99); - clava::dump(CI.getInvocation().getLangOpts()->C11); - clava::dump(CI.getInvocation().getLangOpts()->CPlusPlus); - clava::dump(CI.getInvocation().getLangOpts()->CPlusPlus11); - clava::dump(CI.getInvocation().getLangOpts()->CPlusPlus14); - clava::dump(CI.getInvocation().getLangOpts()->CPlusPlus17); - clava::dump(CI.getInvocation().getLangOpts()->Digraphs); - clava::dump(CI.getInvocation().getLangOpts()->GNUMode); - clava::dump(CI.getInvocation().getLangOpts()->HexFloats); - clava::dump(CI.getInvocation().getLangOpts()->ImplicitInt); - - clava::dump(CI.getInvocation().getLangOpts()->OpenCL); - clava::dump(CI.getInvocation().getLangOpts()->OpenCLVersion); - clava::dump(CI.getInvocation().getLangOpts()->NativeHalfType); - - clava::dump(CI.getInvocation().getLangOpts()->CUDA); - - clava::dump(CI.getInvocation().getLangOpts()->Bool); - clava::dump(CI.getInvocation().getLangOpts()->Half); - clava::dump(CI.getInvocation().getLangOpts()->WChar); - - clava::dump(CI.getTarget().getCharWidth()); - clava::dump(CI.getTarget().getFloatWidth()); - clava::dump(CI.getTarget().getDoubleWidth()); - clava::dump(CI.getTarget().getLongDoubleWidth()); - clava::dump(CI.getTarget().getBoolWidth()); - clava::dump(CI.getTarget().getShortWidth()); - clava::dump(CI.getTarget().getIntWidth()); - clava::dump(CI.getTarget().getLongWidth()); - clava::dump(CI.getTarget().getLongLongWidth()); - } - - - /*** DumpIncludesAction ***/ - // Based on explanation from this website https://xaizek.github.io/2015-04-23/detecting-wrong-first-include/ - void DumpIncludesAction::ExecuteAction() { +/*** DumpAstAction ***/ - IncludeDumper includeDumper(getCompilerInstance()); - getCompilerInstance().getPreprocessor().addPPCallbacks( - includeDumper.createPreprocessorCallbacks() - ); +// For each source file provided to the tool, a new FrontendAction is created. +std::unique_ptr +DumpAstAction::CreateASTConsumer(CompilerInstance &CI, StringRef file) { + int counter = GLOBAL_COUNTER.fetch_add(1); - PreprocessOnlyAction::ExecuteAction(); + // If runId greater than 0, use it instead of global counter + if (DumpResources::runId > 0) { + counter = DumpResources::runId; } + dumpCompilerInstanceData(CI, file); + // Dump id->file data + llvm::errs() << ID_FILE_MAP << "\n"; + llvm::errs() << counter << "\n"; + llvm::errs() << file << "\n"; - /*** IncludeDumper ***/ + ASTContext *Context = &CI.getASTContext(); - IncludeDumper::IncludeDumper(CompilerInstance &compilerInstance) : compilerInstance(compilerInstance), sm(compilerInstance.getSourceManager()) {}; + ClangAstDumper dumper(Context, counter, + DumpResources::systemHeaderThreshold); + return std::make_unique(Context, counter, dumper); +} - std::unique_ptr IncludeDumper::createPreprocessorCallbacks() { - return std::unique_ptr(new CallbacksProxy(*this)); - } +void DumpAstAction::dumpCompilerInstanceData(CompilerInstance &CI, + StringRef file) { + clava::dump(COMPILER_INSTANCE_DATA); + + clava::dump(file.str()); + + clava::dump(CI.getInvocation().getLangOpts()->LineComment); + // Derived from Std.isC89 in Clang 3.8 + clava::dump(CI.getInvocation().getLangOpts()->GNUInline); + clava::dump(CI.getInvocation().getLangOpts()->C99); + clava::dump(CI.getInvocation().getLangOpts()->C11); + clava::dump(CI.getInvocation().getLangOpts()->CPlusPlus); + clava::dump(CI.getInvocation().getLangOpts()->CPlusPlus11); + clava::dump(CI.getInvocation().getLangOpts()->CPlusPlus14); + clava::dump(CI.getInvocation().getLangOpts()->CPlusPlus17); + clava::dump(CI.getInvocation().getLangOpts()->Digraphs); + clava::dump(CI.getInvocation().getLangOpts()->GNUMode); + clava::dump(CI.getInvocation().getLangOpts()->HexFloats); + clava::dump(CI.getInvocation().getLangOpts()->ImplicitInt); + + clava::dump(CI.getInvocation().getLangOpts()->OpenCL); + clava::dump(CI.getInvocation().getLangOpts()->OpenCLVersion); + clava::dump(CI.getInvocation().getLangOpts()->NativeHalfType); + + clava::dump(CI.getInvocation().getLangOpts()->CUDA); + + clava::dump(CI.getInvocation().getLangOpts()->Bool); + clava::dump(CI.getInvocation().getLangOpts()->Half); + clava::dump(CI.getInvocation().getLangOpts()->WChar); + + clava::dump(CI.getTarget().getCharWidth()); + clava::dump(CI.getTarget().getFloatWidth()); + clava::dump(CI.getTarget().getDoubleWidth()); + clava::dump(CI.getTarget().getLongDoubleWidth()); + clava::dump(CI.getTarget().getBoolWidth()); + clava::dump(CI.getTarget().getShortWidth()); + clava::dump(CI.getTarget().getIntWidth()); + clava::dump(CI.getTarget().getLongWidth()); + clava::dump(CI.getTarget().getLongLongWidth()); +} - void IncludeDumper::InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, - StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { - - - if (!sm.isInSystemHeader(HashLoc)) { - // Includes information in stream - llvm::errs() << INCLUDES << "\n"; - // Source - llvm::errs() << sm.getFilename(HashLoc).str() << "\n"; - llvm::errs() << FileName.str() << "\n"; - llvm::errs() << sm.getSpellingLineNumber(HashLoc) << "\n"; - llvm::errs() << IsAngled << "\n"; - } - } +/*** DumpIncludesAction ***/ +// Based on explanation from this website +// https://xaizek.github.io/2015-04-23/detecting-wrong-first-include/ +void DumpIncludesAction::ExecuteAction() { + IncludeDumper includeDumper(getCompilerInstance()); + getCompilerInstance().getPreprocessor().addPPCallbacks( + includeDumper.createPreprocessorCallbacks()); - void IncludeDumper::PragmaDirective(SourceLocation Loc, PragmaIntroducerKind Introducer) { + PreprocessOnlyAction::ExecuteAction(); +} - - // Ignore system headers - if(sm.isInSystemHeader(Loc)) { - return; - } +/*** IncludeDumper ***/ - // Pragma location - clava::dump(PRAGMA); - clava::dump(sm.getFilename(Loc)); - clava::dump(sm.getSpellingLineNumber(Loc)); - clava::dump(sm.getSpellingColumnNumber(Loc)); - } +IncludeDumper::IncludeDumper(CompilerInstance &compilerInstance) + : compilerInstance(compilerInstance), + sm(compilerInstance.getSourceManager()){}; - void IncludeDumper::FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID) { +std::unique_ptr IncludeDumper::createPreprocessorCallbacks() { + return std::unique_ptr(new CallbacksProxy(*this)); +} +void IncludeDumper::InclusionDirective( + SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, + bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, + StringRef SearchPath, StringRef RelativePath, const Module *Imported, + SrcMgr::CharacteristicKind FileType) { + + if (!sm.isInSystemHeader(HashLoc)) { + // Includes information in stream + llvm::errs() << INCLUDES << "\n"; + // Source + llvm::errs() << sm.getFilename(HashLoc).str() << "\n"; + llvm::errs() << FileName.str() << "\n"; + llvm::errs() << sm.getSpellingLineNumber(HashLoc) << "\n"; + llvm::errs() << IsAngled << "\n"; } +} - void IncludeDumper::MacroExpands(const Token & MacroNameTok, const MacroDefinition & MD, SourceRange Range, const MacroArgs * Args) { +void IncludeDumper::PragmaDirective(SourceLocation Loc, + PragmaIntroducerKind Introducer) { + // Ignore system headers + if (sm.isInSystemHeader(Loc)) { + return; } + // Pragma location + clava::dump(PRAGMA); + clava::dump(sm.getFilename(Loc)); + clava::dump(sm.getSpellingLineNumber(Loc)); + clava::dump(sm.getSpellingColumnNumber(Loc)); +} +void IncludeDumper::FileChanged(SourceLocation Loc, FileChangeReason Reason, + SrcMgr::CharacteristicKind FileType, + FileID PrevFID) {} - /*** CallbacksProxy ***/ - - CallbacksProxy::CallbacksProxy(IncludeDumper &original) : original(original) { - } +void IncludeDumper::MacroExpands(const Token &MacroNameTok, + const MacroDefinition &MD, SourceRange Range, + const MacroArgs *Args) {} - void CallbacksProxy::InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, - StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { +/*** CallbacksProxy ***/ - original.InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled, FilenameRange, File, SearchPath, RelativePath, Imported, FileType); - } +CallbacksProxy::CallbacksProxy(IncludeDumper &original) : original(original) {} - void CallbacksProxy::MacroExpands(const Token & MacroNameTok, const MacroDefinition & MD, SourceRange Range, const MacroArgs * Args) { - original.MacroExpands(MacroNameTok, MD, Range, Args); - } +void CallbacksProxy::InclusionDirective( + SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, + bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, + StringRef SearchPath, StringRef RelativePath, const Module *Imported, + SrcMgr::CharacteristicKind FileType) { - void CallbacksProxy::PragmaDirective(SourceLocation Loc, PragmaIntroducerKind Introducer) { - original.PragmaDirective(Loc, Introducer); - } + original.InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled, + FilenameRange, File, SearchPath, RelativePath, + Imported, FileType); +} - void CallbacksProxy::FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID) { - original.FileChanged(Loc, Reason, FileType, PrevFID); - } +void CallbacksProxy::MacroExpands(const Token &MacroNameTok, + const MacroDefinition &MD, SourceRange Range, + const MacroArgs *Args) { + original.MacroExpands(MacroNameTok, MD, Range, Args); +} +void CallbacksProxy::PragmaDirective(SourceLocation Loc, + PragmaIntroducerKind Introducer) { + original.PragmaDirective(Loc, Introducer); +} +void CallbacksProxy::FileChanged(SourceLocation Loc, FileChangeReason Reason, + SrcMgr::CharacteristicKind FileType, + FileID PrevFID) { + original.FileChanged(Loc, Reason, FileType, PrevFID); +} /** * DumpResources Implementations @@ -420,7 +406,6 @@ std::ofstream DumpResources::types_with_templates; int DumpResources::runId; int DumpResources::systemHeaderThreshold; - void DumpResources::writeCounter(int id) { // Output is processed with a line iterator, allows multiple-line processing @@ -430,7 +415,6 @@ void DumpResources::writeCounter(int id) { llvm::errs() << PREFIX << "\n"; llvm::errs() << id << "\n"; - } void DumpResources::init(int runId, int systemLevelThreshold) { @@ -438,11 +422,16 @@ void DumpResources::init(int runId, int systemLevelThreshold) { DumpResources::runId = runId; DumpResources::systemHeaderThreshold = systemLevelThreshold; - DumpResources::is_temporary.open("is_temporary.txt", std::ofstream::out | std::ofstream::trunc); - DumpResources::omp.open("omp.txt", std::ofstream::out | std::ofstream::trunc); - DumpResources::enum_integer_type.open("enum_integer_type.txt", std::ofstream::out | std::ofstream::trunc); - DumpResources::consumer_order.open("consumer_order.txt", std::ofstream::out | std::ofstream::trunc); - DumpResources::types_with_templates.open("types_with_templates.txt", std::ofstream::out | std::ofstream::trunc); + DumpResources::is_temporary.open("is_temporary.txt", + std::ofstream::out | std::ofstream::trunc); + DumpResources::omp.open("omp.txt", + std::ofstream::out | std::ofstream::trunc); + DumpResources::enum_integer_type.open( + "enum_integer_type.txt", std::ofstream::out | std::ofstream::trunc); + DumpResources::consumer_order.open( + "consumer_order.txt", std::ofstream::out | std::ofstream::trunc); + DumpResources::types_with_templates.open( + "types_with_templates.txt", std::ofstream::out | std::ofstream::trunc); } void DumpResources::finish() { diff --git a/ClangAstDumper/src/Clang/ClangAst.h b/ClangAstDumper/src/Clang/ClangAst.h index 6e758ea3a..c6738f2b7 100644 --- a/ClangAstDumper/src/Clang/ClangAst.h +++ b/ClangAstDumper/src/Clang/ClangAst.h @@ -29,7 +29,6 @@ class DumpResources { static std::ofstream includes; static std::ofstream nodetypes; - // static std::ofstream template_args; static std::ofstream is_temporary; static std::ofstream omp; static std::ofstream enum_integer_type; @@ -123,8 +122,6 @@ class DumpAstAction : public PluginASTAction { class DumpAstVisitor : public RecursiveASTVisitor { public: - // explicit DumpAstVisitor(ASTContext *Context, int id, ClangAstDumper - // *dumper) : Context(Context) , id(id), dumper(dumper) {} explicit DumpAstVisitor(ASTContext *Context, int id) : Context(Context), id(id) {} bool TraverseDecl(Decl *D); @@ -132,8 +129,6 @@ class DumpAstVisitor : public RecursiveASTVisitor { private: ASTContext *Context; int id; - // ClangAstDumper dumper; - // ClangAstDumper *dumper; }; class PrintNodesTypesRelationsVisitor @@ -143,18 +138,11 @@ class PrintNodesTypesRelationsVisitor ASTContext *Context; int id; ClangAstDumper dumper; - // ClangAstDumper *dumper; std::set seenNodes; public: - // explicit PrintNodesTypesRelationsVisitor(ASTContext *Context, int id, - // ClangAstDumper *dumper); explicit PrintNodesTypesRelationsVisitor(ASTContext *Context, int id, ClangAstDumper dumper); - // bool TraverseDecl(Decl *D); - - // bool VisitOMPExecutableDirective(OMPExecutableDirective * D); - // bool VisitDeclRefExpr(DeclRefExpr * D); bool VisitCXXConstructExpr(CXXConstructExpr *D); bool VisitExpr(Expr *D); bool VisitLambdaExpr(LambdaExpr *D); @@ -178,8 +166,6 @@ class PrintNodesTypesRelationsVisitor void dumpNodeToType(std::ofstream &stream, void *nodeAddr, const QualType &type, bool checkDuplicates = true); - - // ClangAstDumper getDumper(); }; // Implementation of the ASTConsumer interface for reading an AST produced by @@ -188,13 +174,11 @@ class MyASTConsumer : public ASTConsumer { private: int id; - // ClangAstDumper dumper; DumpAstVisitor topLevelDeclVisitor; PrintNodesTypesRelationsVisitor printRelationsVisitor; public: MyASTConsumer(ASTContext *C, int id, ClangAstDumper dumper); - // MyASTConsumer(ASTContext *C, int id, ClangAstDumper *dumper); ~MyASTConsumer(); bool HandleTopLevelDecl(DeclGroupRef DR) override; diff --git a/ClangAstDumper/src/Clang/ClangNodes.cpp b/ClangAstDumper/src/Clang/ClangNodes.cpp index 782f01482..abe130581 100644 --- a/ClangAstDumper/src/Clang/ClangNodes.cpp +++ b/ClangAstDumper/src/Clang/ClangNodes.cpp @@ -5,120 +5,92 @@ #include "ClangNodes.h" #include "../ClangEnums/ClangEnums.h" -#include "clang/Lex/Lexer.h" #include "clang/AST/Attr.h" #include "clang/Basic/SourceManager.h" - +#include "clang/Lex/Lexer.h" #include #include using namespace clang; -const std::string clava::getClassName(const Decl* D) { +const std::string clava::getClassName(const Decl *D) { const std::string kindName = D->getDeclKindName(); return kindName + "Decl"; } -const std::string clava::getClassName(const Stmt* S) { +const std::string clava::getClassName(const Stmt *S) { const std::string className = S->getStmtClassName(); return className; } -const std::string clava::getClassName(const Type* T) { +const std::string clava::getClassName(const Type *T) { const std::string kindName = T->getTypeClassName(); return kindName + "Type"; } -const std::string clava::getAttrKind(const Attr* A) { - // Print information about Attr - //clava::dump(clava::ATTRIBUTES[A->getKind()]); +const std::string clava::getAttrKind(const Attr *A) { { switch (A->getKind()) { #define ATTR(X) \ - case attr::X: \ - return #X; \ - break; + case attr::X: \ + return #X; \ + break; #include "clang/Basic/AttrList.inc" } - } return ""; } -const std::string clava::getClassName(const Attr* A) { - - //const std::string kindName = clava::ATTRIBUTES[A->getKind()]; - const std::string kindName = clava::getAttrKind(A); +const std::string clava::getClassName(const Attr *A) { + const std::string kindName = clava::getAttrKind(A); return kindName + "Attr"; } - -void clava::dumpSourceRange(ASTContext *Context, SourceLocation startLoc, SourceLocation endLoc) { - //llvm::errs() << "\n"; - - //llvm::errs() << id << "\n"; - +void clava::dumpSourceRange(ASTContext *Context, SourceLocation startLoc, + SourceLocation endLoc) { // All components of the source range will be dumped - const SourceManager& SM = Context->getSourceManager(); + const SourceManager &SM = Context->getSourceManager(); SourceLocation startSpellingLoc = SM.getSpellingLoc(startLoc); - //PresumedLoc startPLoc = SM.getPresumedLoc(startSpellingLoc); - if(startSpellingLoc.isInvalid()) { - //if (startPLoc.isInvalid()) { + if (startSpellingLoc.isInvalid()) { llvm::errs() << "\n"; return; } - // Dump start location llvm::errs() << SM.getFilename(startSpellingLoc) << "\n"; llvm::errs() << SM.getSpellingLineNumber(startSpellingLoc) << "\n"; llvm::errs() << SM.getSpellingColumnNumber(startSpellingLoc) << "\n"; -// llvm::errs() << startPLoc.getFilename() << "\n"; -// llvm::errs() << startPLoc.getLine() << "\n"; -// llvm::errs() << startPLoc.getColumn() << "\n"; - // ISMACRO: Temporarily disabled - //llvm::errs() << startLoc.isMacroID() << "\n"; - - - if(startLoc == endLoc) { + if (startLoc == endLoc) { llvm::errs() << "\n"; return; } SourceLocation endSpellingLoc = SM.getSpellingLoc(endLoc); - //PresumedLoc endPLoc = SM.getPresumedLoc(endSpellingLoc); - if(endSpellingLoc.isInvalid()) { - //if(endPLoc.isInvalid()) { + if (endSpellingLoc.isInvalid()) { + // if(endPLoc.isInvalid()) { llvm::errs() << "\n"; return; } - //const char* endFilename = endPLoc.getFilename(); StringRef endFilename = SM.getFilename(endSpellingLoc); - //if(!endFilename) { - if(endFilename.size() == 0) { + if (endFilename.size() == 0) { endFilename = SM.getFilename(startSpellingLoc); - //endFilename = startPLoc.getFilename(); } - //unsigned int endLine = endPLoc.getLine(); unsigned int endLine = SM.getSpellingLineNumber(endSpellingLoc); - if(!endLine) { - //endLine = startPLoc.getLine(); + if (!endLine) { endLine = SM.getSpellingLineNumber(startSpellingLoc); } - //unsigned int endCol = endPLoc.getColumn(); unsigned int endCol = SM.getSpellingColumnNumber(endSpellingLoc); - if(!endCol) { - //endCol = startPLoc.getColumn(); + if (!endCol) { endCol = SM.getSpellingColumnNumber(startSpellingLoc); } @@ -126,314 +98,215 @@ void clava::dumpSourceRange(ASTContext *Context, SourceLocation startLoc, Source llvm::errs() << endFilename << "\n"; llvm::errs() << endLine << "\n"; llvm::errs() << endCol << "\n"; - - // ISMACRO: Temporarily disabled - //llvm::errs() << endLoc.isMacroID() << "\n"; } -void clava::dumpSourceInfo(ASTContext *Context, SourceLocation begin, SourceLocation end) { - +void clava::dumpSourceInfo(ASTContext *Context, SourceLocation begin, + SourceLocation end) { // Original source range - //clava::dumpSourceRange(Context, begin, end); - clava::dumpSourceRange(Context, Context->getSourceManager().getExpansionLoc(begin), Context->getSourceManager().getExpansionLoc(end)); + clava::dumpSourceRange(Context, + Context->getSourceManager().getExpansionLoc(begin), + Context->getSourceManager().getExpansionLoc(end)); // ISMACRO: Disable this when updating // If it is a macro bool isMacro = begin.isMacroID() || end.isMacroID(); clava::dump(isMacro); -// bool beginIsMacro = begin.isMacroID(); -// bool endIsMacro = end.isMacroID(); -// clava::dump(beginIsMacro); -// clava::dump(endIsMacro); - - // ISMACRO: Disable this when updating + // ISMACRO: Disable this when updating // Spelling location, if macro - if(isMacro) { - clava::dumpSourceRange(Context, Context->getSourceManager().getSpellingLoc(begin), Context->getSourceManager().getSpellingLoc(end)); + if (isMacro) { + clava::dumpSourceRange( + Context, Context->getSourceManager().getSpellingLoc(begin), + Context->getSourceManager().getSpellingLoc(end)); } // If is in system header FullSourceLoc fullLocation = Context->getFullLoc(begin); - if (fullLocation.isValid() && fullLocation.isInSystemHeader()) { clava::dump(true); } else { clava::dump(false); } - - //clava::dumpSourceRange(Context, Context->getFullLoc(begin).getExpansionLoc(), Context->getFullLoc(end).getExpansionLoc()); - //clava::dumpSourceRange(Context, Context->getSourceManager().getImmediateMacroCallerLoc(begin), Context->getSourceManager().getImmediateMacroCallerLoc(end)); - //clava::dumpSourceRange(Context, Context->getSourceManager().getExpansionLoc(begin), Context->getSourceManager().getExpansionLoc(end)); - - //Context->getSourceManager().getCharacterData(begin) - //const char *getCharacterData(SourceLocation SL, bool *Invalid = nullptr) const; - // Original source range - } - -const std::string clava::getId(const void* addr, int id) { - //if(addr == nullptr || addr == 0) { - // return "nullptr"; - //} - +const std::string clava::getId(const void *addr, int id) { std::stringstream ss; - ss << addr << "_" << id; + ss << addr << "_" << id; return ss.str(); } -const std::string clava::getId(const Decl* addr, int id) { - if(addr == nullptr) { +const std::string clava::getId(const Decl *addr, int id) { + if (addr == nullptr) { return "nullptr_decl"; } - return getId((void*) addr, id); + return getId((void *)addr, id); } -/* -const std::string clava::getId(Decl* addr, int id) { - return getId(const_cast(addr), id); -} - */ -const std::string clava::getId(const Stmt* addr, int id) { - if(addr == nullptr) { +const std::string clava::getId(const Stmt *addr, int id) { + if (addr == nullptr) { return "nullptr_stmt"; } - return getId((void*) addr, id); + return getId((void *)addr, id); } -const std::string clava::getId(const Expr* addr, int id) { - if(addr == nullptr) { +const std::string clava::getId(const Expr *addr, int id) { + if (addr == nullptr) { return "nullptr_expr"; } - return getId((void*) addr, id); + return getId((void *)addr, id); } -const std::string clava::getId(Optional addr, int id) { - if(!addr.hasValue()) { +const std::string clava::getId(Optional addr, int id) { + if (!addr.hasValue()) { return "nullptr_expr"; } return getId(addr.getValue(), id); } - - -const std::string clava::getId(const Type* addr, int id) { - if(addr == nullptr) { +const std::string clava::getId(const Type *addr, int id) { + if (addr == nullptr) { return "nullptr_type"; } - return getId((void*) addr, id); + return getId((void *)addr, id); } const std::string clava::getId(const QualType &addr, int id) { - if(addr.isNull()) { + if (addr.isNull()) { return "nullptr_type"; } return getId(addr.getAsOpaquePtr(), id); } -const std::string clava::getId(const Attr* addr, int id) { - if(addr == nullptr) { +const std::string clava::getId(const Attr *addr, int id) { + if (addr == nullptr) { return "nullptr_attr"; } - return getId((void*) addr, id); -} - - -void clava::dump(bool boolean) { - llvm::errs() << boolean << "\n"; + return getId((void *)addr, id); } -void clava::dump(int integer) { - llvm::errs() << integer << "\n"; -} - -void clava::dump(double aDouble) { - llvm::errs() << aDouble << "\n"; -} +void clava::dump(bool boolean) { llvm::errs() << boolean << "\n"; } -void clava::dump(unsigned int integer) { - llvm::errs() << integer << "\n"; -} +void clava::dump(int integer) { llvm::errs() << integer << "\n"; } -void clava::dumpSize(size_t integer) { - llvm::errs() << integer << "\n"; -} - -void clava::dump(const std::string& string) { - llvm::errs() << string << "\n"; -} +void clava::dump(double aDouble) { llvm::errs() << aDouble << "\n"; } +void clava::dump(unsigned int integer) { llvm::errs() << integer << "\n"; } +void clava::dumpSize(size_t integer) { llvm::errs() << integer << "\n"; } +void clava::dump(const std::string &string) { llvm::errs() << string << "\n"; } void clava::dump(const llvm::StringRef string) { llvm::errs() << string << "\n"; } -void clava::dump(const char string[]) { - dump(std::string(string)); -} +void clava::dump(const char string[]) { dump(std::string(string)); } void clava::dump(const std::vector &strings) { // Number of attributes dump((unsigned int)strings.size()); // Dump each attribute address - for(auto string : strings) { + for (auto string : strings) { dump(string); } } -void clava::dump(const std::vector &attributes, const int id) { +void clava::dump(const std::vector &attributes, const int id) { // Number of attributes dump((unsigned int)attributes.size()); // Dump each attribute address - for(auto attr : attributes) { + for (auto attr : attributes) { dump(clava::getId(attr, id)); dump(attr->isImplicit()); dump(attr->isInherited()); dump(attr->isLateParsed()); dump(attr->isPackExpansion()); } -/* - // Dump each attribute - for(auto attr : attributes) { - dump(clava::ATTRIBUTES[attr->getKind()]); - dump(attr->isImplicit()); - dump(attr->isInherited()); - dump(attr->isLateParsed()); - dump(attr->isPackExpansion()); - } -*/ } - -void clava::dump(const QualType& type, int id) { -/* - if(type.isNull()) { - dump("nullptr"); - } -*/ - //dump(getId(type.getTypePtr(), id)); - // QUALTYPE EXP - //dump(getId(type.getAsOpaquePtr(), id)); +void clava::dump(const QualType &type, int id) { + // QUALTYPE EXP dump(getId(type, id)); - - // Check if QualType is the same as the underlying type - /* - if((void*) type.getTypePtr() == type.getAsOpaquePtr()) { - - llvm::errs() << "QualType " << getId(type.getAsOpaquePtr(), id) << " opaque ptr and type ptr are the same\n"; - } else { - llvm::errs() << "QualType " << getId(type.getAsOpaquePtr(), id) << " type ptr is different -> " << getId(type.getTypePtr(), id) << "\n"; - } - */ - - // Dump QualType - /* - if(dumpType(T)) { - return; - } - */ - - - - } -void clava::dump(const Qualifiers& qualifiers, ASTContext* Context) { +void clava::dump(const Qualifiers &qualifiers, ASTContext *Context) { auto c99Qualifiers = qualifiers.getCVRQualifiers(); const int numBits = std::numeric_limits::digits; size_t numSetBits = std::bitset(c99Qualifiers).count(); // Dumps the number of C99 qualifiers, and then the name of the qualifiers - clava::dump((int) numSetBits); - if(qualifiers.hasConst()) {clava::dump("CONST");} - if(qualifiers.hasRestrict()) { - //if(Context->getPrintingPolicy().LangOpts.C99) // LLVM 3.8 - if(Context->getPrintingPolicy().Restrict) + clava::dump((int)numSetBits); + if (qualifiers.hasConst()) { + clava::dump("CONST"); + } + if (qualifiers.hasRestrict()) { + if (Context->getPrintingPolicy().Restrict) clava::dump("RESTRICT_C99"); else clava::dump("RESTRICT"); } - if(qualifiers.hasVolatile()) {clava::dump("VOLATILE");} - + if (qualifiers.hasVolatile()) { + clava::dump("VOLATILE"); + } } - - /** - * Taken from: https://stackoverflow.com/questions/11083066/getting-the-source-behind-clangs-ast + * Taken from: + * https://stackoverflow.com/questions/11083066/getting-the-source-behind-clangs-ast * @param Context * @param start * @param end * @return */ -const std::string clava::getSource(ASTContext *Context, SourceRange sourceRange) { +const std::string clava::getSource(ASTContext *Context, + SourceRange sourceRange) { // Mark beginning of source clava::dump("%CLAVA_SOURCE_BEGIN%"); - //const SourceManager &sm = Context->getSourceManager(); - - /* - - clang::SourceLocation b(start), _e(end); - - clang::SourceLocation e(clang::Lexer::getLocForEndOfToken(_e, 0, sm, Context->getLangOpts())); - - return std::string(sm.getCharacterData(b), - sm.getCharacterData(e)-sm.getCharacterData(b)); -*/ - // (T, U) => "T,," - const SourceManager &sm = Context->getSourceManager(); - SourceLocation begin = sourceRange.getBegin(); SourceLocation end = sourceRange.getEnd(); if (begin.isMacroID()) { - //llvm::errs() << "Begin is macro:" << begin.printToString(sm) << "\n"; begin = sm.getSpellingLoc(begin); - //llvm::errs() << "Begin spelling loc:" << begin.printToString(sm) << "\n"; } else { - //llvm::errs() << "Begin is not macro:" << begin.printToString(sm) << "\n"; } if (end.isMacroID()) { - //llvm::errs() << "End is macro:" << end.printToString(sm) << "\n"; end = sm.getSpellingLoc(end); - //llvm::errs() << "End spelling loc:" << end.printToString(sm) << "\n"; } else { - //llvm::errs() << "End is not macro:" << begin.printToString(sm) << "\n"; } - - - std::string text = Lexer::getSourceText(CharSourceRange::getTokenRange(begin, end), sm, LangOptions(), 0).str(); - if (text.size() > 0 && (text.at(text.size()-1) == ',')) { //the text can be "" - std::string otherText = Lexer::getSourceText(CharSourceRange::getCharRange(begin, end), sm, LangOptions(), 0).str(); - return otherText + "\n%CLAVA_SOURCE_END%"; + std::string text = + Lexer::getSourceText(CharSourceRange::getTokenRange(begin, end), sm, + LangOptions(), 0) + .str(); + if (text.size() > 0 && + (text.at(text.size() - 1) == ',')) { // the text can be "" + std::string otherText = + Lexer::getSourceText(CharSourceRange::getCharRange(begin, end), sm, + LangOptions(), 0) + .str(); + return otherText + "\n%CLAVA_SOURCE_END%"; } return text + "\n%CLAVA_SOURCE_END%"; - - } -void clava::dump(NestedNameSpecifier* qualifier, ASTContext* Context) { +void clava::dump(NestedNameSpecifier *qualifier, ASTContext *Context) { // Dump qualifier if (qualifier != nullptr) { @@ -446,220 +319,182 @@ void clava::dump(NestedNameSpecifier* qualifier, ASTContext* Context) { } } -void clava::dump(NestedNameSpecifier* qualifier, int id) { +void clava::dump(NestedNameSpecifier *qualifier, int id) { auto qualifierKind = qualifier->getKind(); // Dump name clava::dump(clava::NESTED_NAMED_SPECIFIER[qualifier->getKind()]); - switch(qualifierKind) { -// case clang::NestedNameSpecifier::Identifier: -// break; - case clang::NestedNameSpecifier::Namespace: - clava::dump(getId(qualifier->getAsNamespace(), id)); - break; - case clang::NestedNameSpecifier::NamespaceAlias: - clava::dump(getId(qualifier->getAsNamespaceAlias(), id)); - break; - case clang::NestedNameSpecifier::TypeSpec: - clava::dump(getId(qualifier->getAsType(), id)); - break; - case clang::NestedNameSpecifier::TypeSpecWithTemplate: - clava::dump(getId(qualifier->getAsType(), id)); - break; - case clang::NestedNameSpecifier::Global: - break; - case clang::NestedNameSpecifier::Super: - clava::dump(getId(qualifier->getAsRecordDecl(), id)); - break; - default: - throw std::invalid_argument( - "ClangNodes::dump(NestedNameSpecifier):: Case not implemented, '" + clava::NESTED_NAMED_SPECIFIER[qualifier->getKind()] + "'"); - } -} - - -void clava::dump(const TemplateArgument &templateArg, int id, ASTContext* Context) { + switch (qualifierKind) { + case clang::NestedNameSpecifier::Namespace: + clava::dump(getId(qualifier->getAsNamespace(), id)); + break; + case clang::NestedNameSpecifier::NamespaceAlias: + clava::dump(getId(qualifier->getAsNamespaceAlias(), id)); + break; + case clang::NestedNameSpecifier::TypeSpec: + clava::dump(getId(qualifier->getAsType(), id)); + break; + case clang::NestedNameSpecifier::TypeSpecWithTemplate: + clava::dump(getId(qualifier->getAsType(), id)); + break; + case clang::NestedNameSpecifier::Global: + break; + case clang::NestedNameSpecifier::Super: + clava::dump(getId(qualifier->getAsRecordDecl(), id)); + break; + default: + throw std::invalid_argument( + "ClangNodes::dump(NestedNameSpecifier):: Case not implemented, '" + + clava::NESTED_NAMED_SPECIFIER[qualifier->getKind()] + "'"); + } +} + +void clava::dump(const TemplateArgument &templateArg, int id, + ASTContext *Context) { SmallString<0> str; clava::dump(clava::TEMPLATE_ARG_KIND[templateArg.getKind()]); switch (templateArg.getKind()) { - case TemplateArgument::ArgKind::Type: - clava::dump(clava::getId(templateArg.getAsType(), id)); - break; - case TemplateArgument::ArgKind::Expression: - clava::dump(clava::getId(templateArg.getAsExpr(), id)); - break; - case TemplateArgument::ArgKind::Pack: - clava::dump(templateArg.pack_size()); - for (auto currentArg = templateArg.pack_begin(), endArg = templateArg.pack_end(); - currentArg != endArg; ++currentArg) { - clava::dump(*currentArg, id, Context); - } - break; - case TemplateArgument::ArgKind::Integral: - templateArg.getAsIntegral().toString(str, 10); - clava::dump(str); - break; - case TemplateArgument::ArgKind::Template: - clava::dump(templateArg.getAsTemplate(), id, Context); - break; - /* - { - TemplateName templateName = templateArg.getAsTemplate(); - - - break; + case TemplateArgument::ArgKind::Type: + clava::dump(clava::getId(templateArg.getAsType(), id)); + break; + case TemplateArgument::ArgKind::Expression: + clava::dump(clava::getId(templateArg.getAsExpr(), id)); + break; + case TemplateArgument::ArgKind::Pack: + clava::dump(templateArg.pack_size()); + for (auto currentArg = templateArg.pack_begin(), + endArg = templateArg.pack_end(); + currentArg != endArg; ++currentArg) { + clava::dump(*currentArg, id, Context); } - */ - //case TemplateArgument::ArgKind::Qualified - default: - throw std::invalid_argument("ClangNodes::dump(TemplateArgument&): Case not implemented, '" + - clava::TEMPLATE_ARG_KIND[templateArg.getKind()] + "' (" + std::to_string(templateArg.getKind()) +")"); - } -} - -void clava::dump(const TemplateName &templateName, int id, ASTContext* Context) { - clava::dump(clava::TEMPLATE_NAME_KIND[templateName.getKind()]); + break; + case TemplateArgument::ArgKind::Integral: + templateArg.getAsIntegral().toString(str, 10); + clava::dump(str); + break; + case TemplateArgument::ArgKind::Template: + clava::dump(templateArg.getAsTemplate(), id, Context); + break; - switch(templateName.getKind()) { - case TemplateName::NameKind::Template: - clava::dump(clava::getId(templateName.getAsTemplateDecl(), id)); - break; - case TemplateName::NameKind::QualifiedTemplate: - clava::dump(templateName.getAsQualifiedTemplateName()->getQualifier(), Context); - clava::dump(templateName.getAsQualifiedTemplateName()->hasTemplateKeyword()); - clava::dump(clava::getId(templateName.getAsQualifiedTemplateName()->getTemplateDecl(), id)); - break; - case TemplateName::NameKind::SubstTemplateTemplateParm: - clava::dump(clava::getId(templateName.getAsSubstTemplateTemplateParm()->getParameter(), id)); - clava::dump(templateName.getAsSubstTemplateTemplateParm()->getReplacement(), id, Context); - break; - default: - throw std::invalid_argument("ClangNodes::dump(TemplateName&): TemplateName case in kind 'Template' not implemented, '" + - clava::TEMPLATE_NAME_KIND[templateName.getKind()] + "'"); + default: + throw std::invalid_argument( + "ClangNodes::dump(TemplateArgument&): Case not implemented, '" + + clava::TEMPLATE_ARG_KIND[templateArg.getKind()] + "' (" + + std::to_string(templateArg.getKind()) + ")"); } } +void clava::dump(const TemplateName &templateName, int id, + ASTContext *Context) { + clava::dump(clava::TEMPLATE_NAME_KIND[templateName.getKind()]); - -void clava::dump(const CXXBaseSpecifier& base, int id) { - clava::dump(base.isVirtual()); - clava::dump(base.isPackExpansion()); - clava::dump(ACCESS_SPECIFIER[base.getAccessSpecifierAsWritten()]); - clava::dump(ACCESS_SPECIFIER[base.getAccessSpecifier()]); - clava::dump(clava::getId(base.getType(), id)); -} - -/* -void dump(Consumer consumer) { - std::string string; - llvm::raw_string_ostream stream(string); - consumer.apply(stream); - clava::dump(stream.str()); -} -*/ - -void clava::dump(std::function dumper) { + switch (templateName.getKind()) { + case TemplateName::NameKind::Template: + clava::dump(clava::getId(templateName.getAsTemplateDecl(), id)); + break; + case TemplateName::NameKind::QualifiedTemplate: + clava::dump(templateName.getAsQualifiedTemplateName()->getQualifier(), + Context); + clava::dump( + templateName.getAsQualifiedTemplateName()->hasTemplateKeyword()); + clava::dump(clava::getId( + templateName.getAsQualifiedTemplateName()->getTemplateDecl(), id)); + break; + case TemplateName::NameKind::SubstTemplateTemplateParm: + clava::dump(clava::getId( + templateName.getAsSubstTemplateTemplateParm()->getParameter(), id)); + clava::dump( + templateName.getAsSubstTemplateTemplateParm()->getReplacement(), id, + Context); + break; + default: + throw std::invalid_argument( + "ClangNodes::dump(TemplateName&): TemplateName case in kind " + "'Template' not implemented, '" + + clava::TEMPLATE_NAME_KIND[templateName.getKind()] + "'"); + } +} + +void clava::dump(const CXXBaseSpecifier &base, int id) { + clava::dump(base.isVirtual()); + clava::dump(base.isPackExpansion()); + clava::dump(ACCESS_SPECIFIER[base.getAccessSpecifierAsWritten()]); + clava::dump(ACCESS_SPECIFIER[base.getAccessSpecifier()]); + clava::dump(clava::getId(base.getType(), id)); +} + +void clava::dump(std::function dumper) { // Example of call to this function: - // clava::dump([&T](llvm::raw_string_ostream& stream){T->getTemplateName().dump(stream);}); + // clava::dump([&T](llvm::raw_string_ostream& + // stream){T->getTemplateName().dump(stream);}); std::string string; llvm::raw_string_ostream stream(string); dumper(stream); clava::dump(stream.str()); - } -/* -void clava::dump(const TemplateName& templateName) { - - //dump(stream -> templateName.(stream)); - - std::string string; - llvm::raw_string_ostream stream(string); - templateName.dump(stream); - clava::dump(stream.str()); -} - */ - - -/* -llvm::raw_ostream clava::stringStream() { - std::string stringStream; - llvm::raw_string_ostream llvmStringStream(stringStream); - return llvmStringStream; -} - */ -/* -void clava::dump(llvm::raw_string_ostream llvmStringStream) { - dump(llvmStringStream.str()); -} -*/ - -bool clava::isSystemHeader(const Stmt* S, ASTContext* Context) { +bool clava::isSystemHeader(const Stmt *S, ASTContext *Context) { FullSourceLoc fullLocation = Context->getFullLoc(S->getBeginLoc()); return fullLocation.isValid() && fullLocation.isInSystemHeader(); } - -bool clava::isSystemHeader(const Decl* D, ASTContext* Context) { +bool clava::isSystemHeader(const Decl *D, ASTContext *Context) { FullSourceLoc fullLocation = Context->getFullLoc(D->getBeginLoc()); return fullLocation.isValid() && fullLocation.isInSystemHeader(); } /** - * Taken from here: https://stackoverflow.com/questions/874134/find-if-string-ends-with-another-string-in-c#874160 + * Taken from here: + * https://stackoverflow.com/questions/874134/find-if-string-ends-with-another-string-in-c#874160 * * @param str * @param suffix * @return */ -static bool endsWith(const std::string& str, const std::string& suffix) -{ - return str.size() >= suffix.size() && 0 == str.compare(str.size()-suffix.size(), suffix.size(), suffix); +static bool endsWith(const std::string &str, const std::string &suffix) { + return str.size() >= suffix.size() && + 0 == str.compare(str.size() - suffix.size(), suffix.size(), suffix); } /** - * Taken from here: https://stackoverflow.com/questions/874134/find-if-string-ends-with-another-string-in-c#874160 + * Taken from here: + * https://stackoverflow.com/questions/874134/find-if-string-ends-with-another-string-in-c#874160 * * @param str * @param prefix * @return */ -static bool startsWith(const std::string& str, const std::string& prefix) -{ - return str.size() >= prefix.size() && 0 == str.compare(0, prefix.size(), prefix); +static bool startsWith(const std::string &str, const std::string &prefix) { + return str.size() >= prefix.size() && + 0 == str.compare(0, prefix.size(), prefix); } const std::string clava::getQualifiedPrefix(const NamedDecl *D) { const std::string qualifiedName = D->getQualifiedNameAsString(); const std::string declName = D->getDeclName().getAsString(); - //llvm::errs() << "QUALIFIED NAME: " << qualifiedName << "\n"; - //llvm::errs() << "DECL NAME: " << declName << "\n"; - // If declName is empty, return empty string - if(declName.empty()) { + if (declName.empty()) { return ""; } // If declName is the same as the qualified name, return empty string - if(declName == qualifiedName) { + if (declName == qualifiedName) { return ""; } - - // Remove decl name and :: from qualified name const std::string expectedSuffix = "::" + declName; - if(!endsWith(qualifiedName, expectedSuffix)) { - std::string message = "ClangNodes::getQualifiedPrefix(const NamedDecl *): Expected string '" + qualifiedName + - "' to have the suffix '" + expectedSuffix + "'"; + if (!endsWith(qualifiedName, expectedSuffix)) { + std::string message = "ClangNodes::getQualifiedPrefix(const NamedDecl " + "*): Expected string '" + + qualifiedName + "' to have the suffix '" + + expectedSuffix + "'"; throw std::invalid_argument(message); - //throw std::invalid_argument("ClangNodes::getQualifiedPrefix(const NamedDecl *): Expected string '"+qualifiedName+"' to have the suffix '" + - // expectedSuffix + "'"); } int endIndex = qualifiedName.length() - declName.length() - 2; @@ -667,50 +502,51 @@ const std::string clava::getQualifiedPrefix(const NamedDecl *D) { return qualifiedName.substr(0, endIndex); } -void clava::dump(const clang::DesignatedInitExpr::Designator* designator) { +void clava::dump(const clang::DesignatedInitExpr::Designator *designator) { - if(designator->isFieldDesignator()) { + if (designator->isFieldDesignator()) { // Dump kind clava::dump(clava::DESIGNATOR_KIND[0]); clava::dump(designator->getFieldName()->getName()); - } else if(designator->isArrayDesignator()) { + } else if (designator->isArrayDesignator()) { // Dump kind clava::dump(clava::DESIGNATOR_KIND[1]); clava::dump(designator->getFirstExprIndex()); - } else if(designator->isArrayRangeDesignator()) { + } else if (designator->isArrayRangeDesignator()) { // Dump kind clava::dump(clava::DESIGNATOR_KIND[2]); clava::dump(designator->getFirstExprIndex()); } else { - throw std::invalid_argument("ClangNodes::dump(const clang::DesignatedInitExpr::Designator*): Case not implemented"); + throw std::invalid_argument( + "ClangNodes::dump(const clang::DesignatedInitExpr::Designator*): " + "Case not implemented"); } } - -void clava::dump(const ExplicitSpecifier& specifier, int id) { +void clava::dump(const ExplicitSpecifier &specifier, int id) { clava::dump(clava::EXPLICIT_SPEC_KIND, specifier.getKind()); - //clava::dump(specifier.getExpr()); clava::dump(clava::getId(specifier.getExpr(), id)); clava::dump(specifier.isSpecified()); } - -void clava::throwNotImplemented(const std::string& source, const std::string& caseNotImplemented, ASTContext* Context, SourceLocation startLoc, SourceLocation endLoc) { +void clava::throwNotImplemented(const std::string &source, + const std::string &caseNotImplemented, + ASTContext *Context, SourceLocation startLoc, + SourceLocation endLoc) { llvm::errs() << "Dumping source range of code that caused exception:\n"; clava::dumpSourceRange(Context, startLoc, endLoc); - throw std::invalid_argument(source + ": Case not implemented, '" + caseNotImplemented + "', source range has been dumped"); - + throw std::invalid_argument(source + ": Case not implemented, '" + + caseNotImplemented + + "', source range has been dumped"); } - - -void clava::throwNotImplemented(const std::string& source, const std::string& caseNotImplemented, ASTContext* Context, SourceRange range) { - throw std::invalid_argument(source + ": Case not implemented, '" + caseNotImplemented + "', source code that triggered the problem:\n" + clava::getSource(Context, range)); +void clava::throwNotImplemented(const std::string &source, + const std::string &caseNotImplemented, + ASTContext *Context, SourceRange range) { + throw std::invalid_argument(source + ": Case not implemented, '" + + caseNotImplemented + + "', source code that triggered the problem:\n" + + clava::getSource(Context, range)); } - - - - - diff --git a/ClangAstDumper/src/Clang/ClangNodes.h b/ClangAstDumper/src/Clang/ClangNodes.h index d081c8758..32586a482 100644 --- a/ClangAstDumper/src/Clang/ClangNodes.h +++ b/ClangAstDumper/src/Clang/ClangNodes.h @@ -7,152 +7,149 @@ #include "clang/AST/AST.h" #include "clang/AST/Decl.h" -#include "clang/AST/Stmt.h" -#include "clang/AST/Type.h" #include "clang/AST/Expr.h" #include "clang/AST/NestedNameSpecifier.h" +#include "clang/AST/Stmt.h" #include "clang/AST/TemplateName.h" +#include "clang/AST/Type.h" - -#include -#include -#include #include +#include +#include #include - +#include using namespace clang; namespace clava { - /** - * Returns the name of the class of the given Decl. - * @param D - * @return - */ - const std::string getClassName(const Decl* D); - - /** - * Returns the name of the class of the given Stmt. - * @param S - * @return - */ - const std::string getClassName(const Stmt* S); - - /** - * Returns the name of the class of the given Type. - * - * @param T - * @return - */ - const std::string getClassName(const Type* T); - - /** - * Returns the kind name of the class of the given Attribute. - * - * @param A - * @return - */ - const std::string getAttrKind(const Attr* A); - - - /** - * Returns the name of the class of the given Attribute. - * - * @param A - * @return - */ - const std::string getClassName(const Attr* A); - - /** - * Dumps the source range. - * - * @param Context - * @param startLoc - * @param endLoc - */ - void dumpSourceRange(ASTContext *Context, SourceLocation startLoc, SourceLocation endLoc); - - /** - * Dumps info related to the source code (original source location, if it is a macro, spelling source location...) - * @param Context - * @param startLoc - * @param endLoc - */ - void dumpSourceInfo(ASTContext *Context, SourceLocation startLoc, SourceLocation endLoc); - - /** - * Builds a string id. - * - * @param addr - * @param id - * @return - */ - const std::string getId(const Decl* addr, int id); - //const std::string getId(Decl* addr, int id); - const std::string getId(const Stmt* addr, int id); - const std::string getId(const Expr* addr, int id); - const std::string getId(Optional addr, int id); - const std::string getId(const Type* addr, int id); - const std::string getId(const QualType &addr, int id); - const std::string getId(const Attr* addr, int id); - - /** - * Should only be used internally by functions of this include. - * @param addr - * @param id - * @return - */ - const std::string getId(const void* addr, int id); - - /** - * - * @param Context - * @param sourceRange - * @return the source code corresponding to the given sourceRange - */ - const std::string getSource(ASTContext *Context, SourceRange sourceRange); - - //llvm::raw_ostream stringStream(); - - - // Value dumpers - void dump(bool boolean); - void dump(int integer); - void dump(double integer); - void dump(unsigned int integer); - void dumpSize(size_t integer); - void dump(const std::string& string); - void dump(const llvm::StringRef string); - void dump(const char string[]); - void dump(const std::vector &strings); - void dump(const std::vector &attributes, const int id); - void dump(const QualType& type, int id); - void dump(const Qualifiers& qualifiers, ASTContext* Context); - void dump(NestedNameSpecifier* qualifier, int id); - void dump(NestedNameSpecifier* qualifier, ASTContext* Context); - void dump(const TemplateArgument& templateArg, int id, ASTContext* Context); - void dump(const TemplateName &templateName, int id, ASTContext* Context); - void dump(const CXXBaseSpecifier& base, int id); - //void dump(const TemplateName& templateName); - void dump(std::function dumper); - void dump(const clang::DesignatedInitExpr::Designator* designator); - void dump(const ExplicitSpecifier& specifier, int id); - - void throwNotImplemented(const std::string& source, const std::string& caseNotImplemented, ASTContext* Context, SourceLocation startLoc, SourceLocation endLoc); - void throwNotImplemented(const std::string& source, const std::string& caseNotImplemented, ASTContext* Context, SourceRange range); - - template - void dump(const std::string* enumValues, E e) { dump(enumValues[static_cast>(e)]); - } - - bool isSystemHeader(const Stmt* S, ASTContext* context); - bool isSystemHeader(const Decl* S, ASTContext* context); - // void dump(llvm::raw_string_ostream llvmStringStream); - - - const std::string getQualifiedPrefix(const NamedDecl *D); +/** + * Returns the name of the class of the given Decl. + * @param D + * @return + */ +const std::string getClassName(const Decl *D); + +/** + * Returns the name of the class of the given Stmt. + * @param S + * @return + */ +const std::string getClassName(const Stmt *S); + +/** + * Returns the name of the class of the given Type. + * + * @param T + * @return + */ +const std::string getClassName(const Type *T); + +/** + * Returns the kind name of the class of the given Attribute. + * + * @param A + * @return + */ +const std::string getAttrKind(const Attr *A); + +/** + * Returns the name of the class of the given Attribute. + * + * @param A + * @return + */ +const std::string getClassName(const Attr *A); + +/** + * Dumps the source range. + * + * @param Context + * @param startLoc + * @param endLoc + */ +void dumpSourceRange(ASTContext *Context, SourceLocation startLoc, + SourceLocation endLoc); + +/** + * Dumps info related to the source code (original source location, if it is a + * macro, spelling source location...) + * @param Context + * @param startLoc + * @param endLoc + */ +void dumpSourceInfo(ASTContext *Context, SourceLocation startLoc, + SourceLocation endLoc); + +/** + * Builds a string id. + * + * @param addr + * @param id + * @return + */ +const std::string getId(const Decl *addr, int id); +const std::string getId(const Stmt *addr, int id); +const std::string getId(const Expr *addr, int id); +const std::string getId(Optional addr, int id); +const std::string getId(const Type *addr, int id); +const std::string getId(const QualType &addr, int id); +const std::string getId(const Attr *addr, int id); + +/** + * Should only be used internally by functions of this include. + * @param addr + * @param id + * @return + */ +const std::string getId(const void *addr, int id); + +/** + * + * @param Context + * @param sourceRange + * @return the source code corresponding to the given sourceRange + */ +const std::string getSource(ASTContext *Context, SourceRange sourceRange); + +// Value dumpers +void dump(bool boolean); +void dump(int integer); +void dump(double integer); +void dump(unsigned int integer); +void dumpSize(size_t integer); +void dump(const std::string &string); +void dump(const llvm::StringRef string); +void dump(const char string[]); +void dump(const std::vector &strings); +void dump(const std::vector &attributes, const int id); +void dump(const QualType &type, int id); +void dump(const Qualifiers &qualifiers, ASTContext *Context); +void dump(NestedNameSpecifier *qualifier, int id); +void dump(NestedNameSpecifier *qualifier, ASTContext *Context); +void dump(const TemplateArgument &templateArg, int id, ASTContext *Context); +void dump(const TemplateName &templateName, int id, ASTContext *Context); +void dump(const CXXBaseSpecifier &base, int id); +void dump(std::function dumper); +void dump(const clang::DesignatedInitExpr::Designator *designator); +void dump(const ExplicitSpecifier &specifier, int id); + +void throwNotImplemented(const std::string &source, + const std::string &caseNotImplemented, + ASTContext *Context, SourceLocation startLoc, + SourceLocation endLoc); +void throwNotImplemented(const std::string &source, + const std::string &caseNotImplemented, + ASTContext *Context, SourceRange range); + +template void dump(const std::string *enumValues, E e) { + dump(enumValues[static_cast>(e)]); +} +bool isSystemHeader(const Stmt *S, ASTContext *context); +bool isSystemHeader(const Decl *S, ASTContext *context); -} +const std::string getQualifiedPrefix(const NamedDecl *D); + +} // namespace clava -#endif //CLANGASTDUMPER_CLANGNODES_H +#endif // CLANGASTDUMPER_CLANGNODES_H diff --git a/ClangAstDumper/src/ClangAstDumper/ClangAstDumper.cpp b/ClangAstDumper/src/ClangAstDumper/ClangAstDumper.cpp index 1fbe5f3f7..9dd4585da 100644 --- a/ClangAstDumper/src/ClangAstDumper/ClangAstDumper.cpp +++ b/ClangAstDumper/src/ClangAstDumper/ClangAstDumper.cpp @@ -3,710 +3,518 @@ // #include "ClangAstDumper.h" -#include "ClangAstDumperConstants.h" #include "../Clang/ClangNodes.h" #include "../ClangEnums/ClangEnums.h" +#include "ClangAstDumperConstants.h" -//#include "clang/AST/AST.h" #include "clang/Lex/Lexer.h" #include "clang/Basic/SourceManager.h" - #include #include #include -//#define DEBUG +// #define DEBUG -//#define VISIT_CHECK +// #define VISIT_CHECK using namespace clang; -//ClangAstDumper::ClangAstDumper(ASTContext *Context, const ASTContext& constContext, int id, int systemHeaderThreshold) : Context(Context), constContext(constContext), id(id), -ClangAstDumper::ClangAstDumper(ASTContext *Context, int id, int systemHeaderThreshold) : Context(Context), id(id), - systemHeaderThreshold(systemHeaderThreshold), dataDumper(Context, id) {}; +ClangAstDumper::ClangAstDumper(ASTContext *Context, int id, + int systemHeaderThreshold) + : Context(Context), id(id), systemHeaderThreshold(systemHeaderThreshold), + dataDumper(Context, id){}; // This method is equivalent to a VisitQualType() in ClangAstDumperTypes.cpp -void ClangAstDumper::VisitTypeTop(const QualType& T) { +void ClangAstDumper::VisitTypeTop(const QualType &T) { - if(T.isNull()) { - return; - } - -/* - auto singleStepDesugar = T.getSingleStepDesugaredType(*Context); - if(singleStepDesugar != T) { - VisitTypeTop(singleStepDesugar); - } -*/ + if (T.isNull()) { + return; + } - // Check if QualType is the same as the underlying type - if((void*) T.getTypePtr() == T.getAsOpaquePtr()) { + // Check if QualType is the same as the underlying type + if ((void *)T.getTypePtr() == T.getAsOpaquePtr()) { #ifdef VISIT_CHECK - clava::dump(TOP_VISIT_START); - clava::dump(clava::getId(T.getTypePtr(), id)); -#endif - -/* - if(dumpType(T.getTypePtr())) { - return; - } -*/ - // TODO: AST dump method relies on visiting the nodes multiple times - // For now, detect it to avoid visiting children more than once - if(seenTypes.count(T.getTypePtr()) == 0) { - /* - if(dumpType(T.getTypePtr())) { - return; - } - - visitChildrenAndData(T.getTypePtr()); -*/ - TypeVisitor::Visit(T.getTypePtr()); - } - - //llvm::errs() << "BRANCH 1 FOR " << T.getTypePtr() << "\n"; - - //visitChildren(T.getTypePtr()); - //dataDumper.dump(T.getTypePtr()); - //dumpIdToClassMap(T.getTypePtr(), clava::getClassName(T.getTypePtr())); - - dumpType(T.getTypePtr()); -#ifdef VISIT_CHECK - clava::dump(TOP_VISIT_END); - clava::dump(clava::getId(T.getTypePtr(), id)); + clava::dump(TOP_VISIT_START); + clava::dump(clava::getId(T.getTypePtr(), id)); #endif - return; - } - // Dump QualType - /* - if(dumpType(T)) { - return; - } - */ - - - // Visit children // TODO: AST dump method relies on visiting the nodes multiple times // For now, detect it to avoid visiting children more than once - -/* - if(seenTypes.count(T.getAsOpaquePtr()) == 0) { - visitChildren(T); - } -*/ - - - - //dumpType(T); - - if(dumpType(T)) { - return; + if (seenTypes.count(T.getTypePtr()) == 0) { + TypeVisitor::Visit(T.getTypePtr()); } + dumpType(T.getTypePtr()); #ifdef VISIT_CHECK - clava::dump(TOP_VISIT_START); - clava::dump(clava::getId(T, id)); + clava::dump(TOP_VISIT_END); + clava::dump(clava::getId(T.getTypePtr(), id)); #endif + return; + } - //llvm::errs() << "BRANCH 2 FOR " << T.getAsOpaquePtr() << "\n"; - - visitChildren(T); - dataDumper.dump(T); - dumpIdToClassMap(T.getAsOpaquePtr(), "QualType"); + if (dumpType(T)) { + return; + } #ifdef VISIT_CHECK - clava::dump(TOP_VISIT_END); - clava::dump(clava::getId(T, id)); + clava::dump(TOP_VISIT_START); + clava::dump(clava::getId(T, id)); #endif - // Dump data - //dataDumper.dump(clava::TypeNode::TYPE, T); - - // Visit underlying (unqualified) type - //TypeVisitor::Visit(T.getTypePtr()); -//llvm::errs() << "Opaque PTR: " << T.getAsOpaquePtr() << "\n"; -//llvm::errs() << "Underlying PTR: " << T.getTypePtr() << "\n"; - - //dumpType(T); - -// auto typeAddr = T.getTypePtrOrNull(); -// if(typeAddr == nullptr) { -// return; -// } - + visitChildren(T); + dataDumper.dump(T); + dumpIdToClassMap(T.getAsOpaquePtr(), "QualType"); +#ifdef VISIT_CHECK + clava::dump(TOP_VISIT_END); + clava::dump(clava::getId(T, id)); +#endif } void ClangAstDumper::VisitTypeTop(const Type *T) { - //std::cout << "HELLO\n"; - - if(T == nullptr) { - return; - } + if (T == nullptr) { + return; + } -/* - auto desugar = T->getUnqualifiedDesugaredType(); - if(desugar != T) { - VisitTypeTop(desugar); - } -*/ - - -// llvm::errs() << "TYPE TOP:" << T << "\n"; -// llvm::errs() << "TYPE TOP CLASS:" << T->getTypeClass() << "\n"; -// llvm::errs() << "TYPE TOP 2\n"; #ifdef VISIT_CHECK - clava::dump(TOP_VISIT_START); - clava::dump(clava::getId(T, id)); + clava::dump(TOP_VISIT_START); + clava::dump(clava::getId(T, id)); #endif - TypeVisitor::Visit(T); -// llvm::errs() << "TYPE TOP 3\n"; + TypeVisitor::Visit(T); + #ifdef VISIT_CHECK - clava::dump(TOP_VISIT_END); - clava::dump(clava::getId(T, id)); + clava::dump(TOP_VISIT_END); + clava::dump(clava::getId(T, id)); #endif } -/* -void ClangAstDumper::VisitStmtTop(Optional Node) { - VisitStmtTop(Node.getValueOr(nullptr)); -} -*/ - void ClangAstDumper::VisitStmtTop(const Stmt *Node) { - //VisitStmt(Node); - - if(Node == nullptr) { - return; - } + if (Node == nullptr) { + return; + } #ifdef VISIT_CHECK - clava::dump(TOP_VISIT_START); - clava::dump(clava::getId(Node, id)); + clava::dump(TOP_VISIT_START); + clava::dump(clava::getId(Node, id)); #endif -/* - if(dumpStmt(Node)) { - return; - } - - visitChildrenAndData(Node); -*/ - ConstStmtVisitor::Visit(Node); + ConstStmtVisitor::Visit(Node); #ifdef VISIT_CHECK - clava::dump(TOP_VISIT_END); - clava::dump(clava::getId(Node, id)); + clava::dump(TOP_VISIT_END); + clava::dump(clava::getId(Node, id)); #endif } void ClangAstDumper::VisitDeclTop(const Decl *Node) { - if(Node == nullptr) { - return; - } + if (Node == nullptr) { + return; + } #ifdef VISIT_CHECK - clava::dump(TOP_VISIT_START); - clava::dump(clava::getId(Node, id)); + clava::dump(TOP_VISIT_START); + clava::dump(clava::getId(Node, id)); #endif -/* - if(dumpDecl(Node)) { - return; - } - - visitChildrenAndData(Node); -*/ - // Do not visit if in system header - // If is in system header - /* - FullSourceLoc fullLocation = Context->getFullLoc(Node->getLocStart()); - if (fullLocation.isValid() && fullLocation.isInSystemHeader()) { - return; - } - */ - ConstDeclVisitor::Visit(Node); + ConstDeclVisitor::Visit(Node); #ifdef VISIT_CHECK - clava::dump(TOP_VISIT_END); - clava::dump(clava::getId(Node, id)); + clava::dump(TOP_VISIT_END); + clava::dump(clava::getId(Node, id)); #endif - } void ClangAstDumper::VisitAttrTop(const Attr *Node) { - if(Node == nullptr) { - return; - } + if (Node == nullptr) { + return; + } #ifdef VISIT_CHECK - clava::dump(TOP_VISIT_START); - clava::dump(clava::getId(Node, id)); + clava::dump(TOP_VISIT_START); + clava::dump(clava::getId(Node, id)); #endif - VisitAttr(Node); + VisitAttr(Node); #ifdef VISIT_CHECK - clava::dump(TOP_VISIT_END); - clava::dump(clava::getId(Node, id)); + clava::dump(TOP_VISIT_END); + clava::dump(clava::getId(Node, id)); #endif } -//void ClangAstDumper::log(const char* name, const void* addr) { -void ClangAstDumper::log(std::string name, const void* addr) { +void ClangAstDumper::log(std::string name, const void *addr) { #ifdef DEBUG - llvm::errs() << name << " " << addr << "\n"; + llvm::errs() << name << " " << addr << "\n"; #endif - -// clava::dump(VISIT_START); -// clava::dump(clava::getId(addr, id)); -} - -void ClangAstDumper::log(const Decl* D) { - log(clava::getClassName(D), D); } -void ClangAstDumper::log(const Stmt* S) { - log(clava::getClassName(S), S); -} +void ClangAstDumper::log(const Decl *D) { log(clava::getClassName(D), D); } -void ClangAstDumper::log(const Type* T) { - log(clava::getClassName(T), T); -} +void ClangAstDumper::log(const Stmt *S) { log(clava::getClassName(S), S); } -void ClangAstDumper::log(const Attr* A) { - log(clava::getClassName(A), A); -} +void ClangAstDumper::log(const Type *T) { log(clava::getClassName(T), T); } +void ClangAstDumper::log(const Attr *A) { log(clava::getClassName(A), A); } -std::string ClangAstDumper::loc2str(SourceLocation locStart, SourceLocation locEnd) { +std::string ClangAstDumper::loc2str(SourceLocation locStart, + SourceLocation locEnd) { - clang::SourceManager *sm = &Context->getSourceManager(); - clang::LangOptions lopt = Context->getLangOpts(); + clang::SourceManager *sm = &Context->getSourceManager(); + clang::LangOptions lopt = Context->getLangOpts(); - clang::SourceLocation b(locStart), _e(locEnd); - clang::SourceLocation e(clang::Lexer::getLocForEndOfToken(_e, 0, *sm, lopt)); + clang::SourceLocation b(locStart), _e(locEnd); + clang::SourceLocation e(clang::Lexer::getLocForEndOfToken(_e, 0, *sm, lopt)); + std::string bChars(sm->getCharacterData(b)); + std::string eChars(sm->getCharacterData(e)); - std::string bChars(sm->getCharacterData(b)); - std::string eChars(sm->getCharacterData(e)); + if (bChars == "<<<>>>") { + return ""; + } - if(bChars == "<<<>>>") { - return ""; - } + if (eChars == "<<<>>>") { + return ""; + } - if(eChars == "<<<>>>") { - return ""; - } - - return std::string(sm->getCharacterData(b), sm->getCharacterData(e)-sm->getCharacterData(b)); + return std::string(sm->getCharacterData(b), + sm->getCharacterData(e) - sm->getCharacterData(b)); } +void ClangAstDumper::dumpSourceRange(std::string id, SourceLocation startLoc, + SourceLocation endLoc) { + llvm::errs() << "\n"; -void ClangAstDumper::dumpSourceRange(std::string id, SourceLocation startLoc, SourceLocation endLoc) { - llvm::errs() << "\n"; - - llvm::errs() << id << "\n"; - // All components of the source range will be dumped - - const SourceManager& SM = Context->getSourceManager(); - - SourceLocation startSpellingLoc = SM.getSpellingLoc(startLoc); - PresumedLoc startPLoc = SM.getPresumedLoc(startSpellingLoc); - - if (startPLoc.isInvalid()) { - llvm::errs() << "\n"; - /* - llvm::errs() << "startLoc:\n"; - startLoc.dump(SM); - llvm::errs() << "endLoc:\n"; - endLoc.dump(SM); - assert(startLoc == endLoc); - */ - return; - } - - - // Dump start location - llvm::errs() << startPLoc.getFilename() << "\n"; - llvm::errs() << startPLoc.getLine() << "\n"; - llvm::errs() << startPLoc.getColumn() << "\n"; - - if(startLoc == endLoc) { - llvm::errs() << "\n"; - return; - } + llvm::errs() << id << "\n"; + // All components of the source range will be dumped - SourceLocation endSpellingLoc = SM.getSpellingLoc(endLoc); - PresumedLoc endPLoc = SM.getPresumedLoc(endSpellingLoc); + const SourceManager &SM = Context->getSourceManager(); - if(endPLoc.isInvalid()) { - llvm::errs() << "\n"; - return; - } + SourceLocation startSpellingLoc = SM.getSpellingLoc(startLoc); + PresumedLoc startPLoc = SM.getPresumedLoc(startSpellingLoc); - const char* endFilename = endPLoc.getFilename(); - if(!endFilename) { - endFilename = startPLoc.getFilename(); - } + if (startPLoc.isInvalid()) { + llvm::errs() << "\n"; + return; + } - unsigned int endLine = endPLoc.getLine(); - if(!endLine) { - endLine = startPLoc.getLine(); - } + // Dump start location + llvm::errs() << startPLoc.getFilename() << "\n"; + llvm::errs() << startPLoc.getLine() << "\n"; + llvm::errs() << startPLoc.getColumn() << "\n"; - unsigned int endCol = endPLoc.getColumn(); - if(!endCol) { - endCol = startPLoc.getColumn(); - } + if (startLoc == endLoc) { + llvm::errs() << "\n"; + return; + } - // Dump end location - llvm::errs() << endFilename << "\n"; - llvm::errs() << endLine << "\n"; - llvm::errs() << endCol << "\n"; -} + SourceLocation endSpellingLoc = SM.getSpellingLoc(endLoc); + PresumedLoc endPLoc = SM.getPresumedLoc(endSpellingLoc); -/* -std::string ClangAstDumper::getId(const void* addr) { - std::stringstream ss; - ss << addr << "_" << id; + if (endPLoc.isInvalid()) { + llvm::errs() << "\n"; + return; + } - return ss.str(); -} -*/ -/* -std::string ClangAstDumper::getId(const Decl* addr) { + const char *endFilename = endPLoc.getFilename(); + if (!endFilename) { + endFilename = startPLoc.getFilename(); + } -} + unsigned int endLine = endPLoc.getLine(); + if (!endLine) { + endLine = startPLoc.getLine(); + } -std::string ClangAstDumper::getId(const Stmt* addr) { + unsigned int endCol = endPLoc.getColumn(); + if (!endCol) { + endCol = startPLoc.getColumn(); + } + // Dump end location + llvm::errs() << endFilename << "\n"; + llvm::errs() << endLine << "\n"; + llvm::errs() << endCol << "\n"; } -std::string ClangAstDumper::getId(const Expr* addr) { - -} - -std::string ClangAstDumper::getId(const Type* addr) { - -} - -std::string ClangAstDumper::getId(const Attr* addr) { - -} -*/ - std::string ClangAstDumper::toBoolString(int value) { - return value ? "true" : "false"; + return value ? "true" : "false"; } +const Type *getTypePtr(QualType T, std::string source) { + assert(!T.isNull() && "Cannot retrieve a NULL type pointer"); -const Type* getTypePtr(QualType T, std::string source) { - assert(!T.isNull() && "Cannot retrieve a NULL type pointer"); - - return T.getTypePtr(); + return T.getTypePtr(); } -void ClangAstDumper::dumpVisitedChildren(const void *pointer, std::vector children) { - llvm::errs() << VISITED_CHILDREN << "\n"; - // If node has children, pointer will not be null - llvm::errs() << clava::getId(pointer, id) << "\n"; - llvm::errs() << children.size() << "\n"; +void ClangAstDumper::dumpVisitedChildren(const void *pointer, + std::vector children) { + llvm::errs() << VISITED_CHILDREN << "\n"; + // If node has children, pointer will not be null + llvm::errs() << clava::getId(pointer, id) << "\n"; + llvm::errs() << children.size() << "\n"; - for(auto child : children) { - llvm::errs() << child << "\n"; - } + for (auto child : children) { + llvm::errs() << child << "\n"; + } } -void ClangAstDumper::dumpIdToClassMap(const void* pointer, std::string className) { - llvm::errs() << ID_TO_CLASS_MAP << "\n"; - llvm::errs() << clava::getId(pointer, id) << "\n"; - llvm::errs() << className << "\n"; +void ClangAstDumper::dumpIdToClassMap(const void *pointer, + std::string className) { + llvm::errs() << ID_TO_CLASS_MAP << "\n"; + llvm::errs() << clava::getId(pointer, id) << "\n"; + llvm::errs() << className << "\n"; } void ClangAstDumper::dumpTopLevelType(const QualType &type) { - llvm::errs() << TOP_LEVEL_TYPES << "\n"; - clava::dump(type, id); + llvm::errs() << TOP_LEVEL_TYPES << "\n"; + clava::dump(type, id); } - void ClangAstDumper::dumpTopLevelAttr(const Attr *attr) { - llvm::errs() << TOP_LEVEL_ATTRIBUTES << "\n"; - llvm::errs() << clava::getId(attr, id) << "\n"; + llvm::errs() << TOP_LEVEL_ATTRIBUTES << "\n"; + llvm::errs() << clava::getId(attr, id) << "\n"; } - - void ClangAstDumper::emptyChildren(const void *pointer) { - std::vector noChildren; - dumpVisitedChildren(pointer, noChildren); + std::vector noChildren; + dumpVisitedChildren(pointer, noChildren); } +const void ClangAstDumper::addChild(const Decl *addr, + std::vector &children) { -const void ClangAstDumper::addChild(const Decl *addr, std::vector &children) { - - - // Do not add child if goes above system header threshold - if(systemHeaderThreshold > 0 && currentSystemHeaderLevel > systemHeaderThreshold) { - return; - } - + // Do not add child if goes above system header threshold + if (systemHeaderThreshold > 0 && + currentSystemHeaderLevel > systemHeaderThreshold) { + return; + } - std::string clavaId = clava::getId(addr, id); + std::string clavaId = clava::getId(addr, id); #ifdef VISIT_CHECK - if(addr != nullptr) { - clava::dump(VISIT_START); - clava::dump(clavaId); - } + if (addr != nullptr) { + clava::dump(VISIT_START); + clava::dump(clavaId); + } #endif - VisitDeclTop(addr); - children.push_back(clavaId); + VisitDeclTop(addr); + children.push_back(clavaId); #ifdef VISIT_CHECK - if(addr != nullptr) { - clava::dump(VISIT_END); - clava::dump(clavaId); - } + if (addr != nullptr) { + clava::dump(VISIT_END); + clava::dump(clavaId); + } #endif - }; -/* -const void ClangAstDumper::addChildren(DeclContext::decl_range decls, std::vector &children) { - return addChildren(decls, children, true); -} -*/ - -//const void ClangAstDumper::addChildren(DeclContext::decl_range decls, std::vector &children, bool ignoreClassDefinitions) { -const void ClangAstDumper::addChildren(DeclContext::decl_range decls, std::vector &children) { - +const void ClangAstDumper::addChildren(DeclContext::decl_range decls, + std::vector &children) { + for (auto decl = decls.begin(), endDecl = decls.end(); decl != endDecl; + ++decl) { - for (auto decl = decls.begin(), endDecl = decls.end(); decl != endDecl; ++decl) { - - // Ignore decls that are not in the source code - if(decl->isImplicit()) { - continue; - } - - if (*decl == nullptr) { - continue; - } - + // Ignore decls that are not in the source code + if (decl->isImplicit()) { + continue; + } - addChild(*decl, children); + if (*decl == nullptr) { + continue; } + addChild(*decl, children); + } }; -const void ClangAstDumper::addChild(const Stmt *addr, std::vector &children) { - - - // Do not add child if goes above system header threshold - if(systemHeaderThreshold > 0 && currentSystemHeaderLevel > systemHeaderThreshold) { - return; - } +const void ClangAstDumper::addChild(const Stmt *addr, + std::vector &children) { + // Do not add child if goes above system header threshold + if (systemHeaderThreshold > 0 && + currentSystemHeaderLevel > systemHeaderThreshold) { + return; + } - std::string clavaId = clava::getId(addr, id); + std::string clavaId = clava::getId(addr, id); #ifdef VISIT_CHECK - if(addr != nullptr) { - clava::dump(VISIT_START); - clava::dump(clavaId); - } + if (addr != nullptr) { + clava::dump(VISIT_START); + clava::dump(clavaId); + } #endif - VisitStmtTop(addr); - children.push_back(clavaId); + VisitStmtTop(addr); + children.push_back(clavaId); #ifdef VISIT_CHECK - if(addr != nullptr) { - clava::dump(VISIT_END); - clava::dump(clavaId); - } + if (addr != nullptr) { + clava::dump(VISIT_END); + clava::dump(clavaId); + } #endif - }; -const void ClangAstDumper::addChild(const Expr *addr, std::vector &children) { - - // Do not add child if goes above system header threshold - if(systemHeaderThreshold > 0 && currentSystemHeaderLevel > systemHeaderThreshold) { - return; - } +const void ClangAstDumper::addChild(const Expr *addr, + std::vector &children) { + // Do not add child if goes above system header threshold + if (systemHeaderThreshold > 0 && + currentSystemHeaderLevel > systemHeaderThreshold) { + return; + } - std::string clavaId = clava::getId(addr, id); + std::string clavaId = clava::getId(addr, id); #ifdef VISIT_CHECK - if(addr != nullptr) { - clava::dump(VISIT_START); - clava::dump(clavaId); - } + if (addr != nullptr) { + clava::dump(VISIT_START); + clava::dump(clavaId); + } #endif - VisitStmtTop(addr); - children.push_back(clavaId); + VisitStmtTop(addr); + children.push_back(clavaId); #ifdef VISIT_CHECK - if(addr != nullptr) { - clava::dump(VISIT_END); - clava::dump(clavaId); - } + if (addr != nullptr) { + clava::dump(VISIT_END); + clava::dump(clavaId); + } #endif - }; -const void ClangAstDumper::addChild(const Type *addr, std::vector &children) { - - - // Do not add child if goes above system header threshold - if(systemHeaderThreshold > 0 && currentSystemHeaderLevel > systemHeaderThreshold) { - return; - } +const void ClangAstDumper::addChild(const Type *addr, + std::vector &children) { + // Do not add child if goes above system header threshold + if (systemHeaderThreshold > 0 && + currentSystemHeaderLevel > systemHeaderThreshold) { + return; + } - std::string clavaId = clava::getId(addr, id); + std::string clavaId = clava::getId(addr, id); #ifdef VISIT_CHECK - if(addr != nullptr) { - clava::dump(VISIT_START); - clava::dump(clavaId); - } + if (addr != nullptr) { + clava::dump(VISIT_START); + clava::dump(clavaId); + } #endif - VisitTypeTop(addr); - children.push_back(clavaId); + VisitTypeTop(addr); + children.push_back(clavaId); #ifdef VISIT_CHECK - if(addr != nullptr) { - clava::dump(VISIT_END); - clava::dump(clavaId); - } + if (addr != nullptr) { + clava::dump(VISIT_END); + clava::dump(clavaId); + } #endif - }; -const void ClangAstDumper::addChild(const QualType &addr, std::vector &children) { - - - // Do not add child if goes above system header threshold - if(systemHeaderThreshold > 0 && currentSystemHeaderLevel > systemHeaderThreshold) { - return; - } +const void ClangAstDumper::addChild(const QualType &addr, + std::vector &children) { + // Do not add child if goes above system header threshold + if (systemHeaderThreshold > 0 && + currentSystemHeaderLevel > systemHeaderThreshold) { + return; + } - std::string clavaId = clava::getId(addr, id); + std::string clavaId = clava::getId(addr, id); #ifdef VISIT_CHECK - clava::dump(VISIT_START); - clava::dump(clavaId); + clava::dump(VISIT_START); + clava::dump(clavaId); #endif - VisitTypeTop(addr); - children.push_back(clavaId); + VisitTypeTop(addr); + children.push_back(clavaId); #ifdef VISIT_CHECK - clava::dump(VISIT_END); - clava::dump(clavaId); + clava::dump(VISIT_END); + clava::dump(clavaId); #endif - }; -const void ClangAstDumper::addChild(const Attr *addr, std::vector &children) { +const void ClangAstDumper::addChild(const Attr *addr, + std::vector &children) { + // Do not add child if goes above system header threshold + if (systemHeaderThreshold > 0 && + currentSystemHeaderLevel > systemHeaderThreshold) { + return; + } - // Do not add child if goes above system header threshold - if(systemHeaderThreshold > 0 && currentSystemHeaderLevel > systemHeaderThreshold) { - return; - } - - - std::string clavaId = clava::getId(addr, id); + std::string clavaId = clava::getId(addr, id); #ifdef VISIT_CHECK - if(addr != nullptr) { - clava::dump(VISIT_START); - clava::dump(clavaId); - } + if (addr != nullptr) { + clava::dump(VISIT_START); + clava::dump(clavaId); + } #endif - VisitAttrTop(addr); - children.push_back(clavaId); + VisitAttrTop(addr); + children.push_back(clavaId); #ifdef VISIT_CHECK - if(addr != nullptr) { - clava::dump(VISIT_END); - clava::dump(clavaId); - } + if (addr != nullptr) { + clava::dump(VISIT_END); + clava::dump(clavaId); + } #endif - }; - - - -void ClangAstDumper::VisitTemplateArgument(const TemplateArgument& templateArg) { - switch(templateArg.getKind()) { - case TemplateArgument::ArgKind::Type: - VisitTypeTop(templateArg.getAsType()); - break; - case TemplateArgument::ArgKind::Expression: - VisitStmtTop(templateArg.getAsExpr()); - break; - case TemplateArgument::ArgKind::Pack: - // Do nothing - break; - case TemplateArgument::ArgKind::Integral: - // Do nothing - break; - case TemplateArgument::ArgKind::Template: - VisitTemplateName(templateArg.getAsTemplate()); - break; - /* - { - TemplateName templateName = templateArg.getAsTemplate(); - switch(templateName.getKind()) { - case TemplateName::NameKind::Template: - VisitDeclTop(templateName.getAsTemplateDecl()); - break; - case TemplateName::NameKind::QualifiedTemplate: - VisitDeclTop(templateName.getAsQualifiedTemplateName()->getTemplateDecl()); - break; - default: - throw std::invalid_argument("ClangAstDumper::VisitTemplateArgument(): TemplateName case not implemented, '" + - clava::TEMPLATE_NAME_KIND[templateName.getKind()] + "'"); - } - break; - - } -*/ - default: throw std::invalid_argument("ClangAstDumper::VisitTemplateArgument(): Case not implemented, '"+clava::TEMPLATE_ARG_KIND[templateArg.getKind()]+"'"); - } +void ClangAstDumper::VisitTemplateArgument( + const TemplateArgument &templateArg) { + switch (templateArg.getKind()) { + case TemplateArgument::ArgKind::Type: + VisitTypeTop(templateArg.getAsType()); + break; + case TemplateArgument::ArgKind::Expression: + VisitStmtTop(templateArg.getAsExpr()); + break; + case TemplateArgument::ArgKind::Pack: + // Do nothing + break; + case TemplateArgument::ArgKind::Integral: + // Do nothing + break; + case TemplateArgument::ArgKind::Template: + VisitTemplateName(templateArg.getAsTemplate()); + break; + default: + throw std::invalid_argument( + "ClangAstDumper::VisitTemplateArgument(): Case not implemented, '" + + clava::TEMPLATE_ARG_KIND[templateArg.getKind()] + "'"); + } }; -void ClangAstDumper::VisitTemplateName(const TemplateName& templateName) { - - switch(templateName.getKind()) { - case TemplateName::NameKind::Template: - VisitDeclTop(templateName.getAsTemplateDecl()); - break; - case TemplateName::NameKind::QualifiedTemplate: - VisitDeclTop(templateName.getAsQualifiedTemplateName()->getTemplateDecl()); - break; - case TemplateName::NameKind::SubstTemplateTemplateParm: - VisitDeclTop(templateName.getAsSubstTemplateTemplateParm()->getParameter()); - VisitTemplateName(templateName.getAsSubstTemplateTemplateParm()->getReplacement()); - default: - throw std::invalid_argument("ClangAstDumper::VisitTemplateArgument(): TemplateName case not implemented, '" + - clava::TEMPLATE_NAME_KIND[templateName.getKind()] + "'"); - } +void ClangAstDumper::VisitTemplateName(const TemplateName &templateName) { + + switch (templateName.getKind()) { + case TemplateName::NameKind::Template: + VisitDeclTop(templateName.getAsTemplateDecl()); + break; + case TemplateName::NameKind::QualifiedTemplate: + VisitDeclTop(templateName.getAsQualifiedTemplateName()->getTemplateDecl()); + break; + case TemplateName::NameKind::SubstTemplateTemplateParm: + VisitDeclTop(templateName.getAsSubstTemplateTemplateParm()->getParameter()); + VisitTemplateName( + templateName.getAsSubstTemplateTemplateParm()->getReplacement()); + default: + throw std::invalid_argument( + "ClangAstDumper::VisitTemplateArgument(): TemplateName case not " + "implemented, '" + + clava::TEMPLATE_NAME_KIND[templateName.getKind()] + "'"); + } }; \ No newline at end of file diff --git a/ClangAstDumper/src/ClangAstDumper/ClangAstDumper.h b/ClangAstDumper/src/ClangAstDumper/ClangAstDumper.h index 62b15b224..0bc6f5d27 100644 --- a/ClangAstDumper/src/ClangAstDumper/ClangAstDumper.h +++ b/ClangAstDumper/src/ClangAstDumper/ClangAstDumper.h @@ -7,373 +7,376 @@ #include "../ClavaDataDumper/ClavaDataDumper.h" -#include "clang/AST/TypeVisitor.h" -#include "clang/AST/StmtVisitor.h" #include "clang/AST/DeclVisitor.h" -//#include "ClangAst.h" +#include "clang/AST/StmtVisitor.h" +#include "clang/AST/TypeVisitor.h" #include #include #include -//#define DEBUG +// #define DEBUG using namespace clang; - -class ClangAstDumper : public TypeVisitor, public ConstStmtVisitor, public ConstDeclVisitor { +class ClangAstDumper : public TypeVisitor, + public ConstStmtVisitor, + public ConstDeclVisitor { private: - ASTContext *Context; - //const ASTContext& constContext; - int id; - - int systemHeaderThreshold = 2; - int currentSystemHeaderLevel = 0; + ASTContext *Context; + int id; - std::set seenTypes; - std::set seenStmts; - std::set seenDecls; - std::set seenAttrs; + int systemHeaderThreshold = 2; + int currentSystemHeaderLevel = 0; - std::set seenInits; + std::set seenTypes; + std::set seenStmts; + std::set seenDecls; + std::set seenAttrs; - clava::ClavaDataDumper dataDumper; + std::set seenInits; - static const std::map DECL_CHILDREN_MAP; - static const std::map STMT_CHILDREN_MAP; - static const std::map EXPR_CHILDREN_MAP; - static const std::map TYPE_CHILDREN_MAP; - static const std::map ATTR_CHILDREN_MAP; + clava::ClavaDataDumper dataDumper; + static const std::map DECL_CHILDREN_MAP; + static const std::map STMT_CHILDREN_MAP; + static const std::map EXPR_CHILDREN_MAP; + static const std::map TYPE_CHILDREN_MAP; + static const std::map ATTR_CHILDREN_MAP; public: - explicit ClangAstDumper(ASTContext *Context, int id, int systemHeaderThreashold); - //explicit ClangAstDumper(ASTContext *Context, const ASTContext& constContext, int id, int systemHeaderThreashold); - - void VisitTypeTop(const Type *T); - void VisitTypeTop(const QualType& T); - void VisitStmtTop(const Stmt *Node); - //void VisitStmtTop(Optional Node); - void VisitDeclTop(const Decl *Node); - void VisitAttrTop(const Attr *Node); - - - /* - * TYPES - */ - void VisitType(const Type *T); // Should not be manually called, instead call VisitTypeTop() -/* - // TODO: We should only need to call VisitType, children/data maps should handle all cases - //void VisitBuiltinType(const BuiltinType *T); - void VisitPointerType(const PointerType *T); - //void VisitTemplateSpecializationType(const TemplateSpecializationType *T); - void VisitFunctionProtoType(const FunctionProtoType *T); - void VisitTypedefType(const TypedefType *T); - void VisitElaboratedType(const ElaboratedType *T); - void VisitLValueReferenceType(const LValueReferenceType *T); - void VisitDependentSizedArrayType(const DependentSizedArrayType *T); -*/ - - /* - * STMTS - */ - void VisitStmt(const Stmt *T); // Should not be manually called, instead call VisitStmtTop() - /* - //void VisitDeclStmt(const DeclStmt *Node); - void VisitCXXForRangeStmt(const CXXForRangeStmt *Node); - //void VisitCompoundStmt(const CompoundStmt *Node); - void VisitForStmt(const ForStmt *Node); - */ - - /* - * EXPRS - */ - - void VisitExpr(const Expr *Node); - /* - void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node); - void VisitCXXConstructExpr(const CXXConstructExpr *Node); - void VisitDeclRefExpr(const DeclRefExpr *Node); - void VisitOffsetOfExpr(const OffsetOfExpr *Node); - void VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *Node); - void VisitOverloadExpr(const OverloadExpr *Node); - void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node); - void VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *Node); - void VisitLambdaExpr(const LambdaExpr *Node); - void VisitSizeOfPackExpr(const SizeOfPackExpr *Node); - void VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr *Node); - void VisitCXXTypeidExpr(const CXXTypeidExpr *Node); - void VisitInitListExpr(const InitListExpr *Node); - //void VisitCastExpr(const CastExpr *Node); // Works for ImplicitCastExpr, etc - //void VisitCharacterLiteral(const CharacterLiteral *Node); - - //void VisitImplicitCastExpr(const ImplicitCastExpr *Node); -*/ - - - - /* - * DELCS - */ - void VisitDecl(const Decl *D); // Should not be manually called, instead call VisitDeclTop() -/* - //void VisitVarDecl(const VarDecl *D); - //void VisitFunctionDecl(const FunctionDecl *D); - //void VisitCXXMethodDecl(const CXXMethodDecl *D); - void VisitCXXConstructorDecl(const CXXConstructorDecl *D); - //void VisitCXXConversionDecl(const CXXConversionDecl *D); - //void VisitCXXDestructorDecl(const CXXDestructorDecl *D); - void VisitCXXRecordDecl(const CXXRecordDecl *D); - void VisitObjCImplementationDecl(const ObjCImplementationDecl *D); - void VisitTemplateDecl(const TemplateDecl *D); - void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D); - void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D); - void VisitFieldDecl(const FieldDecl *D); - void VisitParmVarDecl(const ParmVarDecl *D); - void VisitTypedefDecl(const TypedefDecl *D); -*/ - /* - * ATTR - */ - void VisitAttr(const Attr* A); + explicit ClangAstDumper(ASTContext *Context, int id, + int systemHeaderThreashold); + void VisitTypeTop(const Type *T); + void VisitTypeTop(const QualType &T); + void VisitStmtTop(const Stmt *Node); + void VisitDeclTop(const Decl *Node); + void VisitAttrTop(const Attr *Node); /* - * EXTRA + * TYPES */ + void VisitType(const Type *T); // Should not be manually called, instead call + // VisitTypeTop() + /* + * STMTS + */ + void VisitStmt(const Stmt *T); // Should not be manually called, instead call + // VisitStmtTop() - /* - * Utility methods - */ - - std::string loc2str(SourceLocation locStart, SourceLocation locEnd); - //std::string getId(const void* addr); - /* - std::string getId(const Decl* addr); - std::string getId(const Stmt* addr); - std::string getId(const Expr* addr); - std::string getId(const Type* addr); - std::string getId(const Attr* addr); - */ - - std::string toBoolString(int value); - const Type* getTypePtr(QualType T, std::string source); + /* + * EXPRS + */ + void VisitExpr(const Expr *Node); - //void log(const char* name, const void* addr); - void log(const Decl* D); - void log(const Stmt* S); - void log(const Type* T); - void log(const Attr* A); + /* + * DELCS + */ + void VisitDecl(const Decl *D); // Should not be manually called, instead call + // VisitDeclTop() + /* + * ATTR + */ + void VisitAttr(const Attr *A); + /* + * Utility methods + */ - /** - * Adds a child. - * - * @param addr - * @param id - * @return - */ - const void addChild(const Decl *addr, std::vector &children); - const void addChildren(DeclContext::decl_range declRange, std::vector &children); - //const void addChildren(DeclContext::decl_range declRange, std::vector &children, bool ignoreClassDefinitions); - const void addChild(const Stmt *addr, std::vector &children); - const void addChild(const Expr *addr, std::vector &children); - const void addChild(const Type *addr, std::vector &children); - const void addChild(const QualType &addr, std::vector &children); - const void addChild(const Attr *addr, std::vector &children); + std::string loc2str(SourceLocation locStart, SourceLocation locEnd); + std::string toBoolString(int value); + const Type *getTypePtr(QualType T, std::string source); + void log(const Decl *D); + void log(const Stmt *S); + void log(const Type *T); + void log(const Attr *A); - // Private functions + /** + * Adds a child. + * + * @param addr + * @param id + * @return + */ + const void addChild(const Decl *addr, std::vector &children); + const void addChildren(DeclContext::decl_range declRange, + std::vector &children); + const void addChild(const Stmt *addr, std::vector &children); + const void addChild(const Expr *addr, std::vector &children); + const void addChild(const Type *addr, std::vector &children); + const void addChild(const QualType &addr, std::vector &children); + const void addChild(const Attr *addr, std::vector &children); + + // Private functions private: - - void log(std::string name, const void* addr); - - // Children and data - void visitChildrenAndData(const Decl *D); - void visitChildrenAndData(const Stmt *S); - void visitChildrenAndData(const Expr *E); - void visitChildrenAndData(const Type *T); - void visitChildrenAndData(const Attr *A); - - - // Children visitors - void dumpVisitedChildren(const void *pointer, std::vector children); - - void visitChildren(const Decl* D); - void visitChildren(const Stmt* S); - void visitChildren(const Expr* E); - void visitChildren(const Type* T); - void visitChildren(const Attr* A); - - void visitChildren(clava::DeclNode declNode, const Decl* D); - void visitChildren(clava::StmtNode stmtNode, const Stmt* S); - void visitChildren(clava::TypeNode typeNode, const Type* T); - void visitChildren(const QualType &T); - void visitChildren(clava::AttrNode attrNode, const Attr* A); - void emptyChildren(const void *pointer); - - // Children visitors for Decls - void VisitDeclChildren(const Decl *D, std::vector &children); - void VisitNamedDeclChildren(const NamedDecl *D, std::vector &children); - void VisitTypeDeclChildren(const TypeDecl *D, std::vector &children); - void VisitTagDeclChildren(const TagDecl *D, std::vector &children); - void VisitEnumDeclChildren(const EnumDecl *D, std::vector &children); - void VisitRecordDeclChildren(const RecordDecl *D, std::vector &children); - void VisitCXXRecordDeclChildren(const CXXRecordDecl *D, std::vector &children); - void VisitClassTemplateSpecializationDeclChildren(const ClassTemplateSpecializationDecl *D, std::vector &children); - void VisitValueDeclChildren(const ValueDecl *D, std::vector &children); - void VisitFieldDeclChildren(const FieldDecl *D, std::vector &children); - void VisitFunctionDeclChildren(const FunctionDecl *D, std::vector &children); - void VisitCXXMethodDeclChildren(const CXXMethodDecl *D, std::vector &children); - void VisitCXXConstructorDeclChildren(const CXXConstructorDecl *D, std::vector &children); - void VisitCXXConversionDeclChildren(const CXXConversionDecl *D, std::vector &children); - - void VisitVarDeclChildren(const VarDecl *D, std::vector &children); - void VisitParmVarDeclChildren(const ParmVarDecl *D, std::vector &children); - - void VisitTemplateDeclChildren(const TemplateDecl *D, std::vector &children); - void VisitTemplateTemplateParmDeclChildren(const TemplateTemplateParmDecl * D, std::vector &children); - void VisitTemplateTypeParmDeclChildren(const TemplateTypeParmDecl *D, std::vector &children); - void VisitEnumConstantDeclChildren(const EnumConstantDecl *D, std::vector &children); - void VisitTypedefNameDeclChildren(const TypedefNameDecl *D, std::vector &children); - void VisitUsingDirectiveDeclChildren(const UsingDirectiveDecl *D, std::vector &children); - void VisitNamespaceDeclChildren(const NamespaceDecl *D, std::vector &children); - void VisitFriendDeclChildren(const FriendDecl *D, std::vector &children); - void VisitNamespaceAliasDeclChildren(const NamespaceAliasDecl *D, std::vector &children); - void VisitLinkageSpecDeclChildren(const LinkageSpecDecl *D, std::vector &children); - void VisitStaticAssertDeclChildren(const StaticAssertDecl *D, std::vector &children); - void VisitNonTypeTemplateParmDeclChildren(const NonTypeTemplateParmDecl *D, std::vector &children); - void VisitUsingDeclChildren(const UsingDecl *D, std::vector &children); - - - // Children visitors for Stmts - void VisitStmtChildren(const Stmt *S, std::vector &children); - //void VisitCompoundStmtChildren(const CompoundStmt *S, std::vector &children); - void VisitDeclStmtChildren(const DeclStmt *S, std::vector &children); - void VisitIfStmtChildren(const IfStmt *S, std::vector &children); - void VisitForStmtChildren(const ForStmt *S, std::vector &children); - void VisitWhileStmtChildren(const WhileStmt *S, std::vector &children); - void VisitDoStmtChildren(const DoStmt *S, std::vector &children); - void VisitCXXForRangeStmtChildren(const CXXForRangeStmt *S, std::vector &children); - void VisitCXXCatchStmtChildren(const CXXCatchStmt *S, std::vector &children); - void VisitCXXTryStmtChildren(const CXXTryStmt *S, std::vector &children); - void VisitCaseStmtChildren(const CaseStmt *S, std::vector &children); - void VisitDefaultStmtChildren(const DefaultStmt *S, std::vector &children); - void VisitGotoStmtChildren(const GotoStmt *S, std::vector &children); - void VisitLabelStmtChildren(const LabelStmt *S, std::vector &children); - void VisitAttributedStmtChildren(const AttributedStmt *S, std::vector &children); - void VisitCapturedStmtChildren(const CapturedStmt *S, std::vector &children); - - // Children visitors for Exprs - void VisitExprChildren(const Expr *S, std::vector &children); - void VisitInitListExprChildren(const InitListExpr *E, std::vector &children); - void VisitDeclRefExprChildren(const DeclRefExpr *E, std::vector &children); - void VisitDependentScopeDeclRefExprChildren(const DependentScopeDeclRefExpr *E, std::vector &children); - void VisitOffsetOfExprChildren(const OffsetOfExpr *E, std::vector &children); - void VisitMemberExprChildren(const MemberExpr *E, std::vector &children); - void VisitMaterializeTemporaryExprChildren(const MaterializeTemporaryExpr *E, std::vector &children); - //void VisitUnresolvedLookupExprChildren(const UnresolvedLookupExpr *E, std::vector &children); - void VisitOverloadExprChildren(const OverloadExpr *E, std::vector &children); - void VisitCallExprChildren(const CallExpr *E, std::vector &children); - void VisitCXXMemberCallExprChildren(const CXXMemberCallExpr *E, std::vector &children); - void VisitCXXTypeidExprChildren(const CXXTypeidExpr *E, std::vector &children); - void VisitExplicitCastExprChildren(const ExplicitCastExpr *E, std::vector &children); - void VisitOpaqueValueExprChildren(const OpaqueValueExpr *E, std::vector &children); - void VisitUnaryExprOrTypeTraitExprChildren(const UnaryExprOrTypeTraitExpr *E, std::vector &children); - void VisitCXXNewExprChildren(const CXXNewExpr *E, std::vector &children); - void VisitCXXDeleteExprChildren(const CXXDeleteExpr *E, std::vector &children); - void VisitLambdaExprChildren(const LambdaExpr *E, std::vector &children); - void VisitSizeOfPackExprChildren(const SizeOfPackExpr *E, std::vector &children); - void VisitDesignatedInitExprChildren(const DesignatedInitExpr *E, std::vector &children); - void VisitCXXConstructExprChildren(const CXXConstructExpr *E, std::vector &children); - void VisitCXXTemporaryObjectExprChildren(const CXXTemporaryObjectExpr *E, std::vector &children); - void VisitCXXDependentScopeMemberExprChildren(const CXXDependentScopeMemberExpr *E, std::vector &children); - void VisitCXXPseudoDestructorExprChildren(const CXXPseudoDestructorExpr *E, std::vector &children); - void VisitMSPropertyRefExprChildren(const MSPropertyRefExpr *E, std::vector &children); - - //void VisitFullExprChildren(const FullExpr *E, std::vector &children); - - //void VisitCXXNoexceptExprChildren(const CXXNoexceptExpr *E, std::vector &children); - - - - //void VisitSubstNonTypeTemplateParmExprChildren(const SubstNonTypeTemplateParmExpr *E, std::vector &children); - - - //void VisitCastExprChildren(const CastExpr *S, std::vector &children); - - - // Children visitors for Attributes - void VisitAlignedAttrChildren(const AlignedAttr * A, std::vector &children); - void VisitTemplateArgument(const TemplateArgument& templateArg); - void VisitTemplateName(const TemplateName& templateArg); - - - - // Dumpers of other kinds of information - void dumpIdToClassMap(const void* pointer, std::string className); - void dumpTopLevelType(const QualType &type); - void dumpTopLevelAttr(const Attr *attr); - - - // Children visitors for Types - void VisitTypeChildren(const Type *T, std::vector &children); - void VisitFunctionTypeChildren(const FunctionType *T, std::vector &visitedChildren); - void VisitFunctionProtoTypeChildren(const FunctionProtoType *T, std::vector &visitedChildren); - void VisitTagTypeChildren(const TagType *T, std::vector &visitedChildren); - //void VisitEnumTypeChildren(const EnumType *T, std::vector &visitedChildren); - void VisitArrayTypeChildren(const ArrayType *T, std::vector &visitedChildren); - void VisitVariableArrayTypeChildren(const VariableArrayType *T, std::vector &visitedChildren); - void VisitDependentSizedArrayTypeChildren(const DependentSizedArrayType *T, std::vector &visitedChildren); - void VisitPointerTypeChildren(const PointerType *T, std::vector &visitedChildren); - void VisitElaboratedTypeChildren(const ElaboratedType *T, std::vector &visitedChildren); - void VisitReferenceTypeChildren(const ReferenceType *T, std::vector &visitedChildren); - void VisitInjectedClassNameTypeChildren(const InjectedClassNameType *T, std::vector &visitedChildren); - void VisitTemplateTypeParmTypeChildren(const TemplateTypeParmType *T, std::vector &visitedChildren); - //void VisitTypedefTypeChildren(const TypedefType *T, std::vector &visitedChildren); - void VisitSubstTemplateTypeParmTypeChildren(const SubstTemplateTypeParmType *T, std::vector &visitedChildren); - void VisitTemplateSpecializationTypeChildren(const TemplateSpecializationType *T, std::vector &visitedChildren); - void VisitTypedefTypeChildren(const TypedefType *T, std::vector &visitedChildren); - void VisitAdjustedTypeChildren(const AdjustedType *T, std::vector &visitedChildren); - void VisitDecayedTypeChildren(const DecayedType *T, std::vector &visitedChildren); - void VisitDecltypeTypeChildren(const DecltypeType *T, std::vector &visitedChildren); - void VisitAutoTypeChildren(const AutoType *T, std::vector &visitedChildren); - void VisitPackExpansionTypeChildren(const PackExpansionType *T, std::vector &visitedChildren); - void VisitTypeOfExprTypeChildren(const TypeOfExprType *T, std::vector &visitedChildren); - void VisitAttributedTypeChildren(const AttributedType *T, std::vector &visitedChildren); - void VisitUnaryTransformTypeChildren(const UnaryTransformType *T, std::vector &visitedChildren); - void VisitComplexTypeChildren(const ComplexType *T, std::vector &visitedChildren); - - // Children visitors for other types of classes - void VisitTemplateArgChildren(const TemplateArgument& arg); - void VisitTemplateNameChildren(const TemplateName& templateName); - void VisitNestedNameSpecifierChildren(NestedNameSpecifier* qualifier); - - - /* Utility methods for DECLS */ - void dumpNumberTemplateParameters(const Decl *D, const TemplateParameterList *TPL); - - void dumpSourceRange(std::string id, SourceLocation startLoc, SourceLocation endLoc); - - // These methods return true if the node had been already visited - - bool dumpType(const Type* typeAddr); - bool dumpType(const QualType& type); - bool dumpStmt(const Stmt* stmtAddr); - bool dumpDecl(const Decl* declAddr); - bool dumpAttr(const Attr* attrAddr); - - /* EXTRA */ - void dumpCXXCtorInitializer(const CXXCtorInitializer *Init); - - - - + void log(std::string name, const void *addr); + + // Children and data + void visitChildrenAndData(const Decl *D); + void visitChildrenAndData(const Stmt *S); + void visitChildrenAndData(const Expr *E); + void visitChildrenAndData(const Type *T); + void visitChildrenAndData(const Attr *A); + + // Children visitors + void dumpVisitedChildren(const void *pointer, + std::vector children); + + void visitChildren(const Decl *D); + void visitChildren(const Stmt *S); + void visitChildren(const Expr *E); + void visitChildren(const Type *T); + void visitChildren(const Attr *A); + + void visitChildren(clava::DeclNode declNode, const Decl *D); + void visitChildren(clava::StmtNode stmtNode, const Stmt *S); + void visitChildren(clava::TypeNode typeNode, const Type *T); + void visitChildren(const QualType &T); + void visitChildren(clava::AttrNode attrNode, const Attr *A); + void emptyChildren(const void *pointer); + + // Children visitors for Decls + void VisitDeclChildren(const Decl *D, std::vector &children); + void VisitNamedDeclChildren(const NamedDecl *D, + std::vector &children); + void VisitTypeDeclChildren(const TypeDecl *D, + std::vector &children); + void VisitTagDeclChildren(const TagDecl *D, + std::vector &children); + void VisitEnumDeclChildren(const EnumDecl *D, + std::vector &children); + void VisitRecordDeclChildren(const RecordDecl *D, + std::vector &children); + void VisitCXXRecordDeclChildren(const CXXRecordDecl *D, + std::vector &children); + void VisitClassTemplateSpecializationDeclChildren( + const ClassTemplateSpecializationDecl *D, + std::vector &children); + void VisitValueDeclChildren(const ValueDecl *D, + std::vector &children); + void VisitFieldDeclChildren(const FieldDecl *D, + std::vector &children); + void VisitFunctionDeclChildren(const FunctionDecl *D, + std::vector &children); + void VisitCXXMethodDeclChildren(const CXXMethodDecl *D, + std::vector &children); + void VisitCXXConstructorDeclChildren(const CXXConstructorDecl *D, + std::vector &children); + void VisitCXXConversionDeclChildren(const CXXConversionDecl *D, + std::vector &children); + + void VisitVarDeclChildren(const VarDecl *D, + std::vector &children); + void VisitParmVarDeclChildren(const ParmVarDecl *D, + std::vector &children); + + void VisitTemplateDeclChildren(const TemplateDecl *D, + std::vector &children); + void + VisitTemplateTemplateParmDeclChildren(const TemplateTemplateParmDecl *D, + std::vector &children); + void VisitTemplateTypeParmDeclChildren(const TemplateTypeParmDecl *D, + std::vector &children); + void VisitEnumConstantDeclChildren(const EnumConstantDecl *D, + std::vector &children); + void VisitTypedefNameDeclChildren(const TypedefNameDecl *D, + std::vector &children); + void VisitUsingDirectiveDeclChildren(const UsingDirectiveDecl *D, + std::vector &children); + void VisitNamespaceDeclChildren(const NamespaceDecl *D, + std::vector &children); + void VisitFriendDeclChildren(const FriendDecl *D, + std::vector &children); + void VisitNamespaceAliasDeclChildren(const NamespaceAliasDecl *D, + std::vector &children); + void VisitLinkageSpecDeclChildren(const LinkageSpecDecl *D, + std::vector &children); + void VisitStaticAssertDeclChildren(const StaticAssertDecl *D, + std::vector &children); + void VisitNonTypeTemplateParmDeclChildren(const NonTypeTemplateParmDecl *D, + std::vector &children); + void VisitUsingDeclChildren(const UsingDecl *D, + std::vector &children); + + // Children visitors for Stmts + void VisitStmtChildren(const Stmt *S, std::vector &children); + void VisitDeclStmtChildren(const DeclStmt *S, + std::vector &children); + void VisitIfStmtChildren(const IfStmt *S, std::vector &children); + void VisitForStmtChildren(const ForStmt *S, + std::vector &children); + void VisitWhileStmtChildren(const WhileStmt *S, + std::vector &children); + void VisitDoStmtChildren(const DoStmt *S, std::vector &children); + void VisitCXXForRangeStmtChildren(const CXXForRangeStmt *S, + std::vector &children); + void VisitCXXCatchStmtChildren(const CXXCatchStmt *S, + std::vector &children); + void VisitCXXTryStmtChildren(const CXXTryStmt *S, + std::vector &children); + void VisitCaseStmtChildren(const CaseStmt *S, + std::vector &children); + void VisitDefaultStmtChildren(const DefaultStmt *S, + std::vector &children); + void VisitGotoStmtChildren(const GotoStmt *S, + std::vector &children); + void VisitLabelStmtChildren(const LabelStmt *S, + std::vector &children); + void VisitAttributedStmtChildren(const AttributedStmt *S, + std::vector &children); + void VisitCapturedStmtChildren(const CapturedStmt *S, + std::vector &children); + + // Children visitors for Exprs + void VisitExprChildren(const Expr *S, std::vector &children); + void VisitInitListExprChildren(const InitListExpr *E, + std::vector &children); + void VisitDeclRefExprChildren(const DeclRefExpr *E, + std::vector &children); + void + VisitDependentScopeDeclRefExprChildren(const DependentScopeDeclRefExpr *E, + std::vector &children); + void VisitOffsetOfExprChildren(const OffsetOfExpr *E, + std::vector &children); + void VisitMemberExprChildren(const MemberExpr *E, + std::vector &children); + void + VisitMaterializeTemporaryExprChildren(const MaterializeTemporaryExpr *E, + std::vector &children); + void VisitOverloadExprChildren(const OverloadExpr *E, + std::vector &children); + void VisitCallExprChildren(const CallExpr *E, + std::vector &children); + void VisitCXXMemberCallExprChildren(const CXXMemberCallExpr *E, + std::vector &children); + void VisitCXXTypeidExprChildren(const CXXTypeidExpr *E, + std::vector &children); + void VisitExplicitCastExprChildren(const ExplicitCastExpr *E, + std::vector &children); + void VisitOpaqueValueExprChildren(const OpaqueValueExpr *E, + std::vector &children); + void + VisitUnaryExprOrTypeTraitExprChildren(const UnaryExprOrTypeTraitExpr *E, + std::vector &children); + void VisitCXXNewExprChildren(const CXXNewExpr *E, + std::vector &children); + void VisitCXXDeleteExprChildren(const CXXDeleteExpr *E, + std::vector &children); + void VisitLambdaExprChildren(const LambdaExpr *E, + std::vector &children); + void VisitSizeOfPackExprChildren(const SizeOfPackExpr *E, + std::vector &children); + void VisitDesignatedInitExprChildren(const DesignatedInitExpr *E, + std::vector &children); + void VisitCXXConstructExprChildren(const CXXConstructExpr *E, + std::vector &children); + void VisitCXXTemporaryObjectExprChildren(const CXXTemporaryObjectExpr *E, + std::vector &children); + void + VisitCXXDependentScopeMemberExprChildren(const CXXDependentScopeMemberExpr *E, + std::vector &children); + void VisitCXXPseudoDestructorExprChildren(const CXXPseudoDestructorExpr *E, + std::vector &children); + void VisitMSPropertyRefExprChildren(const MSPropertyRefExpr *E, + std::vector &children); + + // Children visitors for Attributes + void VisitAlignedAttrChildren(const AlignedAttr *A, + std::vector &children); + void VisitTemplateArgument(const TemplateArgument &templateArg); + void VisitTemplateName(const TemplateName &templateArg); + + // Dumpers of other kinds of information + void dumpIdToClassMap(const void *pointer, std::string className); + void dumpTopLevelType(const QualType &type); + void dumpTopLevelAttr(const Attr *attr); + + // Children visitors for Types + void VisitTypeChildren(const Type *T, std::vector &children); + void VisitFunctionTypeChildren(const FunctionType *T, + std::vector &visitedChildren); + void + VisitFunctionProtoTypeChildren(const FunctionProtoType *T, + std::vector &visitedChildren); + void VisitTagTypeChildren(const TagType *T, + std::vector &visitedChildren); + void VisitArrayTypeChildren(const ArrayType *T, + std::vector &visitedChildren); + void + VisitVariableArrayTypeChildren(const VariableArrayType *T, + std::vector &visitedChildren); + void VisitDependentSizedArrayTypeChildren( + const DependentSizedArrayType *T, + std::vector &visitedChildren); + void VisitPointerTypeChildren(const PointerType *T, + std::vector &visitedChildren); + void VisitElaboratedTypeChildren(const ElaboratedType *T, + std::vector &visitedChildren); + void VisitReferenceTypeChildren(const ReferenceType *T, + std::vector &visitedChildren); + void + VisitInjectedClassNameTypeChildren(const InjectedClassNameType *T, + std::vector &visitedChildren); + void + VisitTemplateTypeParmTypeChildren(const TemplateTypeParmType *T, + std::vector &visitedChildren); + void VisitSubstTemplateTypeParmTypeChildren( + const SubstTemplateTypeParmType *T, + std::vector &visitedChildren); + void VisitTemplateSpecializationTypeChildren( + const TemplateSpecializationType *T, + std::vector &visitedChildren); + void VisitTypedefTypeChildren(const TypedefType *T, + std::vector &visitedChildren); + void VisitAdjustedTypeChildren(const AdjustedType *T, + std::vector &visitedChildren); + void VisitDecayedTypeChildren(const DecayedType *T, + std::vector &visitedChildren); + void VisitDecltypeTypeChildren(const DecltypeType *T, + std::vector &visitedChildren); + void VisitAutoTypeChildren(const AutoType *T, + std::vector &visitedChildren); + void + VisitPackExpansionTypeChildren(const PackExpansionType *T, + std::vector &visitedChildren); + void VisitTypeOfExprTypeChildren(const TypeOfExprType *T, + std::vector &visitedChildren); + void VisitAttributedTypeChildren(const AttributedType *T, + std::vector &visitedChildren); + void + VisitUnaryTransformTypeChildren(const UnaryTransformType *T, + std::vector &visitedChildren); + void VisitComplexTypeChildren(const ComplexType *T, + std::vector &visitedChildren); + + // Children visitors for other types of classes + void VisitTemplateArgChildren(const TemplateArgument &arg); + void VisitTemplateNameChildren(const TemplateName &templateName); + void VisitNestedNameSpecifierChildren(NestedNameSpecifier *qualifier); + + /* Utility methods for DECLS */ + void dumpNumberTemplateParameters(const Decl *D, + const TemplateParameterList *TPL); + + void dumpSourceRange(std::string id, SourceLocation startLoc, + SourceLocation endLoc); + + // These methods return true if the node had been already visited + + bool dumpType(const Type *typeAddr); + bool dumpType(const QualType &type); + bool dumpStmt(const Stmt *stmtAddr); + bool dumpDecl(const Decl *declAddr); + bool dumpAttr(const Attr *attrAddr); + + /* EXTRA */ + void dumpCXXCtorInitializer(const CXXCtorInitializer *Init); }; - -#endif //CLANGASTDUMPER_CLANGASTDUMPER_H +#endif // CLANGASTDUMPER_CLANGASTDUMPER_H diff --git a/ClangAstDumper/src/ClangAstDumper/ClangAstDumperAttr.cpp b/ClangAstDumper/src/ClangAstDumper/ClangAstDumperAttr.cpp index e8928a2fa..f4b69ac90 100644 --- a/ClangAstDumper/src/ClangAstDumper/ClangAstDumperAttr.cpp +++ b/ClangAstDumper/src/ClangAstDumper/ClangAstDumperAttr.cpp @@ -2,62 +2,44 @@ // Created by JoaoBispo on 12/04/2018. // -#include "ClangAstDumper.h" #include "../Clang/ClangNodes.h" +#include "ClangAstDumper.h" #include "clang/AST/Attr.h" #include - using namespace clang; - void ClangAstDumper::VisitAttr(const Attr *A) { - if(dumpAttr(A)) { - return; - } - - visitChildrenAndData(A); - - // Dump data - //dataDumper.dump(clava::DeclNode::DECL, D); + if (dumpAttr(A)) { + return; + } - -// llvm::errs() << DECL_INFO << "\n"; -// llvm::errs() << getId(D) << "\n"; -// DumpDeclData(D); + visitChildrenAndData(A); } -bool ClangAstDumper::dumpAttr(const Attr* attrAddr) { - if(seenAttrs.count(attrAddr) != 0) { - return true; - } - - log(attrAddr); - - // A Dumper is created for each context, - // no need to use id to disambiguate - seenAttrs.insert(attrAddr); +bool ClangAstDumper::dumpAttr(const Attr *attrAddr) { + if (seenAttrs.count(attrAddr) != 0) { + return true; + } - //std::ostringstream extendedId; - //extendedId << attrAddr << "_" << id; + log(attrAddr); + // A Dumper is created for each context, + // no need to use id to disambiguate + seenAttrs.insert(attrAddr); - //dumpIdToClassMap(attrAddr, clava::getClassName(attrAddr)); - - return false; + return false; } - void ClangAstDumper::visitChildrenAndData(const Attr *A) { - // Visit children - visitChildren(A); - - // Dump data - dataDumper.dump(A); + // Visit children + visitChildren(A); - // Dump id - dumpIdToClassMap(A, clava::getClassName(A)); + // Dump data + dataDumper.dump(A); + // Dump id + dumpIdToClassMap(A, clava::getClassName(A)); } diff --git a/ClangAstDumper/src/ClangAstDumper/ClangAstDumperConstants.h b/ClangAstDumper/src/ClangAstDumper/ClangAstDumperConstants.h index 244098c43..8c02b0507 100644 --- a/ClangAstDumper/src/ClangAstDumper/ClangAstDumperConstants.h +++ b/ClangAstDumper/src/ClangAstDumper/ClangAstDumperConstants.h @@ -11,32 +11,31 @@ static const std::string CXX_CTOR_INITIALIZER_BEGIN = ""; static const std::string CXX_CTOR_INITIALIZER_END = ""; // Use in TemplateDecl -static const std::string DUMP_NUMBER_TEMPLATE_PARAMETERS = ""; +static const std::string DUMP_NUMBER_TEMPLATE_PARAMETERS = + ""; // Used in FunctionDecl, such as FunctionTemplateDecl -//static const std::string DUMP_NUMBER_TEMPLATE_ARGUMENTS = ""; -static const std::string DUMP_NAMESPACE_ALIAS_PREFIX = ""; -//static const std::string DUMP_TEMPLATE_ARGS = "