diff --git a/pya2l/aml.g4 b/pya2l/aml.g4 index bcd482c..1ab90ee 100644 --- a/pya2l/aml.g4 +++ b/pya2l/aml.g4 @@ -1,7 +1,7 @@ /* pySART - Simplified AUTOSAR-Toolkit for Python. - (C) 2009-2022 by Christoph Schueler + (C) 2009-2024 by Christoph Schueler All Rights Reserved @@ -33,8 +33,8 @@ amlFile: ; declaration: - ( t = type_definition - | b = block_definition) ';' + ( t = type_definition ';') + | (b = block_definition ';') ; type_definition: @@ -42,13 +42,11 @@ type_definition: ; type_name: - t = tagValue? ( pr = predefined_type_name | st = struct_type_name | ts = taggedstruct_type_name | tu = taggedunion_type_name | en = enum_type_name - ) ; predefined_type_name: @@ -67,9 +65,8 @@ predefined_type_name: ; block_definition: - 'block' tag = tagValue - tn = type_name - | (/* Owed to Vector Informatik... */ '(' mem = member ')' (mult = '*')?) + //block_definition | 'block' tag = tagValue tn = type_name + 'block' tag = tagValue (blk = block_definition | tn = type_name) ; enum_type_name: @@ -91,8 +88,7 @@ struct_type_name: ; struct_member: - m = member ';' - | '(' mstar = member ')' (m0 = '*')? ';' + m = member | block_definition ';' ; member: @@ -104,32 +100,30 @@ array_specifier: ; taggedstruct_type_name: - 'taggedstruct' t1 = identifierValue - | 'taggedstruct' t0 = identifierValue? ('{' (l += taggedstruct_member)* '}' | (l += taggedstruct_member)*) + 'taggedstruct' t0 = identifierValue? '{' (l += taggedstruct_member)* '}' + | 'taggedstruct' t1 = identifierValue ; taggedstruct_member: - ('(' ts0 = taggedstruct_definition ';'? ')' '*' ';') - | ('(' bl0 = block_definition ')' '*' ';') - | (ts1 = taggedstruct_definition ';') - | (bl1 = block_definition ';') - ; + ts1 = taggedstruct_definition ';' + | '(' ts0 = taggedstruct_definition ')' '*' ';' + | bl1 = block_definition ';' + | '(' bl0 = block_definition ')' '*' ';' + ; taggedstruct_definition: - tag = tagValue? mem = member? - | tag = tagValue? '(' mem = member ')' '*' - ; + tag = tagValue mem = member? + | tag = tagValue '(' mem = member ';'? ')' '*' // ';' + ; taggedunion_type_name: - (('taggedunion' t0 = identifierValue? '{' l += tagged_union_member* '}') - | ('taggedunion' t1 = identifierValue)) + 'taggedunion' t0 = identifierValue? '{' l += tagged_union_member* '}' + | 'taggedunion' t1 = identifierValue ; tagged_union_member: - ( - t = tagValue m = member? ';' + t = tagValue m = member? ';' | b = block_definition ';' - ) ; numericValue: diff --git a/pya2l/aml/aml_visitor.cpp b/pya2l/aml/aml_visitor.cpp index 95995f0..12f2edf 100644 --- a/pya2l/aml/aml_visitor.cpp +++ b/pya2l/aml/aml_visitor.cpp @@ -23,8 +23,8 @@ struct TypeRegistry { static TypeRegistry type_registry; template -Type *make_type(const std::string &tag, const Ty &value) { - auto result = new Type(tag, value); +Type *make_type(const Ty &value) { + auto result = new Type(value); type_registry.add(result); return result; } @@ -120,12 +120,13 @@ std::any AmlVisitor::visitType_definition(amlParser::Type_definitionContext *ctx } std::any AmlVisitor::visitType_name(amlParser::Type_nameContext *ctx) { - const auto ctx_t = ctx->t; + //const auto ctx_t = ctx->t; const auto ctx_pr = ctx->pr; const auto ctx_st = ctx->st; const auto ctx_ts = ctx->ts; const auto ctx_tu = ctx->tu; const auto ctx_en = ctx->en; +#if 0 std::string tag_text{}; if (ctx_t) { @@ -134,25 +135,26 @@ std::any AmlVisitor::visitType_name(amlParser::Type_nameContext *ctx) { tag_text = *tag_opt; } } +#endif if (ctx_pr) { auto pdt = std::any_cast(visit(ctx_pr)); - return make_type(tag_text, pdt); + return make_type(pdt); } if (ctx_st) { const auto sst = std::any_cast(visit(ctx_st)); - return make_type(tag_text, sst); + return make_type(sst); } if (ctx_ts) { const auto sst = std::any_cast(visit(ctx_ts)); - return make_type(tag_text, sst); + return make_type(sst); } if (ctx_tu) { const auto sst = std::any_cast(visit(ctx_tu)); - return make_type(tag_text, sst); + return make_type(sst); } if (ctx_en) { const auto enumeration = std::any_cast(visit(ctx_en)); - return make_type(tag_text, enumeration); + return make_type(enumeration); } return {}; @@ -167,13 +169,13 @@ std::any AmlVisitor::visitPredefined_type_name(amlParser::Predefined_type_nameCo std::any AmlVisitor::visitBlock_definition(amlParser::Block_definitionContext *ctx) { const auto ctx_tag = ctx->tag; const auto ctx_tn = ctx->tn; - const auto ctx_mem = ctx->mem; - const auto ctx_mult = ctx->mult; + //const auto ctx_mem = ctx->mem; + //const auto ctx_mult = ctx->mult; std::string tag_text; - bool multiple{ false }; + //bool multiple{ false }; Type *tn = nullptr; - Member member; + //Member member; if (ctx_tag) { const auto tag_opt = std::any_cast(visit(ctx_tag)); @@ -185,7 +187,7 @@ std::any AmlVisitor::visitBlock_definition(amlParser::Block_definitionContext *c if (ctx_tn) { tn = std::any_cast(visit(ctx_tn)); } - +#if 0 if (ctx_mem) { member = std::any_cast(visit(ctx_mem)); } @@ -195,8 +197,8 @@ std::any AmlVisitor::visitBlock_definition(amlParser::Block_definitionContext *c multiple = true; } } - - return BlockDefinition(tag_text, tn, member, multiple); +#endif + return BlockDefinition(tag_text, tn/*, member, multiple*/); } std::any AmlVisitor::visitEnum_type_name(amlParser::Enum_type_nameContext *ctx) { @@ -305,14 +307,14 @@ std::any AmlVisitor::visitStruct_type_name(amlParser::Struct_type_nameContext *c std::any AmlVisitor::visitStruct_member(amlParser::Struct_memberContext *ctx) { const auto ctx_m = ctx->m; - const auto ctx_mstar = ctx->mstar; - const auto ctx_m0 = ctx->m0; + //const auto ctx_mstar = ctx->mstar; + //const auto ctx_m0 = ctx->m0; if (ctx_m) { const auto mem = std::any_cast(visit(ctx_m)); - return StructMember(mem, false); + return StructMember(mem); } - +#if 0 if (ctx_m0) { if (ctx_m0->getText() == "*") { if (ctx_mstar) { @@ -321,6 +323,7 @@ std::any AmlVisitor::visitStruct_member(amlParser::Struct_memberContext *ctx) { } } } +#endif return {}; } diff --git a/pya2l/aml/klasses.hpp b/pya2l/aml/klasses.hpp index 86c243b..25e30f1 100644 --- a/pya2l/aml/klasses.hpp +++ b/pya2l/aml/klasses.hpp @@ -195,11 +195,11 @@ class Member { class BlockDefinition { public: - BlockDefinition() : m_tag(), m_type(nullptr), m_member(), m_multiple(false) { + BlockDefinition() : m_tag(), m_type(nullptr)/*, m_member(), m_multiple(false)*/ { } - explicit BlockDefinition(const std::string& tag, Type* type, const Member& member, bool multiple) : - m_tag(tag), m_type(type), m_member(member), m_multiple(multiple) { + explicit BlockDefinition(const std::string& tag, Type* type/*, const Member& member, bool multiple*/) : + m_tag(tag), m_type(type) /*, m_member(member), m_multiple(multiple)*/ { } const std::string& get_tag() const noexcept { @@ -209,7 +209,7 @@ class BlockDefinition { const Type* get_type() const noexcept { return m_type; } - + #if 0 const Member& get_member() const noexcept { return m_member; } @@ -217,33 +217,33 @@ class BlockDefinition { bool get_multiple() const noexcept { return m_multiple; } - + #endif private: std::string m_tag; Type* m_type; - Member m_member; - bool m_multiple; + //Member m_member; + //bool m_multiple; }; class StructMember { public: - explicit StructMember(const Member& member, bool multiple) : m_member(member), m_multiple(multiple) { + explicit StructMember(const Member& member/*, bool multiple*/) : m_member(member) /*, m_multiple(multiple)*/ { } const Member& get_member() const noexcept { return m_member; } - +#if 0 bool get_multiple() const noexcept { return m_multiple; } - +#endif private: Member m_member; - bool m_multiple; + // bool m_multiple; }; class Struct { @@ -440,24 +440,20 @@ using TypeVariant = std::variant< class Type { public: - Type(const std::string& tag, const AMLPredefinedType& predef_type) : - m_tag(tag), m_type(predef_type), m_disc(TypeType::PredefinedType) { + Type(const AMLPredefinedType& predef_type) : + m_type(predef_type), m_disc(TypeType::PredefinedType) { } - Type(const std::string& tag, const EnumerationOrReferrer& en) : m_tag(tag), m_type(en), m_disc(TypeType::Enumeration) { + Type(const EnumerationOrReferrer& en) : m_type(en), m_disc(TypeType::Enumeration) { } - Type(const std::string& tag, const StructOrReferrer& st) : m_tag(tag), m_type(st), m_disc(TypeType::StructType) { + Type(const StructOrReferrer& st) : m_type(st), m_disc(TypeType::StructType) { } - Type(const std::string& tag, const TaggedStructOrReferrer& st) : m_tag(tag), m_type(st), m_disc(TypeType::TaggedStructType) { + Type(const TaggedStructOrReferrer& st) : m_type(st), m_disc(TypeType::TaggedStructType) { } - Type(const std::string& tag, const TaggedUnionOrReferrer& tu) : m_tag(tag), m_type(tu), m_disc(TypeType::TaggedUnionType) { - } - - const std::string& get_tag() const noexcept { - return m_tag; + Type(const TaggedUnionOrReferrer& tu) : m_type(tu), m_disc(TypeType::TaggedUnionType) { } const TypeVariant& get_type() const noexcept { @@ -470,7 +466,6 @@ class Type { private: - std::string m_tag; TypeVariant m_type; TypeType m_disc; }; diff --git a/pya2l/aml/marshal.cpp b/pya2l/aml/marshal.cpp index d06dfb9..f552f33 100644 --- a/pya2l/aml/marshal.cpp +++ b/pya2l/aml/marshal.cpp @@ -42,18 +42,21 @@ void dumps(std::stringstream& ss, const BlockDefinition& block) { ss << to_binary("B"); const auto& tag = block.get_tag(); const auto type = block.get_type(); - const auto& member = block.get_member(); - const auto& multiple = block.get_multiple(); + //const auto& member = block.get_member(); + //const auto& multiple = block.get_multiple(); ss << to_binary(tag); if (type) { ss << to_binary("T"); dumps(ss, type); - } else if (member.get_type()) { + } +#if 0 + else if (member.get_type()) { ss << to_binary("M"); dumps(ss, member); } ss << to_binary(multiple); +#endif } // TaggedStructDefinition. @@ -155,10 +158,10 @@ void dumps(std::stringstream& ss, const StructOrReferrer& sr) { ss << to_binary(name); ss << to_binary(member_count); for (const auto& sm : members) { - auto mult = sm.get_multiple(); + //auto mult = sm.get_multiple(); const auto& mem = sm.get_member(); dumps(ss, mem); - ss << to_binary(mult); + //ss << to_binary(mult); } } else if (std::holds_alternative(sr)) { auto ref = std::get(sr); @@ -190,8 +193,8 @@ void dumps(std::stringstream& ss, const EnumerationOrReferrer& er) { // Type. void dumps(std::stringstream& ss, const Type* tp_) { auto tp = tp_->get_type(); - auto tag = tp_->get_tag(); - ss << to_binary(tag); + //auto tag = tp_->get_tag(); + //ss << to_binary(tag); std::visit( [&ss, &tp](auto&& arg) { using T = std::decay_t; diff --git a/pya2l/aml/unmarshal.hpp b/pya2l/aml/unmarshal.hpp index 15fbc63..93539af 100644 --- a/pya2l/aml/unmarshal.hpp +++ b/pya2l/aml/unmarshal.hpp @@ -368,20 +368,20 @@ inline Node make_member(const std::vector& array_spec, const Node return res; } -inline Node make_block(const std::string& tag, bool multiple, const Node& type, const Node& member) { +inline Node make_block(const std::string& tag /*, bool multiple*/, const Node& type/*, const Node& member*/) { Node::map_t map = { { "TAG", Node(Node::AmlType::TERMINAL, tag) }, - { "MULTIPLE", Node(Node::AmlType::TERMINAL, multiple) }, + //{ "MULTIPLE", Node(Node::AmlType::TERMINAL, multiple) }, { "TYPE", type }, - { "MEMBER", member }, + //{ "MEMBER", member }, }; auto res = Node(Node::AmlType::BLOCK, map); return res; } -inline Node make_struct_member(bool multiple, const Node& member) { +inline Node make_struct_member(/* bool multiple, */ const Node & member) { Node::map_t map = { - { "MULTIPLE", Node(Node::AmlType::TERMINAL, multiple) }, + // { "MULTIPLE", Node(Node::AmlType::TERMINAL, multiple) }, { "MEMBER", member }, }; auto res = Node(Node::AmlType::STRUCT_MEMBER, map); @@ -462,7 +462,7 @@ class Unmarshaller { auto available = m_reader.from_binary< bool >(); if (available) { - return make_tagged_struct_definition(multiple, /*load_type()*/load_member()); + return make_tagged_struct_definition(multiple, load_member()); } // else TAG only. return make_tagged_struct_definition(multiple, std::nullopt); @@ -522,7 +522,7 @@ class Unmarshaller { } Node load_type() { - const auto& tag = m_reader.from_binary_str(); + // const auto& tag = m_reader.from_binary_str(); // "PD" - AMLPredefinedType // "TS" - TaggedStruct // "TU" - TaggedUnion @@ -565,8 +565,8 @@ class Unmarshaller { for (auto idx = 0UL; idx < member_count; ++idx) { auto member = load_member(); - auto mult = m_reader.from_binary(); - members.emplace_back(make_struct_member(mult, member)); + //auto mult = m_reader.from_binary(); + members.emplace_back(make_struct_member(/*mult, */member)); } return make_struct(name, members); } else if (disc == "R") { @@ -582,11 +582,14 @@ class Unmarshaller { Node member{}; if (disc == "T") { tp = load_type(); - } else if (disc == "M") { + } +#if 0 + else if (disc == "M") { member = load_member(); } - auto multiple = m_reader.from_binary(); - return make_block(tag, multiple, tp, member); +#endif + //auto multiple = m_reader.from_binary(); + return make_block(tag, /*multiple,*/ tp/*, member*/); } Node run() {