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 _Asn_Tag_HH | |
9 | #define _Asn_Tag_HH | |
10 | ||
11 | #include "../Int.hh" | |
12 | #include "AST_asn1.hh" | |
13 | #include "../Code.hh" | |
14 | ||
15 | namespace Asn { | |
16 | ||
17 | using namespace Common; | |
18 | ||
19 | /** | |
20 | * Class to represent ASN tag. | |
21 | */ | |
22 | class Tag : public Node, public Location { | |
23 | public: | |
24 | enum tagplicit_t {TAG_DEFPLICIT, TAG_EXPLICIT, TAG_IMPLICIT}; | |
25 | enum tagclass_t { | |
26 | TAG_ERROR, TAG_NONE, | |
27 | TAG_ALL, | |
28 | TAG_UNIVERSAL, | |
29 | TAG_APPLICATION, | |
30 | TAG_CONTEXT, | |
31 | TAG_PRIVATE | |
32 | }; | |
33 | private: | |
34 | tagplicit_t plicit; | |
35 | tagclass_t tagclass; | |
36 | Value *tagvalue; | |
37 | Int tagval; | |
38 | bool is_auto; | |
39 | ||
40 | public: | |
41 | Tag(tagplicit_t p_plicit, tagclass_t p_tagclass, Value *p_tagvalue); | |
42 | Tag(tagplicit_t p_plicit, tagclass_t p_tagclass, Int p_tagval); | |
43 | Tag(const Tag& p); | |
44 | virtual ~Tag(); | |
45 | virtual Tag* clone() const | |
46 | {return new Tag(*this);} | |
47 | Tag& operator=(const Tag& p); | |
48 | bool operator==(const Tag& p) const; | |
49 | bool operator<(const Tag& p) const; | |
50 | tagplicit_t get_plicit() const {return plicit;} | |
51 | void set_plicit(tagplicit_t p_plicit) {plicit=p_plicit;} | |
52 | tagclass_t get_tagclass() const {return tagclass;} | |
53 | const char *get_tagclass_str() const; | |
54 | void set_tagclass(tagclass_t p_tagclass) {tagclass=p_tagclass;} | |
55 | bool is_automatic() const { return is_auto; } | |
56 | void set_automatic() {is_auto = true;} | |
57 | Int get_tagvalue(); | |
58 | void set_tagvalue(const Int& p_tagval); | |
59 | void set_my_scope(Scope *p_scope); | |
60 | void chk(); | |
61 | virtual void dump(unsigned level) const; | |
62 | }; | |
63 | ||
64 | /** | |
65 | * Class to represent a series of tags applied to a type. Index 0 is | |
66 | * the innermost tag. | |
67 | */ | |
68 | class Tags : public Node { | |
69 | private: | |
70 | Scope *my_scope; | |
71 | /** tags */ | |
72 | vector<Tag> tags; | |
73 | ||
74 | Tags(const Tags&); | |
75 | public: | |
76 | Tags(); | |
77 | virtual ~Tags(); | |
78 | virtual Tags* clone() const | |
79 | {return new Tags(*this);} | |
80 | virtual void set_fullname(const string& p_fullname); | |
81 | void set_my_scope(Scope *p_scope); | |
82 | void add_tag(Tag *p_tag); | |
83 | size_t get_nof_tags() const | |
84 | {return tags.size();} | |
85 | Tag* get_tag_byIndex(const size_t p_i) | |
86 | {return tags[p_i];} | |
87 | void chk(); | |
88 | void set_plicit(Type *p_type); | |
89 | void cut_auto_tags(); | |
90 | virtual void dump(unsigned level) const; | |
91 | }; | |
92 | ||
93 | /** | |
94 | * Class to represent a collection of tags. This can be used to | |
95 | * check tag clashes, "monoton increment"-requirements of tags etc. | |
96 | */ | |
97 | class TagCollection : public Node, public Location { | |
98 | private: | |
99 | map<Tag, void> tag_map; | |
100 | const Tag *has_all; | |
101 | bool is_extensible; | |
102 | ||
103 | TagCollection(const TagCollection& p); | |
104 | public: | |
105 | TagCollection(); | |
106 | virtual ~TagCollection(); | |
107 | virtual TagCollection* clone() const | |
108 | {return new TagCollection(*this);} | |
109 | /** Adds the tag to the collection. p_tag is copied; the | |
110 | * tagcollection does not become the owner of p_tag. */ | |
111 | void addTag(const Tag *p_tag); | |
112 | bool hasTag(const Tag *p_tag) const; | |
113 | /** Adds (copies) every tag of p_tags to this. */ | |
114 | void addTags(const TagCollection *p_tags); | |
115 | bool hasTags(const TagCollection *p_tags) const; | |
116 | /** Return true if all the tags of p_tags are greater than all the | |
117 | * tags of this. */ | |
118 | bool greaterTags(const TagCollection *p_tags) const; | |
119 | /** Returns the smallest or largest tag of the collection. | |
120 | * Applicable only of the collection is not empty. */ | |
121 | const Tag *getSmallestTag() const; | |
122 | const Tag *getGreatestTag() const; | |
123 | bool isExtensible() const { return is_extensible; } | |
124 | void setExtensible(); | |
125 | bool isEmpty() const; | |
126 | /** Makes it empty. */ | |
127 | void clear(); | |
128 | }; | |
129 | ||
130 | } // namespace Asn | |
131 | ||
132 | #endif // _Asn_Tag_HH |