Commit | Line | Data |
---|---|---|
d44e3c4f | 1 | /****************************************************************************** |
2 | * Copyright (c) 2000-2016 Ericsson Telecom AB | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * Balasko, Jeno | |
10 | * Raduly, Csaba | |
11 | * | |
12 | ******************************************************************************/ | |
970ed795 EL |
13 | #ifndef COMPFIELD_HH_ |
14 | #define COMPFIELD_HH_ | |
15 | ||
16 | #include "Setting.hh" | |
17 | ||
18 | class RawAST; | |
19 | ||
20 | namespace Common { | |
21 | ||
22 | /** | |
23 | * A class to represent a field of a compound type (sequence/record, | |
24 | * set and choice/union). | |
25 | */ | |
26 | class CompField : public Node, public Location { | |
27 | private: | |
28 | /** The name of the field. Owned by the CompField. */ | |
29 | Identifier *name; | |
30 | /** The type of the field. Owned. */ | |
31 | Type *type; | |
32 | bool is_optional; | |
33 | /** Default value or 0 if no default value. Owned. */ | |
34 | Value *defval; | |
35 | /** Raw attributes or 0. Owned */ | |
36 | RawAST *rawattrib; | |
37 | /** Copy constructor not implemented */ | |
38 | CompField(const CompField& p); | |
39 | /** Assignment disabled */ | |
40 | CompField& operator=(const CompField& p); | |
41 | public: | |
42 | CompField(Identifier *p_name, Type *p_type, bool p_is_optional=false, | |
43 | Value *p_defval=0); | |
44 | virtual ~CompField(); | |
45 | virtual CompField *clone() const; | |
46 | virtual void set_fullname(const string& p_fullname); | |
47 | void set_my_scope(Scope *p_scope); | |
48 | const Identifier& get_name() const { return *name; } | |
49 | Type *get_type() const { return type; } | |
50 | RawAST* get_raw_attrib() const { return rawattrib; } | |
51 | void set_raw_attrib(RawAST* r_attr); | |
52 | bool get_is_optional() const { return is_optional; } | |
53 | bool has_default() const { return defval != 0; } | |
54 | Value *get_defval() const { return defval; } | |
55 | virtual void dump(unsigned level) const; | |
56 | }; | |
57 | ||
58 | /** | |
59 | * Class to represent a map of TTCN-3 StructFieldDef (BNF | |
60 | * 23). Create a CompFieldMap and use add_comp(CompField *) to add | |
61 | * each StructFieldDef (a.k.a. CompRef) into it! Finally, pass | |
62 | * CompFieldMap* to constructors of record/set/union types! | |
63 | */ | |
64 | class CompFieldMap : public Node { | |
65 | private: | |
66 | /** Maps the name of the component to the actual component. */ | |
67 | map<string, CompField> m; | |
68 | /** Contains pointers to the individual CompField s. | |
69 | * The CompFieldMap owns the CompFields and will free them. */ | |
70 | vector<CompField> v; | |
71 | /** Points to the owner type, which shall be a TTCN-3 record, set or | |
72 | * union or an ASN.1 open type. | |
73 | * The CompFieldMap does not own the type. */ | |
74 | Type *my_type; | |
75 | /** Indicates whether the uniqueness of field identifiers has been | |
76 | * verified. */ | |
77 | bool checked; | |
78 | ||
79 | CompFieldMap(const CompFieldMap& p); | |
80 | /** Assignment disabled */ | |
81 | CompFieldMap& operator=(const CompFieldMap& p); | |
82 | public: | |
83 | CompFieldMap() : Node(), m(), v(), my_type(0), checked(false) {} | |
84 | virtual ~CompFieldMap(); | |
85 | virtual CompFieldMap *clone() const; | |
86 | virtual void set_fullname(const string& p_fullname); | |
87 | virtual void set_my_scope(Scope *p_scope); | |
88 | void set_my_type(Type *p_my_type) { my_type = p_my_type; } | |
89 | void add_comp(CompField *comp); | |
90 | size_t get_nof_comps() const { return v.size(); } | |
91 | CompField* get_comp_byIndex(size_t n) const { return v[n]; } | |
92 | bool has_comp_withName(const Identifier& p_name); | |
93 | CompField* get_comp_byName(const Identifier& p_name); | |
94 | private: | |
95 | const char *get_typetype_name() const; | |
96 | /** Check the uniqueness of field identifiers. | |
97 | * Builds the map \c m in the process. */ | |
98 | void chk_uniq(); | |
99 | public: | |
100 | void chk(); | |
101 | virtual void dump(unsigned level) const; | |
102 | }; | |
103 | ||
104 | ||
105 | } /* namespace Common */ | |
106 | #endif /* COMPFIELD_HH_ */ |