Sync with 5.4.0
[deliverable/titan.core.git] / compiler2 / CompField.hh
1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2015 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 COMPFIELD_HH_
9 #define COMPFIELD_HH_
10
11 #include "Setting.hh"
12
13 class RawAST;
14
15 namespace Common {
16
17 /**
18 * A class to represent a field of a compound type (sequence/record,
19 * set and choice/union).
20 */
21 class CompField : public Node, public Location {
22 private:
23 /** The name of the field. Owned by the CompField. */
24 Identifier *name;
25 /** The type of the field. Owned. */
26 Type *type;
27 bool is_optional;
28 /** Default value or 0 if no default value. Owned. */
29 Value *defval;
30 /** Raw attributes or 0. Owned */
31 RawAST *rawattrib;
32 /** Copy constructor not implemented */
33 CompField(const CompField& p);
34 /** Assignment disabled */
35 CompField& operator=(const CompField& p);
36 public:
37 CompField(Identifier *p_name, Type *p_type, bool p_is_optional=false,
38 Value *p_defval=0);
39 virtual ~CompField();
40 virtual CompField *clone() const;
41 virtual void set_fullname(const string& p_fullname);
42 void set_my_scope(Scope *p_scope);
43 const Identifier& get_name() const { return *name; }
44 Type *get_type() const { return type; }
45 RawAST* get_raw_attrib() const { return rawattrib; }
46 void set_raw_attrib(RawAST* r_attr);
47 bool get_is_optional() const { return is_optional; }
48 bool has_default() const { return defval != 0; }
49 Value *get_defval() const { return defval; }
50 virtual void dump(unsigned level) const;
51 };
52
53 /**
54 * Class to represent a map of TTCN-3 StructFieldDef (BNF
55 * 23). Create a CompFieldMap and use add_comp(CompField *) to add
56 * each StructFieldDef (a.k.a. CompRef) into it! Finally, pass
57 * CompFieldMap* to constructors of record/set/union types!
58 */
59 class CompFieldMap : public Node {
60 private:
61 /** Maps the name of the component to the actual component. */
62 map<string, CompField> m;
63 /** Contains pointers to the individual CompField s.
64 * The CompFieldMap owns the CompFields and will free them. */
65 vector<CompField> v;
66 /** Points to the owner type, which shall be a TTCN-3 record, set or
67 * union or an ASN.1 open type.
68 * The CompFieldMap does not own the type. */
69 Type *my_type;
70 /** Indicates whether the uniqueness of field identifiers has been
71 * verified. */
72 bool checked;
73
74 CompFieldMap(const CompFieldMap& p);
75 /** Assignment disabled */
76 CompFieldMap& operator=(const CompFieldMap& p);
77 public:
78 CompFieldMap() : Node(), m(), v(), my_type(0), checked(false) {}
79 virtual ~CompFieldMap();
80 virtual CompFieldMap *clone() const;
81 virtual void set_fullname(const string& p_fullname);
82 virtual void set_my_scope(Scope *p_scope);
83 void set_my_type(Type *p_my_type) { my_type = p_my_type; }
84 void add_comp(CompField *comp);
85 size_t get_nof_comps() const { return v.size(); }
86 CompField* get_comp_byIndex(size_t n) const { return v[n]; }
87 bool has_comp_withName(const Identifier& p_name);
88 CompField* get_comp_byName(const Identifier& p_name);
89 private:
90 const char *get_typetype_name() const;
91 /** Check the uniqueness of field identifiers.
92 * Builds the map \c m in the process. */
93 void chk_uniq();
94 public:
95 void chk();
96 virtual void dump(unsigned level) const;
97 };
98
99
100 } /* namespace Common */
101 #endif /* COMPFIELD_HH_ */
This page took 0.033401 seconds and 5 git commands to generate.