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