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 | * Baji, Laszlo | |
10 | * Balasko, Jeno | |
11 | * Raduly, Csaba | |
12 | * | |
13 | ******************************************************************************/ | |
970ed795 EL |
14 | #ifndef COMPTYPE_HH_ |
15 | #define COMPTYPE_HH_ | |
16 | ||
17 | #include "Setting.hh" | |
18 | ||
19 | struct output_struct_t; | |
20 | ||
21 | namespace Ttcn { | |
22 | class Definition; | |
23 | class WithAttribPath; | |
24 | class Reference; | |
25 | } | |
26 | ||
27 | namespace Common { | |
28 | ||
29 | class CompTypeRefList; | |
30 | ||
31 | /** Class to represent the definition of a component type */ | |
32 | class ComponentTypeBody : public Scope, public Location { | |
33 | public: | |
34 | /** represents the check state of this component | |
35 | * every check increments the value */ | |
36 | enum check_state_t { | |
37 | CHECK_INITIAL, /**< initial state before checks */ | |
38 | CHECK_WITHATTRIB, /**< with attribute checked, | |
39 | set by chk_extends_attr() */ | |
40 | CHECK_EXTENDS, /**< component extension checked, | |
41 | set by chk_extends() */ | |
42 | CHECK_DEFUNIQ, /**< definitions id uniqueness checked, | |
43 | set by chk_defs_uniq() */ | |
44 | CHECK_OWNDEFS, /**< own definitions checked, | |
45 | set by chk_my_defs() */ | |
46 | CHECK_EXTDEFS, /**< definitions inherited by attribute checked, | |
47 | set by chk_attr_ext_defs() */ | |
48 | CHECK_FINAL /**< everything was checked, set by chk() */ | |
49 | }; | |
50 | private: | |
51 | /** Identifier of this component */ | |
52 | const Identifier *comp_id; | |
53 | /** the Type that contains this, needed to reach w_attrib_path */ | |
54 | Type *my_type; | |
55 | /** tells which checks have already been performed */ | |
56 | check_state_t check_state; | |
57 | /** true when chk() is running */ | |
58 | bool checking; | |
59 | /** Vector containing own definitions. Used for building. */ | |
60 | vector<Ttcn::Definition> def_v; | |
61 | /** component references from the "extends" part or NULL if there were no */ | |
62 | CompTypeRefList *extends_refs; | |
63 | /** component references from the extends attribute or NULL */ | |
64 | CompTypeRefList *attr_extends_refs; | |
65 | /** map of own definitions equal to inherited by extension attribute | |
66 | * needed to initialize the the value with own value, | |
67 | * pointers to the defs are owned by def_v */ | |
68 | map<string, Ttcn::Definition> orig_defs_m; | |
69 | /** map of my and inherited definitions */ | |
70 | map<string, Ttcn::Definition> all_defs_m; | |
71 | /** compatibility map for is_compatible() function, filled in chk(), | |
72 | * all components inherited along pure extends-keyword path have the value | |
73 | * equal to the key, others have NULL value */ | |
74 | map<ComponentTypeBody*, ComponentTypeBody> compatible_m; | |
75 | void init_compatibility(CompTypeRefList *crl, bool is_standard_extends); | |
76 | private: | |
77 | /** Copy constructor not implemented */ | |
78 | ComponentTypeBody(const ComponentTypeBody& p); | |
79 | /** Assignment not implemented */ | |
80 | ComponentTypeBody& operator=(const ComponentTypeBody& p); | |
81 | public: | |
82 | ComponentTypeBody() | |
83 | : Scope(), comp_id(0), my_type(0), check_state(CHECK_INITIAL), | |
84 | checking(false), def_v(), extends_refs(0), attr_extends_refs(0), | |
85 | orig_defs_m(), all_defs_m(), compatible_m() { } | |
86 | ~ComponentTypeBody(); | |
87 | ComponentTypeBody *clone() const; | |
88 | ||
89 | void set_id(const Identifier *p_id) { comp_id = p_id; } | |
90 | Identifier const * get_id() const { return comp_id; } | |
91 | void set_my_type(Type *p_type) { my_type = p_type; } | |
92 | Type* get_my_type() { return my_type; } | |
93 | ||
94 | virtual void set_fullname(const string& p_fullname); | |
95 | virtual void set_my_scope(Scope *p_scope); | |
96 | ||
97 | bool has_local_ass_withId(const Identifier& p_id); | |
98 | Assignment* get_local_ass_byId(const Identifier& p_id); | |
99 | bool has_ass_withId(const Identifier& p_id); | |
100 | bool is_own_assignment(const Assignment* p_ass); | |
101 | size_t get_nof_asss(); | |
102 | Assignment* get_ass_byIndex(size_t p_i); | |
103 | virtual Assignment *get_ass_bySRef(Ref_simple *p_ref); | |
104 | ||
105 | void add_extends(CompTypeRefList *p_crl); | |
106 | ||
107 | /** Returns if this component is compatible with the given other component. | |
108 | * This component is compatible with other component if this extends the | |
109 | * other component (with standard extends or with extension attribute) | |
110 | * directly or this extends a component which is compatible with other */ | |
111 | bool is_compatible(ComponentTypeBody *other); | |
112 | /** Adds the assignment p_ass and becomes the owner of it. | |
113 | * The uniqueness of the identifier is not checked. */ | |
114 | void add_ass(Ttcn::Definition *p_ass); | |
115 | /** Prints the contents of the component. */ | |
116 | void dump(unsigned level) const; | |
117 | private: | |
118 | void chk_extends_attr(); | |
119 | public: | |
120 | /** Check component extends recursions (extends keyword and attribute) */ | |
121 | void chk_recursion(ReferenceChain& refch); | |
122 | private: | |
123 | void collect_defs_from_standard_extends(); | |
124 | void collect_defs_from_attribute_extends(); | |
125 | /** Checks the AST for correct component extensions. */ | |
126 | void chk_extends(); | |
127 | /** Checks definition id uniqueness */ | |
128 | void chk_defs_uniq(); | |
129 | /** Checks all own definitions */ | |
130 | void chk_my_defs(); | |
131 | /** Checks definitions inherited with attribute extends */ | |
132 | void chk_attr_ext_defs(); | |
133 | public: | |
134 | /** perform all checks */ | |
135 | void chk(check_state_t required_check_state = CHECK_FINAL); | |
136 | /** Sets the genname of embedded definitions using \a prefix. */ | |
137 | void set_genname(const string& prefix); | |
138 | void generate_code(output_struct_t *target); | |
139 | /** Generates a pair of C++ strings that contain the module name and name | |
140 | * of the component type and appends them to \a str. */ | |
141 | char *generate_code_comptype_name(char *str); | |
142 | ||
143 | void set_parent_path(Ttcn::WithAttribPath* p_path); | |
144 | }; | |
145 | ||
146 | /** Class to represent a list of references to components */ | |
147 | class CompTypeRefList : public Node, public Location { | |
148 | private: | |
149 | bool checked; | |
150 | vector<Ttcn::Reference> comp_ref_v; | |
151 | /** Pointers to ComponentTypeBody objects in the AST, filled by chk() */ | |
152 | map<ComponentTypeBody*,Ttcn::Reference> comp_body_m; | |
153 | /** Contains the keys of comp_body_m in the order determined by comp_ref_v, | |
154 | * used to perform checks in deterministic order ( the order of keys in | |
155 | * comp_body_m is platform dependent */ | |
156 | vector<ComponentTypeBody> comp_body_v; | |
157 | /** Copy constructor not implemented */ | |
158 | CompTypeRefList(const CompTypeRefList& p); | |
159 | /** Assignment disabled */ | |
160 | CompTypeRefList& operator=(const CompTypeRefList& p); | |
161 | public: | |
162 | CompTypeRefList() | |
163 | : checked(false), comp_ref_v(), comp_body_m(), comp_body_v() { } | |
164 | ~CompTypeRefList(); | |
165 | CompTypeRefList *clone() const; | |
166 | void add_ref(Ttcn::Reference *p_ref); | |
167 | void dump(unsigned level) const; | |
168 | virtual void set_fullname(const string& p_fullname); | |
169 | void chk_uniq(); | |
170 | void chk(ComponentTypeBody::check_state_t required_check_state); | |
171 | void chk_recursion(ReferenceChain& refch); | |
172 | virtual void set_my_scope(Scope *p_scope); | |
173 | ||
174 | /** utility functions to access comp_body_m */ | |
175 | size_t get_nof_comps(); | |
176 | ComponentTypeBody *get_nth_comp_body(size_t i); | |
177 | Ttcn::Reference *get_nth_comp_ref(size_t i); | |
178 | bool has_comp_body(ComponentTypeBody *cb); | |
179 | }; | |
180 | ||
181 | } /* namespace Common */ | |
182 | #endif /* COMPTYPE_HH_ */ |