diff --git a/project/src/transpiler/CMakeLists.txt b/project/src/transpiler/CMakeLists.txt index 167a9db2..578910d4 100755 --- a/project/src/transpiler/CMakeLists.txt +++ b/project/src/transpiler/CMakeLists.txt @@ -32,6 +32,8 @@ set(SOURCE_FILES aliases.h tracer.h process_variables.h + enumdecl.h + enum_manager.h # Sources main.cpp @@ -47,7 +49,9 @@ set(SOURCE_FILES recorddecl.cpp record_manager.cpp tracer.cpp - process_variables.cpp) + process_variables.cpp + enumdecl.cpp + enum_manager.cpp) # add_executable(recvisitor main.cpp) add_executable(c2eo ${SOURCE_FILES}) diff --git a/project/src/transpiler/analyzers.cpp b/project/src/transpiler/analyzers.cpp index a26bb57a..7b935538 100755 --- a/project/src/transpiler/analyzers.cpp +++ b/project/src/transpiler/analyzers.cpp @@ -100,7 +100,7 @@ void EnumDeclAnalyzer::run(const MatchFinder::MatchResult &result) { if (context == nullptr) { context = result.Context; } - const auto *ED = result.Nodes.getNodeAs("enumDecl"); + const auto *ED = result.Nodes.getNodeAs("enumDecl"); if (ED == nullptr) { return; } diff --git a/project/src/transpiler/analyzers.h b/project/src/transpiler/analyzers.h index 6f4db680..a8aadcbe 100755 --- a/project/src/transpiler/analyzers.h +++ b/project/src/transpiler/analyzers.h @@ -71,7 +71,6 @@ class DeclBaseVarGlobalMemoryAnalyzer const clang::ast_matchers::MatchFinder::MatchResult &result) override; }; -#endif // PROJECT_SRC_TRANSPILER_ANALYZERS_H_ class EnumDeclAnalyzer : public clang::ast_matchers::MatchFinder::MatchCallback { public: @@ -85,4 +84,4 @@ class EnumDeclAnalyzer const clang::ast_matchers::MatchFinder::MatchResult &result) override; }; -#endif // C2EO_SRC_TRANSPILER_ANALYZERS_H_ +#endif // PROJECT_SRC_TRANSPILER_ANALYZERS_H_ diff --git a/project/src/transpiler/enum_manager.cpp b/project/src/transpiler/enum_manager.cpp index d754c403..00735a55 100644 --- a/project/src/transpiler/enum_manager.cpp +++ b/project/src/transpiler/enum_manager.cpp @@ -1,4 +1,28 @@ -#include "enum_manager.h" +/* + * The MIT License (MIT) + * + * Copyright (c) 2021-2022 c2eo team + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "src/transpiler/enum_manager.h" EnumType EnumManager::Add(const clang::EnumDecl *id, std::string name, size_t size, diff --git a/project/src/transpiler/enum_manager.h b/project/src/transpiler/enum_manager.h index 80047fd6..cfef6642 100644 --- a/project/src/transpiler/enum_manager.h +++ b/project/src/transpiler/enum_manager.h @@ -1,13 +1,38 @@ -#ifndef C2EO_ENUM_MANAGER_H -#define C2EO_ENUM_MANAGER_H +/* + * The MIT License (MIT) + * + * Copyright (c) 2021-2022 c2eo team + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef PROJECT_SRC_TRANSPILER_ENUM_MANAGER_H_ +#define PROJECT_SRC_TRANSPILER_ENUM_MANAGER_H_ #include #include #include +#include #include "clang/AST/Decl.h" -#include "eo_object.h" -#include "memory_manager.h" +#include "src/transpiler/eo_object.h" +#include "src/transpiler/memory_manager.h" class EnumConstantType { public: @@ -34,4 +59,4 @@ class EnumManager { std::vector enum_types; }; -#endif // C2EO_ENUM_MANAGER_H +#endif // PROJECT_SRC_TRANSPILER_ENUM_MANAGER_H_ diff --git a/project/src/transpiler/enumdecl.cpp b/project/src/transpiler/enumdecl.cpp index 57411cfb..1dfa9d2e 100644 --- a/project/src/transpiler/enumdecl.cpp +++ b/project/src/transpiler/enumdecl.cpp @@ -1,10 +1,36 @@ -#include "enumdecl.h" +/* + * The MIT License (MIT) + * + * Copyright (c) 2021-2022 c2eo team + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "src/transpiler/enumdecl.h" #include +#include +#include -#include "transpile_helper.h" -#include "unit_transpiler.h" -#include "vardecl.h" +#include "src/transpiler/transpile_helper.h" +#include "src/transpiler/unit_transpiler.h" +#include "src/transpiler/vardecl.h" EnumType ProcessEnumDecl(const clang::EnumDecl *ED) { if (ED == nullptr) { diff --git a/project/src/transpiler/enumdecl.h b/project/src/transpiler/enumdecl.h index 2d8dba21..cf824749 100644 --- a/project/src/transpiler/enumdecl.h +++ b/project/src/transpiler/enumdecl.h @@ -1,5 +1,29 @@ -#ifndef C2EO_ENUMDECL_H -#define C2EO_ENUMDECL_H +/* + * The MIT License (MIT) + * + * Copyright (c) 2021-2022 c2eo team + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef PROJECT_SRC_TRANSPILER_ENUMDECL_H_ +#define PROJECT_SRC_TRANSPILER_ENUMDECL_H_ #include "clang/AST/ASTContext.h" #include "clang/AST/Decl.h" @@ -8,9 +32,9 @@ #include "clang/Frontend/FrontendActions.h" #include "clang/Tooling/CommonOptionsParser.h" #include "clang/Tooling/Tooling.h" -#include "enum_manager.h" #include "llvm/Support/CommandLine.h" +#include "src/transpiler/enum_manager.h" EnumType ProcessEnumDecl(const clang::EnumDecl *ED); -#endif // C2EO_ENUMDECL_H +#endif // PROJECT_SRC_TRANSPILER_ENUMDECL_H_ diff --git a/project/src/transpiler/matchers.cpp b/project/src/transpiler/matchers.cpp index c39aef44..a9d5356d 100755 --- a/project/src/transpiler/matchers.cpp +++ b/project/src/transpiler/matchers.cpp @@ -25,6 +25,7 @@ #include "src/transpiler/matchers.h" using clang::ast_matchers::DeclarationMatcher; +using clang::ast_matchers::enumDecl; using clang::ast_matchers::functionDecl; using clang::ast_matchers::MatchFinder; using clang::ast_matchers::recordDecl; diff --git a/project/src/transpiler/transpile_helper.cpp b/project/src/transpiler/transpile_helper.cpp index 5837c518..13946bbf 100644 --- a/project/src/transpiler/transpile_helper.cpp +++ b/project/src/transpiler/transpile_helper.cpp @@ -51,6 +51,7 @@ using clang::DeclRefExpr; using clang::DeclStmt; using clang::DefaultStmt; using clang::DoStmt; +using clang::EnumConstantDecl; using clang::Expr; using clang::FloatingLiteral; using clang::ForStmt; @@ -133,6 +134,7 @@ EOObject GetCaseCondEOObject(const vector &all_cases, const EOObject &switch_exp, size_t i); extern UnitTranspiler transpiler; +extern ASTContext *context; EOObject GetFunctionBody(const clang::FunctionDecl *FD) { if (!FD->hasBody()) { @@ -1203,7 +1205,6 @@ EOObject GetSeqForBodyEOObject(const Stmt *p_stmt) { } uint64_t GetTypeSize(QualType qual_type) { - extern ASTContext *context; const clang::Type *type_ptr = qual_type.getTypePtr(); TypeInfo type_info = context->getTypeInfo(type_ptr); uint64_t type_size = type_info.Width; @@ -1219,7 +1220,6 @@ uint64_t GetTypeSize(QualType qual_type) { } std::string GetPostfix(QualType qual_type) { - extern ASTContext *context; const clang::Type *type_ptr = qual_type.getTypePtr(); TypeInfo type_info = context->getTypeInfo(type_ptr); uint64_t type_size = type_info.Width; @@ -1255,7 +1255,6 @@ std::string GetPostfix(QualType qual_type) { } std::string GetTypeName(QualType qual_type) { - extern ASTContext *context; const clang::Type *type_ptr = qual_type.getTypePtr(); TypeInfo type_info = context->getTypeInfo(type_ptr); uint64_t type_size = type_info.Width;