1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
|
/******************************************************************************
* Copyright (c) 2000-2021 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
*
* Contributors:
* Balasko, Jeno
* Delic, Adam
* Raduly, Csaba
* Szabo, Bence Janos
*
******************************************************************************/
#include "RootType.hh"
#include "TTCN3Module.hh"
RootType::RootType(XMLParser * a_parser, TTCN3Module * a_module, const ConstructType a_construct)
: parser(a_parser)
, module(a_module)
, name()
, type(a_module, a_parser)
, variant()
, variant_ref()
, comment()
, construct(a_construct)
, new_construct(a_construct)
, origin(from_unknown)
, visible(true)
, nameDepList()
, minOccurs(1)
, maxOccurs(1)
, min_mod(false)
, max_mod(false){
Mstring xsdPrefix = module->getxmlSchemaPrefixes().size() != 0 ?
(module->getxmlSchemaPrefixes().front() + ':') : empty_string;
switch (a_construct) {
case c_schema:
case c_annotation:
case c_include:
case c_import:
//redundant: origin = from_unknown;
break;
case c_unknown: // because when using fields in complextypes we set construct to c_unknown
case c_simpleType:
origin = from_simpleType;
type.upload(xsdPrefix + Mstring("anySimpleType"), false);
break;
case c_element:
origin = from_element;
type.upload(xsdPrefix + Mstring("anyType"), false);
addVariant(V_element);
break;
case c_attribute:
origin = from_attribute;
type.upload(xsdPrefix + Mstring("anySimpleType"), false);
addVariant(V_attribute);
break;
case c_complexType:
origin = from_complexType;
type.upload(Mstring("record"), false);
break;
case c_group:
origin = from_group;
type.upload(Mstring("record"), false);
addVariant(V_untagged);
break;
case c_attributeGroup:
origin = from_attributeGroup;
type.upload(Mstring("record"), false);
addVariant(V_attributeGroup);
visible = false;
break;
default:
break;
}
}
void RootType::addVariant(const VariantMode var, const Mstring& var_value, const bool into_variant_ref) {
Mstring variantstring;
switch (var) {
case V_abstract:
variantstring = "\"abstract\"";
break;
case V_anyAttributes:
variantstring = "\"anyAttributes" + var_value + "\"";
break;
case V_anyElement:
variantstring = "\"anyElement" + var_value + "\"";
break;
case V_attribute:
variantstring = "\"attribute\"";
break;
case V_attributeFormQualified:
variantstring = "\"attributeFormQualified\"";
break;
case V_attributeGroup:
variantstring = "\"attributeGroup\"";
break;
case V_block:
variantstring = "\"block\"";
break;
case V_controlNamespace:
variantstring = "\"controlNamespace" + var_value + "\"";
break;
case V_defaultForEmpty:
// The apostrophes are not needed because the var_value will be a constant
// reference.
variantstring = "\"defaultForEmpty as " + var_value + "\""; // chapter 7.1.5
break;
case V_element:
variantstring = "\"element\"";
break;
case V_elementFormQualified:
variantstring = "\"elementFormQualified\"";
break;
case V_embedValues:
variantstring = "\"embedValues\"";
break;
case V_formAs:
variantstring = "\"form as " + var_value + "\"";
break;
case V_list:
variantstring = "\"list\"";
break;
case V_nameAs:
variantstring = "\"name as \'" + var_value + "\'\"";
break;
case V_namespaceAs:
{
Mstring prefix;
Mstring uri;
for (List<NamespaceType>::iterator namesp = module->getDeclaredNamespaces().begin(); namesp; namesp = namesp->Next) {
if (namesp->Data.uri == var_value) {
prefix = namesp->Data.prefix;
uri = namesp->Data.uri;
break;
}
}
if (prefix.empty() || uri.empty()) {
break;
}
variantstring = "\"namespace as \'" + uri + "\' prefix \'" + prefix + "\'\"";
break;
}
case V_onlyValue:
variantstring = var_value;
break;
case V_onlyValueHidden:
hidden_variant.push_back(var_value);
break;
case V_untagged:
variantstring = "\"untagged\"";
break;
case V_useNil:
variantstring = "\"useNil\"";
break;
case V_useNumber:
variantstring = "\"useNumber\"";
break;
case V_useOrder:
variantstring = "\"useOrder\"";
break;
case V_useType:
variantstring = "\"useType\"";
break;
case V_useUnion:
variantstring = "\"useUnion\"";
break;
case V_whiteSpace:
variantstring = "\"whiteSpace " + var_value + "\"";
break;
case V_fractionDigits:
variantstring = "\"fractionDigits " + var_value + "\"";
break;
}
if (!variantstring.empty()) {
variant.push_back(variantstring);
if (into_variant_ref) {
variant_ref.push_back(variantstring);
}
}
}
void RootType::printVariant(FILE * file) {
if (!e_flag_used && !variant.empty()) {
fprintf(file, "\nwith {\n");
for (List<Mstring>::iterator var = variant.end(); var; var = var->Prev) {
fprintf(file, " variant %s;\n", var->Data.c_str());
}
for (List<Mstring>::iterator var = hidden_variant.end(); var; var = var->Prev) {
fprintf(file, " //variant %s;\n", var->Data.c_str());
}
fprintf(file, "}");
} else if (!e_flag_used && type.originalValueWoPrefix == Mstring("boolean")) {
fprintf(file, ";\n//with {\n");
for (List<Mstring>::iterator var = hidden_variant.end(); var; var = var->Prev) {
fprintf(file, " //variant %s;\n", var->Data.c_str());
}
fprintf(file, "//}");
}
}
void RootType::addComment(const Mstring& text) {
comment.push_back(Mstring("/* " + text + " */\n"));
}
void RootType::printComment(FILE * file, unsigned int level) {
if (!c_flag_used && !comment.empty()) {
for (List<Mstring>::iterator c = comment.begin(); c; c = c->Next) {
indent(file, level);
fprintf(file, "%s", c->Data.c_str());
}
}
}
void RootType::printMinOccursMaxOccurs(FILE * file, const bool inside_union,
const bool empty_allowed /* = true */) const {
unsigned long long tmp_minOccurs = minOccurs;
if (minOccurs == 0 && !empty_allowed) tmp_minOccurs = 1ULL;
if (maxOccurs == 1) {
if (minOccurs == 0) {
if (inside_union || name.list_extension) {
fputs("record length(", file);
if (empty_allowed) fputs("0 .. ", file);
// else: length(1..1) is shortened to length(1)
fputs("1) of ", file);
}
// else it's optional which is not printed from here
} else if (minOccurs == 1) {
// min==max==1; do nothing unless...
if (name.convertedValue == "embed_values") {
fputs("record length(1) of ", file);
}
}
} else if (maxOccurs == ULLONG_MAX) {
if (minOccurs == 0) {
fputs("record ", file);
if (!empty_allowed) fputs("length(1 .. infinity) ", file);
fputs("of ", file);
} else fprintf(file, "record length(%llu .. infinity) of ", tmp_minOccurs);
} else {
if (tmp_minOccurs == maxOccurs) {
fprintf(file, "record length(%llu) of ", tmp_minOccurs);
} else {
fprintf(file, "record length(%llu .. %llu) of ", tmp_minOccurs, maxOccurs);
}
}
}
bool RootType::hasVariant(const Mstring& var) const{
for(List<Mstring>::iterator vars = variant.begin(); vars; vars = vars->Next){
if(vars->Data.isFound(var)){
return true;
}
}
for(List<Mstring>::iterator vars = hidden_variant.begin(); vars; vars = vars->Next){
if(vars->Data.isFound(var)){
return true;
}
}
return false;
}
void TypeType::upload(const Mstring& input, bool prefixCheck) {
if (input.empty()) return;
convertedValue = input;
originalValueWoPrefix = input.getValueWithoutPrefix(':');
if (isBuiltInType(input)) {
refPrefix = input.getPrefix(':');
if (prefixCheck) {
checkBuintInTypeReference();
}
}
}
void TypeType::checkBuintInTypeReference() {
bool found = false;
for (List<Mstring>::iterator px = t_module->getxmlSchemaPrefixes().begin(); px; px = px->Next) {
if (refPrefix == px->Data) {
found = true;
break;
}
}
// Second chance. It may be a prefix from one of the xsd-s.
if (!found) {
for (List<NamespaceType>::iterator ns = t_module->getDeclaredNamespaces().begin(); ns; ns = ns->Next) {
if (refPrefix == ns->Data.prefix.c_str()) {
found = true;
break;
}
}
}
// Third chance. NoTargetNamespace module without a prefix.
if (t_module->getTargetNamespace() == "NoTargetNamespace" && refPrefix.empty()) {
found = true;
}
if (!found) {
printError(t_module->getSchemaname(), t_parser->getActualLineNumber(), Mstring("Cannot find the namespace of type: ") + originalValueWoPrefix);
t_parser->incrNumErrors();
}
}
|