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