Merge pull request #19 from nspaseski/master
[deliverable/titan.core.git] / compiler2 / XerAttributes.hh
CommitLineData
970ed795 1///////////////////////////////////////////////////////////////////////////////
3abe9331 2// Copyright (c) 2000-2015 Ericsson Telecom AB
970ed795
EL
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/*
9 * XerAttributes.h
10 *
11 * Created on: Oct 17, 2008
12 * Author: ecsardu
13 */
14
15#ifndef XERATTRIBUTES_H_
16#define XERATTRIBUTES_H_
17
18#include <stddef.h>
19#include <limits.h>
20#include "../common/memory.h"
21
22namespace Common {
23class Value;
24}
25
26struct NamespaceRestriction // union member, no constructor allowed
27{
28 size_t nElements_;
29 /** URIs for ANY-ATTRIBUTES and ANY-ELEMENT. NULL is used to represent
30 * ABSENT */
31 char ** uris_;
32 enum {
33 UNUSED,
34 NOTHING, ///< anyElement
35 FROM, ///< anyElement from ...
36 EXCEPT ///< anyElement except ...
37 } type_;
38};
39// #define ABSENT ((char*)5) just use NULL
40
41void FreeNamespaceRestriction(NamespaceRestriction& nsr);
42
43
44struct NamespaceSpecification
45{
46 /** How to transform the ASN/TTCN name to XML name */
47 enum NameMangling {
48 NO_MANGLING, ///< no change
49 CAPITALIZED, ///< change the first letter to uppercase
50 UNCAPITALIZED,///< change the first letter to lowercase
51 UPPERCASED, ///< change all letters to uppercase
52 LOWERCASED, ///< change all letters to lowercase
53 // The underlying type of the enum is an integral type that can cover
54 // all the enum values. Using a value which doesn't fit into signed int,
55 // we try to force the underlying type to be _unsigned_ int.
56 FORCE_UNSIGNED = UINT_MAX
57 };
58 enum { ALL = LOWERCASED+1 }; // should be one bigger than the last of NameMangling
59
60 /** The URI for the NAMESPACE encoding instruction, or TextToBeUsed for TEXT.
61 * May be a valid pointer or any of the NameMangling enum values,
62 * or NULL for "text".
63 * For NAMESPACE, NULL (NO_MANGLING) means that no NAMESPACE instruction
64 * is assigned directly; UNCAPITALIZED means that an explicit "cancel
65 * all namespaces" instruction was applied: "namespace '' prefix ''" */
66 union {
67 char * uri; // for NAMESPACE
68 char * new_text; // for TEXT
69 NameMangling keyword; // for TEXT
70 };
71 /** The prefix for the NAME encoding instruction or the Target for TEXT.
72 * May be XerAttributes::ALL for "text all as ...cased", or 0 for "text" */
73 union {
74 char * prefix; // for NAMESPACE
75 char * target; // for TEXT
76 };
77};
78
79inline void free_name_or_kw(char *s)
80{
81 if (s > (char*)NamespaceSpecification::ALL) {
82 Free(s);
83 }
84}
85
86/** XER attributes during compilation.
87 *
88 * @todo members are ordered alphabetically, this should be changed to
89 * be more space efficient (pointers, then integers, then booleans)
90 */
91class XerAttributes {
92private:
93 // Compiler-generated copy constructor and assignment NOT safe.
94 // Must disable or implement own.
95 XerAttributes(const XerAttributes&);
96 XerAttributes& operator=(const XerAttributes&);
97public:
98 //enum PI_Location { NOWHERE, BEFORE_TAG, BEFORE_VALUE, AFTER_TAG, AFTER_VALUE };
99 enum WhitespaceAction { PRESERVE, REPLACE, COLLAPSE };
100 enum Form { // a bit mask
101 UNSET = 0,
102 // Global defaults for the module:
103 ELEMENT_DEFAULT_QUALIFIED = 1,
104 ATTRIBUTE_DEFAULT_QUALIFIED = 2,
105 // Locally set values (applied directly to the type or field)
106 UNQUALIFIED = 4, //< "form as unqualified"
107 QUALIFIED = 8, //< "form as qualified"
108 LOCALLY_SET = (QUALIFIED | UNQUALIFIED)
109 };
110
111 /** Name change action.
112 *
113 * When importing XSD into ASN.1 or TTCN-3, some names might need to be
114 * changed to protect the guilty (make them valid ASN.1/TTCN.3).
115 * The NAME encoding instruction describes how to get back to the XML
116 * tag name. The original name may be retrieved with one of the "canned" actions
117 * (change the case of the first or all letters) or by storing the original
118 * name in full (usually if characters were appended to remove name clashes).
119 *
120 * This union and the related code makes the assumption that not only
121 * 0, but 1,2,3,4 will not appear as valid pointers. Switch statements
122 * operating on the kw_ member must have cases for the enumeration values,
123 * the default case means that the nn_ member is in fact active
124 * and contains a pointer to the string. Remember to free/alloc new space
125 * in this situation. */
126 typedef union {
127 NamespaceSpecification::NameMangling kw_;
128 char* nn_;
129 } NameChange;
130
131 XerAttributes();
132 ~XerAttributes();
133
134 /// If the NameChange structure contains a string, free it.
135 static void FreeNameChange(NameChange& n);
136 /// If the NamespaceSpecification contains a string, free it.
137 static void FreeNamespace(NamespaceSpecification& ns);
138public:
51fa56b9 139 bool abstract_;
970ed795
EL
140 bool attribute_;
141 NamespaceRestriction anyAttributes_;
142 NamespaceRestriction anyElement_;
143 /// Base64 encoding for string-like types (XSD:base64Binary)
144 bool base64_;
51fa56b9 145 bool block_;
970ed795
EL
146 /// No scientific notation for float
147 bool decimal_;
148 /// String parsed out from the encoding attribute
149 char * defaultForEmpty_;
150 /// Value object constructed by Type::chk_xer() from defaultForEmpty_
151 Common::Value *defaultValue_;
152 /// Global element in XSD
153 bool element_;
154 /// Give values to text nodes. Applied to record containing a record of string
155 bool embedValues_;
156 /// Qualified or unqualified form for local elements and attributes
157 unsigned short form_;
158 /// XSD:hexBinary
159 bool hex_;
160 /// space-separated values for record-of/set-of
161 bool list_;
162 /// How to get back the XML name
163 NameChange name_;
164 NamespaceSpecification namespace_;
165 //struct { PI_Location position_; /*const*/ char * value_; } pi_or_comment_;
166 /// Number of TEXT instructions stored.
167 size_t num_text_;
168 /// Pointer to an array for the TEXT encoding instruction
169 NamespaceSpecification *text_; // re-use of struct
170 /// No XML tag, just the value
171 bool untagged_;
172 bool useNil_;
173 bool useNumber_;
174 bool useOrder_;
175 bool useQName_;
176 bool useType_;
177 bool useUnion_;
178 WhitespaceAction whitespace_;
179
180 void print(const char *type_name) const;
181
182 /** Override/merge XER attributes from @p other.
183 *
184 * Boolean attributes (attribute_, base64_, decimal_, embedValues_,
185 * list_, untagged_, useNil_, useNumber_, useOrder_, useQName_, useType_,
186 * useUnion_) are merged.
187 * In case of "Value" attributes (anyAttributes_, anyElement_, name_,
188 * namespace_, text_, whitespace_) the value in @p other overwrites
189 * the value in @p this.
190 *
191 * @param other set of XER attributes
192 * @return the merged object (@p *this)
193 * @pre @a other must not be @t empty() */
194 XerAttributes& operator |= (const XerAttributes& other);
195
196 /** Return true if no attribute is set, false otherwise */
197 bool empty() const;
198};
199
200inline bool has_ae(const XerAttributes *xa) {
201 return xa->anyElement_.type_ != NamespaceRestriction::UNUSED;
202}
203
204inline bool has_aa(const XerAttributes *xa) {
205 return xa->anyAttributes_.type_ != NamespaceRestriction::UNUSED;
206}
207
208
209#endif /* XERATTRIBUTES_H_ */
This page took 0.031423 seconds and 5 git commands to generate.