Skip to content

Commit

Permalink
today()
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed Jul 2, 2024
1 parent f1ba3c1 commit 9a47b99
Show file tree
Hide file tree
Showing 10 changed files with 660 additions and 96 deletions.
7 changes: 1 addition & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ antlr_target(AMLParser ${CMAKE_CURRENT_SOURCE_DIR}/pya2l/aml.g4 LEXER PARSER
)

add_executable(aml_tester ${CMAKE_CURRENT_SOURCE_DIR}/pya2l/aml_parser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pya2l/aml/aml_visitor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pya2l/aml/aml_visitor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/pya2l/aml/marshal.cpp ${CMAKE_CURRENT_SOURCE_DIR}/pya2l/aml/unmarshal.cpp
${ANTLR_AMLParser_CXX_OUTPUTS}
)

Expand All @@ -128,11 +128,6 @@ include_directories(${ANTLR_pyA2LLexer_OUTPUT_DIR}/pya2l)
include_directories(${ANTLR_AMLParser_OUTPUT_DIR}/pya2l)


message("AML output: " ${ANTLR_AMLParser_OUTPUT_DIR})
message("AML CXX out " ${ANTLR_AMLParser_CXX_OUTPUTS})
message("LXR output: " ${ANTLR_pyA2LLexer_OUTPUT_DIR})
message("NS: " ${Antlr4_NamespaceOption})

# message("PROJ " ${PROJECT_SOURCE_DIR})
# message("AML-Output: " ${ANTLR_AMLParser_OUTPUTS} " cxx: " ${ANTLR_AMLParser_CXX_OUTPUTS})

Expand Down
3 changes: 3 additions & 0 deletions build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def banner(msg: str) -> None:
print("=" * 80)


# tool["cs_build"]={"antlr4_version": "4.13.0"}


def build_extension(debug: bool = False) -> None:
print("CMakeBuild::build_extension()")

Expand Down
13 changes: 12 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions pya2l/a2lparser_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

// #include <iostream>
#include <sstream>

#include "a2lparser.hpp"

// #include "ifdata.hpp"
// #include "line_map.hpp"
#include "preprocessor.hpp"

namespace py = pybind11;
Expand Down
35 changes: 18 additions & 17 deletions pya2l/aml/aml_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct TypeRegistry {
static TypeRegistry type_registry;

template<typename Ty>
Type *make_type(const std::string& tag, const Ty &value) {
Type *make_type(const std::string &tag, const Ty &value) {
auto result = new Type(tag, value);
type_registry.add(result);
return result;
Expand Down Expand Up @@ -82,19 +82,19 @@ std::string strip(std::string str, char chr = '"') {
std::any AmlVisitor::visitAmlFile(amlParser::AmlFileContext *ctx) {
const auto ctx_d = ctx->d;

std::vector< Declaration> decls;
std::vector<Declaration> decls;

for (const auto &elem_ctx : ctx_d) {
decls.emplace_back(std::any_cast<Declaration>(visit(elem_ctx)));
}

return decls;
return AmlFile(decls);
}

std::any AmlVisitor::visitDeclaration(amlParser::DeclarationContext *ctx) {
const auto ctx_t = ctx->t;
const auto ctx_b = ctx->b;
TypeDefinition td;
TypeDefinition td;
BlockDefinition block;

if (ctx_t) {
Expand All @@ -110,10 +110,10 @@ std::any AmlVisitor::visitDeclaration(amlParser::DeclarationContext *ctx) {

std::any AmlVisitor::visitType_definition(amlParser::Type_definitionContext *ctx) {
const auto td_ctx = ctx->type_name();
Type * tp = nullptr;
Type *tp = nullptr;

if (td_ctx) {
tp = std::any_cast<Type*>(td_ctx);
tp = std::any_cast<Type *>(visit(td_ctx));
}

return TypeDefinition(tp);
Expand All @@ -126,7 +126,6 @@ std::any AmlVisitor::visitType_name(amlParser::Type_nameContext *ctx) {
const auto ctx_ts = ctx->ts;
const auto ctx_tu = ctx->tu;
const auto ctx_en = ctx->en;
std::string pdt_name;
std::string tag_text{};

if (ctx_t) {
Expand All @@ -136,8 +135,8 @@ std::any AmlVisitor::visitType_name(amlParser::Type_nameContext *ctx) {
}
}
if (ctx_pr) {
pdt_name = std::any_cast<std::string>(visit(ctx_pr));
return make_type(tag_text, pdt_name);
auto pdt = std::any_cast<AMLPredefinedType>(visit(ctx_pr));
return make_type(tag_text, pdt);
}
if (ctx_st) {
const auto sst = std::any_cast<StructOrReferrer>(visit(ctx_st));
Expand All @@ -162,7 +161,7 @@ std::any AmlVisitor::visitType_name(amlParser::Type_nameContext *ctx) {
std::any AmlVisitor::visitPredefined_type_name(amlParser::Predefined_type_nameContext *ctx) {
const std::string name = ctx->name->getText();

return name;
return createPredefinedType(name);
}

std::any AmlVisitor::visitBlock_definition(amlParser::Block_definitionContext *ctx) {
Expand Down Expand Up @@ -408,12 +407,10 @@ std::any AmlVisitor::visitTaggedstruct_member(amlParser::Taggedstruct_memberCont
auto multiple{ false };

if (ctx_ts0) {
const auto ts = visit(ctx_ts0);
tsd = std::any_cast<TaggedStructDefinition>(ts);
multiple = true;
tsd = std::any_cast<TaggedStructDefinition>(visit(ctx_ts0));
} else if (ctx_ts1) {
multiple = true;
const auto ts = visit(ctx_ts1);
tsd = std::any_cast<TaggedStructDefinition>(ts);
tsd = std::any_cast<TaggedStructDefinition>(visit(ctx_ts1));
}

if (ctx_bl0) {
Expand All @@ -428,13 +425,17 @@ std::any AmlVisitor::visitTaggedstruct_member(amlParser::Taggedstruct_memberCont

std::any AmlVisitor::visitTaggedstruct_definition(amlParser::Taggedstruct_definitionContext *ctx) {
const auto length = std::size(ctx->children);
const auto multiple = (length == 5); // !!CHECK!!
const auto multiple = (length > 4);
const auto ctx_tag = ctx->tag;
const auto ctx_mem = ctx->mem;

std::string tag{};
Member member;

if (multiple) {
auto x = 9;
}

if (ctx_tag) {
const auto str_opt = std::any_cast<string_opt_t>(visit(ctx_tag));
if (str_opt) {
Expand All @@ -446,7 +447,7 @@ std::any AmlVisitor::visitTaggedstruct_definition(amlParser::Taggedstruct_defini
member = std::any_cast<Member>(visit(ctx_mem));
}

return TaggedStructDefinition(tag, member);
return TaggedStructDefinition(tag, member, multiple);
}

std::any AmlVisitor::visitTaggedunion_type_name(amlParser::Taggedunion_type_nameContext *ctx) {
Expand Down
Loading

0 comments on commit 9a47b99

Please sign in to comment.