Skip to content

Commit

Permalink
today()
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed Aug 3, 2024
1 parent 1ee8310 commit cf86b19
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 9 deletions.
11 changes: 9 additions & 2 deletions pya2l/aml/marshal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ void dumps(std::stringstream& ss, const Member& mem) {
ss << to_binary<std::uint32_t>(arr);
}
const auto& tp = mem.get_type();
dumps(ss, tp);
if (tp != nullptr) {
dumps(ss, tp);
}
else {
std::cout << "nullptr\n";
}

}

// Referrer.
Expand Down Expand Up @@ -58,7 +64,8 @@ void dumps(std::stringstream& ss, const TaggedStructDefinition& tsd) {
ss << to_binary<bool>(multiple);
if (tp) {
ss << to_binary<bool>(true); // available.
dumps(ss, tp);
//dumps(ss, tp);
dumps(ss, member); // FIXED!!!
} else {
// Tag-only.
ss << to_binary<bool>(false); // NOT available.
Expand Down
49 changes: 47 additions & 2 deletions pya2l/aml/unmarshal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Node {
TAGGED_UNION_MEMBER,
};

using terminal_t = std::variant<std::monostate, long long, float, std::string>;
using terminal_t = std::variant<std::monostate, long long, double, std::string>;
using list_t = std::vector<Node>;
using map_t = std::map<std::string, Node>;

Expand Down Expand Up @@ -194,6 +194,51 @@ class Node {
return {};
}

std::map<std::string, std::tuple<const Node*, bool, bool>> get_tagged_struct_members() const noexcept {

std::map<std::string, std::tuple<const Node*, bool, bool>> result;

if (m_aml_type != AmlType::TAGGED_STRUCT) {
return {};
}
const auto& members = m_map.at("MEMBERS");

for (const auto& member : members.list()) {
const auto& mmap = member.map();
const auto& ts_member = mmap.at("MEMBER");
const auto& ts_tag = mmap.at("TAG").get_string();
const auto& ts_def = ts_member.map().at("DEFINITION");
const auto ts_mult = bool(ts_member.map().at("MULTIPLE").get_int());

const auto& tsd_type = ts_def.map().at("TYPE");
const auto tsd_mult = bool(ts_def.map().at("MULTIPLE").get_int());
result.emplace(ts_tag, std::forward_as_tuple( & tsd_type, ts_mult, tsd_mult ));
}
return result;
}

long long get_int() const noexcept {
if (m_node_type != NodeType::TERMINAL) {
return {};
}
return std::get<long long>(value());
}

double get_float() const noexcept {
if (m_node_type != NodeType::TERMINAL) {
return {};
}
return std::get<double>(value());
}

std::string get_string() const noexcept {
if (m_node_type != NodeType::TERMINAL) {
return {};
}
return std::get<std::string>(value());
}


///////////////////////////////////////////////////////////////

AmlType aml_type() const noexcept {
Expand Down Expand Up @@ -420,7 +465,7 @@ class Unmarshaller {
auto available = m_reader.from_binary< bool >();

if (available) {
return make_tagged_struct_definition(multiple, load_type());
return make_tagged_struct_definition(multiple, /*load_type()*/load_member());
}
// else TAG only.
return make_tagged_struct_definition(multiple, std::nullopt);
Expand Down
8 changes: 6 additions & 2 deletions pya2l/aml_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ using namespace antlr4;

void marshal(std::stringstream& ss, const AmlFile& amlf);

const std::string BASE{ "C:/csProjects/" };
//const std::string BASE{ ""C:/Users/HP/PycharmProjects/" };


int main(int argc, const char* argv[]) {
std::ifstream stream;

Expand All @@ -24,7 +28,7 @@ int main(int argc, const char* argv[]) {
// stream.open("C:/csProjects/pyA2L/pya2l/examples/AML.tmp");
// stream.open("C:/csProjects/pyA2L/pya2l/PreProcessor/AML.tmp");
// stream.open("C:\\Users\\HP\\PycharmProjects\\pyA2L\\pya2l\\examples\\vector.aml");
stream.open("C:/Users/HP/PycharmProjects/pyA2L/pya2l/examples/AML.tmp");
stream.open(BASE + "pyA2L/pya2l/examples/AML.tmp");
}

ANTLRInputStream input(stream);
Expand All @@ -49,7 +53,7 @@ int main(int argc, const char* argv[]) {
marshal(ss, res);
// std::cout << ss.str();

constexpr auto FNAME{ "C:/Users/HP/PycharmProjects/pyA2L/pya2l/examples/aml_dump.bin" };
const auto FNAME{ BASE + "pyA2L/pya2l/examples/aml_dump.bin" };

std::ofstream outf(FNAME, std::ios::binary);
outf << ss.str();
Expand Down
37 changes: 34 additions & 3 deletions pya2l/if_data_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,50 @@ class IfDataParser {
}

void tagged_struct_type() {
auto token = current_token();
if (token) {
auto [tp, text] = *token;
const auto tos = top();
const auto& ts_members = tos->get_tagged_struct_members();
const auto& [type, b0, b1] = ts_members.at(text);
}
}

void tagged_union_type() {
auto token = current_token();
if (token) {
auto [tp, text] = *token;
const auto member = top()->find_tag(text);
m_grammar.push(member);
const auto& [arr_spec, type] = member->get_type();
m_grammar.push(type);
consume();
do_type();
m_grammar.pop();
}
}

void do_type() {
const auto tos = top();
switch (tos->aml_type()) {
case Node::AmlType::STRUCT:
struct_type();
break;
case Node::AmlType::TAGGED_STRUCT:
tagged_struct_type();
break;
case Node::AmlType::TAGGED_UNION:
tagged_union_type();
break;
case Node::AmlType::ENUMERATION:
enumeration_type();
break;
case Node::AmlType::PDT:
pdt_type();
break;
default:
std::cerr << "Unknown type: " << std::endl;
break;
}
}

void enumeration_type() {
Expand All @@ -166,16 +194,19 @@ class IfDataParser {
token_t m_current_token;
};

const std::string BASE{ "C:/csProjects/" };
//const std::string BASE{ ""C:/Users/HP/PycharmProjects/" };

int main() {
std::ifstream stream;

stream.open("C:/Users/HP/PycharmProjects/pyA2L/pya2l/examples/some_if_data.txt");
stream.open(BASE + "pyA2L/pya2l/examples/some_if_data.txt");

ANTLRInputStream input(stream);

auto ifd_lexer = a2llg(&input);

auto root = load_grammar("C:/Users/HP/PycharmProjects/pyA2L/pya2l/examples/aml_dump.bin");
auto root = load_grammar(BASE + "pyA2L/pya2l/examples/aml_dump.bin");

std::string TEXT("/begin IF_DATA ETK\n"
"ADDRESS_MAPPING\n"
Expand Down

0 comments on commit cf86b19

Please sign in to comment.