Skip to content

Commit

Permalink
today()
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed Aug 6, 2024
1 parent 2925fc6 commit ef7a798
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 85 deletions.
44 changes: 19 additions & 25 deletions pya2l/aml.g4
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
pySART - Simplified AUTOSAR-Toolkit for Python.
(C) 2009-2022 by Christoph Schueler <cpu12.gems@googlemail.com>
(C) 2009-2024 by Christoph Schueler <cpu12.gems@googlemail.com>
All Rights Reserved
Expand Down Expand Up @@ -33,22 +33,20 @@ amlFile:
;

declaration:
( t = type_definition
| b = block_definition) ';'
( t = type_definition ';')
| (b = block_definition ';')
;

type_definition:
type_name
;

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:
Expand All @@ -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:
Expand All @@ -91,8 +88,7 @@ struct_type_name:
;

struct_member:
m = member ';'
| '(' mstar = member ')' (m0 = '*')? ';'
m = member | block_definition ';'
;

member:
Expand All @@ -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:
Expand Down
41 changes: 22 additions & 19 deletions pya2l/aml/aml_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ struct TypeRegistry {
static TypeRegistry type_registry;

template<typename Ty>
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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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<AMLPredefinedType>(visit(ctx_pr));
return make_type(tag_text, pdt);
return make_type(pdt);
}
if (ctx_st) {
const auto sst = std::any_cast<StructOrReferrer>(visit(ctx_st));
return make_type(tag_text, sst);
return make_type(sst);
}
if (ctx_ts) {
const auto sst = std::any_cast<TaggedStructOrReferrer>(visit(ctx_ts));
return make_type(tag_text, sst);
return make_type(sst);
}
if (ctx_tu) {
const auto sst = std::any_cast<TaggedUnionOrReferrer>(visit(ctx_tu));
return make_type(tag_text, sst);
return make_type(sst);
}
if (ctx_en) {
const auto enumeration = std::any_cast<EnumerationOrReferrer>(visit(ctx_en));
return make_type(tag_text, enumeration);
return make_type(enumeration);
}

return {};
Expand All @@ -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<string_opt_t>(visit(ctx_tag));
Expand All @@ -185,7 +187,7 @@ std::any AmlVisitor::visitBlock_definition(amlParser::Block_definitionContext *c
if (ctx_tn) {
tn = std::any_cast<Type *>(visit(ctx_tn));
}

#if 0
if (ctx_mem) {
member = std::any_cast<Member>(visit(ctx_mem));
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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<Member>(visit(ctx_m));
return StructMember(mem, false);
return StructMember(mem);
}

#if 0
if (ctx_m0) {
if (ctx_m0->getText() == "*") {
if (ctx_mstar) {
Expand All @@ -321,6 +323,7 @@ std::any AmlVisitor::visitStruct_member(amlParser::Struct_memberContext *ctx) {
}
}
}
#endif
return {};
}

Expand Down
39 changes: 17 additions & 22 deletions pya2l/aml/klasses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -209,41 +209,41 @@ class BlockDefinition {
const Type* get_type() const noexcept {
return m_type;
}

#if 0
const Member& get_member() const noexcept {
return m_member;
}

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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -470,7 +466,6 @@ class Type {

private:

std::string m_tag;
TypeVariant m_type;
TypeType m_disc;
};
Expand Down
17 changes: 10 additions & 7 deletions pya2l/aml/marshal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,21 @@ void dumps(std::stringstream& ss, const BlockDefinition& block) {
ss << to_binary<std::string>("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<std::string>("T");
dumps(ss, type);

} else if (member.get_type()) {
}
#if 0
else if (member.get_type()) {
ss << to_binary<std::string>("M");
dumps(ss, member);
}
ss << to_binary(multiple);
#endif
}

// TaggedStructDefinition.
Expand Down Expand Up @@ -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<Referrer>(sr)) {
auto ref = std::get<Referrer>(sr);
Expand Down Expand Up @@ -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<decltype(arg)>;
Expand Down
Loading

0 comments on commit ef7a798

Please sign in to comment.