ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
plcopen_xml_parser.h
Go to the documentation of this file.
1#pragma once
2
4#include <stdexcept>
5#include <string>
6
7// Thrown when the PLCopen XML file cannot be parsed or has a schema error.
8struct LdParseError : std::runtime_error
9{
10 explicit LdParseError(const std::string &msg) : std::runtime_error(msg)
11 {
12 }
13};
14
15// Thrown when an unsupported Tier-2+ construct is encountered.
16struct UnsupportedConstructError : std::runtime_error
17{
18 std::string construct;
19 int tier;
20 UnsupportedConstructError(const std::string &name, int t)
21 : std::runtime_error(
22 "UnsupportedConstruct(" + name + ", tier=" + std::to_string(t) + ")"),
23 construct(name),
24 tier(t)
25 {
26 }
27};
28
30{
31public:
32 // Parse a PLCopen XML file and return the typed AST.
33 // Throws LdParseError on schema or structural errors.
34 // Throws UnsupportedConstructError for Tier-2+ constructs.
35 LdAst parse(const std::string &path);
36
37private:
38 // Schema normalisation: absorb vendor-specific deviations before building
39 // AST.
40 void normalise(struct pugi_doc_wrapper &doc);
41
43 var_kind_from_string(const std::string &type_str, bool derived = false);
44 ContactKind contact_kind_from_string(const std::string &s);
45 CoilKind coil_kind_from_string(const std::string &s);
46 FBKind fb_kind_from_string(const std::string &s);
47
48 // Parse helpers
49 VarDecl parse_var_decl(const void *xml_node);
50 RungElement parse_rung_element(const void *xml_node);
51 RungNode parse_rung(const void *xml_node);
52 NetworkNode parse_network(const void *xml_node);
53
54 std::string source_file_;
55
56 // Variables the graphical resolver has to invent: function-block pins and
57 // the accumulators that OR parallel paths together. Appended to the AST's
58 // declarations once every network has been resolved.
59 std::vector<VarDecl> synth_vars_;
60
61 // Cyclic task period in milliseconds, used to convert IEC duration literals
62 // into the scan ticks the fixed-tick timer model counts. Zero means the
63 // program declares no task, in which case one tick is taken to be one ms.
64 unsigned scan_interval_ms_ = 0;
65};
Definition plcopen_xml_parser.h:30
LdAst parse(const std::string &path)
Definition plcopen_xml_parser.cpp:1833
FBKind
Definition ld_ast.h:66
ContactKind
Definition ld_ast.h:20
CoilKind
Definition ld_ast.h:48
VarKind
Definition ld_ast.h:172
Definition path.py:1
Definition exception.cpp:51
Definition ld_ast.h:256
LdParseError(const std::string &msg)
Definition plcopen_xml_parser.h:10
Definition ld_ast.h:161
Definition ld_ast.h:141
Definition ld_ast.h:153
std::string construct
Definition plcopen_xml_parser.h:18
UnsupportedConstructError(const std::string &name, int t)
Definition plcopen_xml_parser.h:20
int tier
Definition plcopen_xml_parser.h:19
Definition ld_ast.h:182
Definition plcopen_xml_parser.cpp:1458