Commit | Line | Data |
---|---|---|
970ed795 EL |
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 _Common_Identifier_HH | |
9 | #define _Common_Identifier_HH | |
10 | ||
11 | #include "string.hh" | |
12 | #include "map.hh" | |
13 | ||
14 | namespace Common { | |
15 | ||
16 | /** | |
17 | * \addtogroup AST | |
18 | * | |
19 | * @{ | |
20 | */ | |
21 | ||
22 | /** | |
23 | * This is a universal identifier class which can handle all | |
24 | * reserved keywords. It contains also the name mappings. It is | |
25 | * effective because of using reference counter. | |
26 | */ | |
27 | class Identifier { | |
28 | public: | |
29 | enum id_t { | |
30 | ID_NAME, /**< internal name == C++ (generated) name */ | |
31 | ID_ASN, /**< ASN.1 display name */ | |
32 | ID_TTCN /**< TTCN-3 display name */ | |
33 | }; | |
34 | struct id_data_t; | |
35 | /** Returns whether \a p_name is a reserved word in the language | |
36 | * identified by \a p_id_t */ | |
37 | static bool is_reserved_word(const string& p_name, id_t p_id_t); | |
38 | /** Converts ASN.1 name \a p_name to internal (C++) name */ | |
39 | static string asn_2_name(const string& p_name); | |
40 | /** Converts internal (C++) name \a p_name to ASN.1 name */ | |
41 | static string name_2_asn(const string& p_name); | |
42 | /** Converts TTCN-3 name \a p_from to internal (C++) name */ | |
43 | static string ttcn_2_name(const string& p_name); | |
44 | /** Converts internal (C++) name \a p_from to TTCN-3 name */ | |
45 | static string name_2_ttcn(const string& p_name); | |
46 | private: | |
47 | id_data_t *id_data; | |
48 | id_t origin; | |
49 | public: | |
50 | /** Creates a new identifier with origin \a p_id_t and name \a | |
51 | * p_name. If \a dontreg is true, then this new identifier will | |
52 | * not be registered in the mapping tables. */ | |
53 | Identifier(id_t p_id_t, const string& p_name, bool dontreg=false); | |
54 | Identifier(const Identifier& p); | |
55 | ~Identifier(); | |
56 | ||
57 | Identifier *clone() const { return new Identifier(*this); } | |
58 | Identifier& operator=(const Identifier& p); | |
59 | bool operator==(const Identifier& p) const; | |
60 | inline bool operator!=(const Identifier& p) const | |
61 | { return !(*this == p); } | |
62 | bool operator<(const Identifier& p) const; | |
63 | ||
64 | /** Gets the origin. */ | |
65 | id_t get_origin() const { return origin; } | |
66 | /** Gets the internal (and C++) name. */ | |
67 | const string& get_name() const; | |
68 | /** Gets the display name according to its origin. */ | |
69 | const string& get_dispname() const; | |
70 | /** Gets the ASN display name. */ | |
71 | const string& get_asnname() const; | |
72 | /** Gets the TTCN display name. */ | |
73 | const string& get_ttcnname() const; | |
74 | /** Returns false if this identifier does not have a valid name | |
75 | * for the requested purpose. */ | |
76 | bool get_has_valid(id_t p_id_t) const; | |
77 | /** Gets each valid/set name. */ | |
78 | string get_names() const; | |
79 | ||
80 | /** True if it is a valid ASN modulereference. */ | |
81 | bool isvalid_asn_modref() const; | |
82 | /** True if it is a valid ASN typereference. */ | |
83 | bool isvalid_asn_typeref() const; | |
84 | /** True if it is a valid ASN valuereference. */ | |
85 | bool isvalid_asn_valref() const; | |
86 | /** True if it is a valid ASN valuesetreference. */ | |
87 | bool isvalid_asn_valsetref() const; | |
88 | /** True if it is a valid ASN objectclassreference. */ | |
89 | bool isvalid_asn_objclassref() const; | |
90 | /** True if it is a valid ASN objectreference. */ | |
91 | bool isvalid_asn_objref() const; | |
92 | /** True if it is a valid ASN objectsetreference. */ | |
93 | bool isvalid_asn_objsetref() const; | |
94 | /** True if it is a valid ASN typefieldreference. */ | |
95 | bool isvalid_asn_typefieldref() const; | |
96 | /** True if it is a valid ASN valuefieldreference. */ | |
97 | bool isvalid_asn_valfieldref() const; | |
98 | /** True if it is a valid ASN valuesetfieldreference. */ | |
99 | bool isvalid_asn_valsetfieldref() const; | |
100 | /** True if it is a valid ASN objectfieldreference. */ | |
101 | bool isvalid_asn_objfieldref() const; | |
102 | /** True if it is a valid ASN objectsetfieldreference. */ | |
103 | bool isvalid_asn_objsetfieldref() const; | |
104 | /** True if it is a valid ASN "word". */ | |
105 | bool isvalid_asn_word() const; | |
106 | ||
107 | void dump(unsigned level) const; | |
108 | }; | |
109 | ||
110 | /// Identifier to represent the contained type of a record-of | |
111 | /// as a pseudo-component when checking attribute qualifiers. | |
112 | extern const Identifier underscore_zero; | |
113 | ||
114 | /** @} end of AST group */ | |
115 | ||
116 | } // namespace Common | |
117 | ||
118 | #endif // _Common_Identifier_HH |