Newer
Older
/******************************************************************************
* 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:
* Baji, Laszlo
* Balasko, Jeno
* Delic, Adam
* Feher, Csaba
* Forstner, Matyas
* Kovacs, Ferenc
* Raduly, Csaba
* Szabados, Kristof
* Szabo, Janos Zoltan – initial implementation
*
******************************************************************************/
#include "../common/dbgnew.hh"
#include "Identifier.hh"
#include <ctype.h>
#include "Setting.hh"
#include "CompilerError.hh"
Botond Baranyi
committed
#include "main.hh"
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
namespace Common {
// =================================
// ===== Identifier::id_data_t
// =================================
struct Identifier::id_data_t {
size_t ref_count;
string name, asnname, ttcnname;
/** ASN kind of the identifier. */
enum asn_kind_t {
ASN_UNDEF, /**< undefined */
ASN_LOWER, /**< LOWERIDENTIFIER [a-z](-?[A-Za-z0-9]+)* */
ASN_UPPER, /**< UPPERIDENTIFIER [A-Z](-?[A-Za-z0-9]+)* */
ASN_ALLUPPER, /**< ALLUPPERIDENTIFIER [A-Z](-?[A-Z0-9]+)* */
ASN_WORD, /**< WORD [A-Z](-?[A-Z]+)* */
ASN_ampUPPER, /**< ampUPPERIDENTIFIER \\\&{UPPERIDENTIFIER} */
ASN_ampLOWER /**< ampLOWERIDENTIFIER \\\&{LOWERIDENTIFIER} */
} asn_kind;
static void asn_2_name(string& p_to, const string& p_from);
static void name_2_asn(string& p_to, const string& p_from);
static void ttcn_2_name(string& p_to, const string& p_from);
static void name_2_ttcn(string& p_to, const string& p_from);
id_data_t(const string& p_name)
: ref_count(1), name(p_name), asnname(), ttcnname(), asn_kind(ASN_UNDEF){}
static void delete_this(id_data_t *p_id_data_t);
/** Gets the internal (and C++) name. */
const string& get_name() const {return name;}
/** Gets the ASN display name. */
const string& get_asnname();
/** Gets the TTCN display name. */
const string& get_ttcnname();
bool get_has_valid(id_t p_id_t);
string get_names() const;
/** True if it is a valid ASN modulereference. */
bool isvalid_asn_modref();
/** True if it is a valid ASN typereference. */
bool isvalid_asn_typeref();
/** True if it is a valid ASN valuereference. */
bool isvalid_asn_valref();
/** True if it is a valid ASN valuesetreference. */
bool isvalid_asn_valsetref();
/** True if it is a valid ASN objectclassreference. */
bool isvalid_asn_objclassref();
/** True if it is a valid ASN objectreference. */
bool isvalid_asn_objref();
/** True if it is a valid ASN objectsetreference. */
bool isvalid_asn_objsetref();
/** True if it is a valid ASN typefieldreference. */
bool isvalid_asn_typefieldref();
/** True if it is a valid ASN valuefieldreference. */
bool isvalid_asn_valfieldref();
/** True if it is a valid ASN valuesetfieldreference. */
bool isvalid_asn_valsetfieldref();
/** True if it is a valid ASN objectfieldreference. */
bool isvalid_asn_objfieldref();
/** True if it is a valid ASN objectsetfieldreference. */
bool isvalid_asn_objsetfieldref();
/** True if it is a valid ASN "word". */
bool isvalid_asn_word();
private:
~id_data_t() {}
void decide_asn_kind();
};
// =================================
// ===== internal_data_t
// =================================
class internal_data_t {
private:
static internal_data_t *instance;
static const char* const keywords[][3];
Botond Baranyi
committed
static const char* const realtime_keywords[][3];
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
size_t identifier_counter;
public:
const string string_invalid;
/** Container for identifiers, indexed by ID_NAME. */
map<string, Identifier::id_data_t> id_map_name;
/** Container for identifiers, indexed by ID_ASN. */
map<string, Identifier::id_data_t> id_map_asn;
/** Container for identifiers, indexed by ID_TTCN. */
map<string, Identifier::id_data_t> id_map_ttcn;
private:
internal_data_t();
internal_data_t(const internal_data_t&);
~internal_data_t();
void add_keyword(const char* const keyword[3]);
void add_keywords();
public:
static internal_data_t *Instance();
/** Increases the instance counter. Initializes the keywords if
* this is the first instance. Must be called in every Identifier
* constructor. */
void increase_counter();
/** Decreases the instance counter. Finalizes the keywords if this
* is the last instance. Must be called in Identifier
* destructor. */
void decrease_counter();
};
// ======================================================================
// ======================================================================
// =================================
// ===== Identifier::id_data_t
// =================================
void Identifier::id_data_t::asn_2_name(string& p_to, const string& p_from)
{
p_to = p_from;
/* "@aaa" -> "_root_aaa" */
if (p_to.size() > 0 && p_to[0] == '@') p_to.replace(0, 1, "_root_");
/* "aa.<xxxx>.bb" -> "aa.bb" */
size_t pos = 0;
while ((pos = p_to.find(".<", pos)) < p_to.size()) {
size_t pos2 = p_to.find(">.", pos);
if (pos2 < p_to.size()) p_to.replace(pos, pos2 + 1 - pos, "");
else break;
}
/* "-" -> "__" */
pos = 0;
while ((pos = p_to.find('-', pos)) < p_to.size()) {
p_to.replace(pos, 1, "__");
pos += 2;
}
/* "." -> "_" */
pos = 0;
while ((pos = p_to.find('.', pos)) < p_to.size()) {
p_to[pos] = '_';
pos++;
}
/* "&" -> "" */
pos = 0;
while ((pos = p_to.find('&', pos)) < p_to.size())
p_to.replace(pos, 1, "");
}
void Identifier::id_data_t::name_2_asn(string& p_to, const string& p_from)
{
p_to = p_from;
/* remove leading '_'s */
size_t pos = 0;
while (pos < p_to.size() && p_to[pos] == '_') pos++;
if (pos > 0) p_to.replace(0, pos, "");
/* remove trailing '_'s */
pos = p_to.size();
while (pos > 0 && p_to[pos - 1] == '_') pos--;
if (pos < p_to.size()) p_to.resize(pos);
/* "__" -> "-" */
pos = 0;
while ((pos = p_to.find("__", pos)) < p_to.size()) {
p_to.replace(pos, 2, "-");
pos++;
}
/* "_" -> "-" */
pos = 0;
while ((pos = p_to.find('_', pos)) < p_to.size()) {
p_to[pos] = '-';
pos++;
}
}
void Identifier::id_data_t::ttcn_2_name(string& p_to, const string& p_from)
{
p_to = p_from;
/* "_" -> "__" */
size_t pos = 0;
while ((pos = p_to.find('_', pos)) < p_to.size()) {
p_to.replace(pos, 1, "__");
pos += 2;
}
}
void Identifier::id_data_t::name_2_ttcn(string& p_to, const string& p_from)
{
p_to = p_from;
/* remove leading '_'s */
size_t pos = 0;
while (pos < p_to.size() && p_to[pos] == '_') pos++;
if (pos > 0) p_to.replace(0, pos, "");
/* remove trailing '_'s */
pos = p_to.size();
while (pos > 0 && p_to[pos - 1] == '_') pos--;
if (pos < p_to.size()) p_to.resize(pos);
/* "__" -> "_" */
pos = 0;
while ((pos = p_to.find("__", pos)) < p_to.size()) {
p_to.replace(pos, 1, "");
pos++;
}
}
const string& Identifier::id_data_t::get_asnname()
{
if (asnname.empty()) name_2_asn(asnname, name);
return asnname;
}
const string& Identifier::id_data_t::get_ttcnname()
{
if (ttcnname.empty()) name_2_ttcn(ttcnname, name);
return ttcnname;
}
bool Identifier::id_data_t::get_has_valid(id_t p_id_t)
{
const string& inval=internal_data_t::Instance()->string_invalid;
switch(p_id_t) {
case ID_NAME:
return get_name()!=inval;
case ID_ASN:
return get_asnname()!=inval;
case ID_TTCN:
return get_ttcnname()!=inval;
default:
FATAL_ERROR("Identifier::id_data_t::get_has_valid()");
return false;
}
}
void Identifier::id_data_t::delete_this(id_data_t *p_id_data_t)
{
p_id_data_t->ref_count--;
if(p_id_data_t->ref_count==0)
delete p_id_data_t;
}
string Identifier::id_data_t::get_names() const
{
const string& inval=internal_data_t::Instance()->string_invalid;
string s="(C++: `"+name+"'";
if(!asnname.empty() && asnname!=inval)
s+=", ASN: `"+asnname+"'";
if(!ttcnname.empty() && ttcnname!=inval)
s+=", TTCN: `"+ttcnname+"'";
s+=")";
return s;
}
void Identifier::id_data_t::decide_asn_kind()
{
if(asn_kind!=ASN_UNDEF) return;
get_asnname();
if(asnname==internal_data_t::Instance()->string_invalid) return;
if(asnname[0]=='&') {
if(asnname.size()>=2) {
if(isupper(asnname[1]))
asn_kind=ASN_ampUPPER;
else if(islower(asnname[1]))
asn_kind=ASN_ampLOWER;
}
}
else if(islower(asnname[0])) {
asn_kind=ASN_LOWER;
}
else if(isupper(asnname[0])) {
asn_kind=ASN_UPPER;
if(asnname.find_if(0, asnname.size(), islower)==asnname.size()) {
asn_kind=ASN_ALLUPPER;
if(asnname.find_if(0, asnname.size(), isdigit)==asnname.size()) {
asn_kind=ASN_WORD;
}
}
}
}
bool Identifier::id_data_t::isvalid_asn_modref()
{
return isvalid_asn_typeref();
}
bool Identifier::id_data_t::isvalid_asn_typeref()
{
decide_asn_kind();
return (asn_kind==ASN_UPPER
|| asn_kind==ASN_ALLUPPER
|| asn_kind==ASN_WORD);
}
bool Identifier::id_data_t::isvalid_asn_valref()
{
decide_asn_kind();
return (asn_kind==ASN_LOWER);
}
bool Identifier::id_data_t::isvalid_asn_valsetref()
{
return isvalid_asn_typeref();
}
bool Identifier::id_data_t::isvalid_asn_objclassref()
{
decide_asn_kind();
return (asn_kind==ASN_ALLUPPER
|| asn_kind==ASN_WORD);
}
bool Identifier::id_data_t::isvalid_asn_objref()
{
decide_asn_kind();
return (asn_kind==ASN_LOWER);
}
bool Identifier::id_data_t::isvalid_asn_objsetref()
{
return isvalid_asn_typeref();
}
bool Identifier::id_data_t::isvalid_asn_typefieldref()
{
decide_asn_kind();
return (asn_kind==ASN_ampUPPER);
}
bool Identifier::id_data_t::isvalid_asn_valfieldref()
{
decide_asn_kind();
return (asn_kind==ASN_ampLOWER);
}
bool Identifier::id_data_t::isvalid_asn_valsetfieldref()
{
decide_asn_kind();
return (asn_kind==ASN_ampUPPER);
}
bool Identifier::id_data_t::isvalid_asn_objfieldref()
{
decide_asn_kind();
return (asn_kind==ASN_ampLOWER);
}
bool Identifier::id_data_t::isvalid_asn_objsetfieldref()
{
decide_asn_kind();
return (asn_kind==ASN_ampUPPER);
}
bool Identifier::id_data_t::isvalid_asn_word()
{
decide_asn_kind();
return (asn_kind==ASN_WORD);
}
// =================================
// ===== internal_data_t
// =================================
internal_data_t *internal_data_t::instance=0;
/* format: c++ - asn - ttcn */
const char* const internal_data_t::keywords[][3] = {
/* C++ keywords - never can be used */
{"and", 0, 0},
{"and_eq", 0, 0},
{"asm", 0, 0},
{"auto", 0, 0},
{"bitand", 0, 0},
{"bitor", 0, 0},
{"bool", 0, 0},
{"break", 0, 0},
{"case", 0, 0},
{"catch", 0, 0},
{"char", 0, 0},
{"class", 0, 0},
{"compl", 0, 0},
{"const", 0, 0},
{"const_cast", 0, 0},
{"continue", 0, 0},
{"default", 0, 0},
{"delete", 0, 0},
{"do", 0, 0},
{"double", 0, 0},
{"dynamic_cast", 0, 0},
{"else", 0, 0},
{"enum", 0, 0},
{"explicit", 0, 0},
{"export", 0, 0},
{"extern", 0, 0},
{"false", 0, 0},
{"float", 0, 0},
{"for", 0, 0},
{"friend", 0, 0},
{"goto", 0, 0},
{"if", 0, 0},
{"inline", 0, 0},
{"int", 0, 0},
{"long", 0, 0},
{"mutable", 0, 0},
{"namespace", 0, 0},
{"new", 0, 0},
{"not", 0, 0},
{"not_eq", 0, 0},
{"operator", 0, 0},
{"or", 0, 0},
{"or_eq", 0, 0},
{"private", 0, 0},
{"protected", 0, 0},
{"public", 0, 0},
{"register", 0, 0},
{"reinterpret_cast", 0, 0},
{"return", 0, 0},
{"short", 0, 0},
{"signed", 0, 0},
{"sizeof", 0, 0},
{"static", 0, 0},
{"static_cast", 0, 0},
{"struct", 0, 0},
{"switch", 0, 0},
{"template", 0, 0},
{"this", 0, 0},
{"throw", 0, 0},
{"true", 0, 0},
{"try", 0, 0},
{"typedef", 0, 0},
{"typeid", 0, 0},
{"typename", 0, 0},
{"union", 0, 0},
{"unsigned", 0, 0},
{"using", 0, 0},
{"virtual", 0, 0},
{"void", 0, 0},
{"volatile", 0, 0},
{"wchar_t", 0, 0},
{"while", 0, 0},
{"xor", 0, 0},
{"xor_eq", 0, 0},
/* C++ keywords postfixed, avoiding conflicts from valid ASN/TTCN names */
{"asm_", "asm", "asm"},
{"auto_", "auto", "auto"},
{"bitand_", "bitand", "bitand"},
{"bitor_", "bitor", "bitor"},
{"bool_", "bool", "bool"},
{"class_", "class", "class"},
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
{"compl_", "compl", "compl"},
{"delete_", "delete", "delete"},
{"double_", "double", "double"},
{"enum_", "enum", "enum"},
{"explicit_", "explicit", "explicit"},
{"export_", "export", "export"},
{"extern_", "extern", "extern"},
{"friend__", "friend", "friend_"},
{"inline_", "inline", "inline"},
{"int_", "int", "int"},
{"long_", "long", "long"},
{"mutable_", "mutable", "mutable"},
{"namespace_", "namespace", "namespace"},
{"new_", "new", "new"},
{"operator_", "operator", "operator"},
{"private__", "private", "private_"},
{"protected_", "protected", "protected"},
{"public__", "public", "public_"},
{"register_", "register", "register"},
{"short_", "short", "short"},
{"signed_", "signed", "signed"},
{"static_", "static", "static"},
{"struct_", "struct", "struct"},
{"switch_", "switch", "switch"},
{"this_", "this", "this"},
{"throw_", "throw", "throw"},
{"try_", "try", "try"},
{"typedef_", "typedef", "typedef"},
{"typeid_", "typeid", "typeid"},
{"typename_", "typename", "typename"},
{"unsigned_", "unsigned", "unsigned"},
{"using_", "using", "using"},
{"virtual_", "virtual", "virtual"},
{"void_", "void", "void"},
{"volatile_", "volatile", "volatile"},
/* C++ keywords postfixed - keywords in TTCN */
{"and__", "and", "and_"},
{"break__", "break", "break_"},
{"case__", "case", "case_"},
{"catch__", "catch", "catch_"},
{"char__", "char", "char_"},
{"const__", "const", "const_"},
{"continue__", "continue", "continue_"},
{"default__", "default", "default_"},
{"do__", "do", "do_"},
{"else__", "else", "else_"},
{"false__", "false", "false_"},
{"float__", "float", "float_"},
{"for__", "for", "for_"},
{"goto__", "goto", "goto_"},
{"if__", "if", "if_"},
{"not__", "not", "not_"},
{"or__", "or", "or_"},
{"return__", "return", "return_"},
{"sizeof__", "sizeof", "sizeof_"},
{"template__", "template", "template_"},
{"true__", "true", "true_"},
{"union__", "union", "union_"},
{"while__", "while", "while_"},
{"xor__", "xor", "xor_"},
/* reserved names of base library */
{"CHAR", 0, 0},
{"ERROR", 0, 0},
{"FAIL", 0, 0},
{"INCONC", 0, 0},
{"FALSE", 0, 0},
{"NONE", 0, 0},
{"OPTIONAL", 0, 0},
{"PASS", 0, 0},
{"PORT", 0, 0},
{"TIMER", 0, 0},
{"TRUE", 0, 0},
{"bit2hex", 0, 0},
{"bit2int", 0, 0},
{"bit2oct", 0, 0},
{"bit2str", 0, 0},
{"boolean", 0, 0},
{"char2int", 0, 0},
{"char2oct", 0, 0},
{"component", 0, 0},
{"decomp", 0, 0},
{"decvalue_unichar", 0, 0},
{"encvalue_unichar", 0, 0},
{"float2int", 0, 0},
{"float2str", 0, 0},
{"hex2bit", 0, 0},
{"hex2int", 0, 0},
{"hex2oct", 0, 0},
{"hex2str", 0, 0},
{"int2bit", 0, 0},
{"int2char", 0, 0},
{"int2float", 0, 0},
{"int2hex", 0, 0},
{"int2oct", 0, 0},
{"int2str", 0, 0},
{"int2unichar", 0, 0},
{"ischosen", 0, 0},
{"ispresent", 0, 0},
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
{"isvalue", 0, 0},
{"lengthof", 0, 0},
{"log", 0, 0},
{"log2str", 0, 0},
{"main", 0, 0},
{"match", 0, 0},
{"mod", 0, 0},
{"oct2bit", 0, 0},
{"oct2char", 0, 0},
{"oct2hex", 0, 0},
{"oct2int", 0, 0},
{"oct2str", 0, 0},
{"regexp", 0, 0},
{"replace", 0, 0},
{"rem", 0, 0},
{"rnd", 0, 0},
{"self", 0, 0},
{"stderr", 0, 0}, // temporary hack
{"stdin", 0, 0}, // temporary hack
{"stdout", 0, 0}, // temporary hack
{"str2bit", 0, 0},
{"str2float", 0, 0},
{"str2hex", 0, 0},
{"str2int", 0, 0},
{"str2oct", 0, 0},
{"substr", 0, 0},
{"unichar2int", 0, 0},
{"unichar2char", 0, 0},
{"valueof", 0, 0},
{"verdicttype", 0, 0},
{"unichar2oct", 0, 0},
{"oct2unichar", 0, 0},
{"get_stringencoding", 0, 0},
{"remove_bom", 0, 0},
{"encode_base64", 0, 0},
{"decode_base64", 0, 0},
/* reserved names of base library - keywords in TTCN - valid ASN.1 */
{"bit2hex__", "bit2hex", "bit2hex_"},
{"bit2int__", "bit2int", "bit2int_"},
{"bit2oct__", "bit2oct", "bit2oct_"},
{"bit2str__", "bit2str", "bit2str_"},
{"boolean__", "boolean", "boolean_"},
{"char2int__", "char2int", "char2int_"},
{"char2oct__", "char2oct", "char2oct_"},
{"component__", "component", "component_"},
{"decmatch__", "decmatch", "decmatch_"},
{"decvalue_unichar__", "decvalue_unichar", "decvalue_unichar_"},
{"encvalue_unichar__", "encvalue_unichar", "encvalue_unichar_"},
{"float2int__", "float2int", "float2int_"},
{"float2str__", "float2str", "float2str_"},
{"hex2bit__", "hex2bit", "hex2bit_"},
{"hex2int__", "hex2int", "hex2int_"},
{"hex2oct__", "hex2oct", "hex2oct_"},
{"hex2str__", "hex2str", "hex2str_"},
{"int2bit__", "int2bit", "int2bit_"},
{"int2char__", "int2char", "int2char_"},
{"int2float__", "int2float", "int2float_"},
{"int2hex__", "int2hex", "int2hex_"},
{"int2oct__", "int2oct", "int2oct_"},
{"int2str__", "int2str", "int2str_"},
{"int2unichar__", "int2unichar", "int2unichar_"},
{"ischosen__", "ischosen", "ischosen_"},
{"ispresent__", "ispresent", "ispresent_"},
{"istemplatekind__", "istemplatekind", "istemplatekind_"},
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
{"isvalue__", "isvalue", "isvalue_"},
{"lengthof__", "lengthof", "lengthof_"},
{"log__", "log", "log_"},
{"log2str__", "log2str", "log2str_"},
{"match__", "match", "match_"},
{"mod__", "mod", "mod_"},
{"oct2bit__", "oct2bit", "oct2bit_"},
{"oct2char__", "oct2char", "oct2char_"},
{"oct2hex__", "oct2hex", "oct2hex_"},
{"oct2int__", "oct2int", "oct2int_"},
{"oct2str__", "oct2str", "oct2str_"},
{"regexp__", "regexp", "regexp_"},
{"replace__", "replace", "replace_"},
{"rem__", "rem", "rem_"},
{"rnd__", "rnd", "rnd_"},
{"self__", "self", "self_"},
{"str2bit__", "str2bit", "str2bit_"},
{"str2float__", "str2float", "str2float_"},
{"str2hex__", "str2hex", "str2hex_"},
{"str2int__", "str2int", "str2int_"},
{"str2oct__", "str2oct", "str2oct_"},
{"substr__", "substr", "substr_"},
{"unichar2int__", "unichar2int", "unichar2int_"},
{"unichar2char__", "unichar2char", "unichar2char_"},
{"valueof__", "valueof", "valueof_"},
{"verdicttype__", "verdicttype", "verdicttype_"},
{"ttcn2string__", "ttcn2string", "ttcn2string_"},
{"string2ttcn__", "string2ttcn", "string2ttcn_"},
{"unichar2oct__", "unichar2oct", "unichar2oct_"},
{"oct2unichar__", "oct2unichar", "oct2unichar_"},
{"remove__bom__", "remove_bom", "remove_bom_"},
{"encode__base64__", "encode_base64", "encode_base64_"},
{"decode__base64__", "decode_base64", "decode_base64_"},
{"json2cbor__", "json2cbor", "json2cbor_"},
{"cbor2json__", "cbor2json", "cbor2json_"},
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
{"get__stringencoding__", "get_stringencoding", "get_stringencoding_"},
/* reserved names of base library - keywords in ASN.1 */
{"FALSE_", 0, "FALSE"},
{"OPTIONAL_", 0, "OPTIONAL"},
{"TRUE_", 0, "TRUE"},
/* reserved names of base library - not keywords */
{"CHAR_", "CHAR", "CHAR"},
{"ERROR_", "ERROR", "ERROR"},
{"FAIL_", "FAIL", "FAIL"},
{"INCONC_", "INCONC", "INCONC"},
{"NONE_", "NONE", "NONE"},
{"PASS_", "PASS", "PASS"},
{"PORT_", "PORT", "PORT"},
{"TIMER_", "TIMER", "TIMER"},
{"main_", "main", "main"},
{"stderr_", "stderr", "stderr"}, // temporary hack
{"stdin_", "stdin", "stdin"}, // temporary hack
{"stdout_", "stdout", "stdout"}, // temporary hack
{"TTCN3_", "TTCN3", "TTCN3"},
/* built-in types. this is the ASN/TTCN -> C++ name mapping */
{"ADDRESS", 0, "address"},
{"ASN_NULL", "NULL", 0},
{"BITSTRING", "BIT STRING", "bitstring"},
{"BOOLEAN", "BOOLEAN", "boolean"},
{"BMPString", "BMPString", 0},
{"CHARSTRING", 0, "charstring"},
{"CHARACTER_STRING", "CHARACTER STRING", 0},
{"COMPONENT", 0, "component"},
{"DEFAULT", 0, "default"},
{"EMBEDDED_PDV", "EMBEDDED PDV", 0},
{"EXTERNAL", "EXTERNAL", 0},
{"FLOAT", "REAL", "float"},
{"GraphicString", "GraphicString", 0},
{"HEXSTRING", 0, "hexstring"},
{"IA5String", "IA5String", 0},
{"INTEGER", "INTEGER", "integer"},
{"ISO646String", "ISO646String", 0},
{"NumericString", "NumericString", 0},
{"OBJID", "OBJECT IDENTIFIER", "objid"},
{"OCTETSTRING", "OCTET STRING", "octetstring"},
{"ObjectDescriptor", "ObjectDescriptor", 0},
{"PrintableString", "PrintableString", 0},
{"T61String", "T61String", 0},
{"TeletexString", "TeletexString", 0},
{"UTF8String", "UTF8String", 0},
{"UniversalString", "UniversalString", 0},
{"UNIVERSAL_CHARSTRING", 0, "universal charstring"},
{"VERDICTTYPE", 0, "verdicttype"},
{"VideotexString", "VideotexString", 0},
{"VisibleString", "VisibleString", 0},
/* reserved names of built-in types - valid ASN.1/TTCN names */
{"ADDRESS_", "ADDRESS", "ADDRESS"},
{"BITSTRING_", "BITSTRING", "BITSTRING"},
{"BOOLEAN_", 0, "BOOLEAN"},
{"BMPString_", 0, "BMPString"},
{"CHARSTRING_", "CHARSTRING", "CHARSTRING"},
{"COMPONENT_", "COMPONENT", "COMPONENT"},
{"DEFAULT_", 0, "DEFAULT"},
{"EXTERNAL_", 0, "EXTERNAL"},
{"FLOAT_", "FLOAT", "FLOAT"},
{"GraphicString_", 0, "GraphicString"},
{"HEXSTRING_", "HEXSTRING", "HEXSTRING"},
{"IA5String_", 0, "IA5String"},
{"INTEGER_", 0, "INTEGER"},
{"ISO646String_", 0, "ISO646String"},
{"NumericString_", 0, "NumericString"},
{"OBJECT_", "OBJECT", "OBJECT"},
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
{"OBJID_", "OBJID", "OBJID"},
{"OCTETSTRING_", "OCTETSTRING", "OCTETSTRING"},
{"ObjectDescriptor_", 0, "ObjectDescriptor"},
{"PrintableString_", 0, "PrintableString"},
{"T61String_", 0, "T61String"},
{"TeletexString_", 0, "TeletexString"},
{"UTF8String_", 0, "UTF8String"},
{"UniversalString_", 0, "UniversalString"},
{"VERDICTTYPE_", "VERDICTTYPE", "VERDICTTYPE"},
{"VideotexString_", 0, "VideotexString"},
{"VisibleString_", 0, "VisibleString"},
/* keywords in TTCN-3, not reserved words in C++, postfixed in TTCN */
{"action__", "action", "action_"},
{"activate__", "activate", "activate_"},
{"address__", "address", "address_"},
{"alive__", "alive", "alive_"},
{"all__", "all", "all_"},
{"alt__", "alt", "alt_"},
{"altstep__", "altstep", "altstep_"},
{"and4b__", "and4b", "and4b_"},
{"any__", "any", "any_"},
{"anytype__", "anytype", "anytype_"},
{"apply__", "apply", "apply_"},
{"bitstring__", "bitstring", "bitstring_"},
{"call__", "call", "call_"},
{"charstring__", "charstring", "charstring_"},
{"check__", "check", "check_"},
{"clear__", "clear", "clear_"},
{"complement__", "complement", "complement_"},
{"connect__", "connect", "connect_"},
{"control__", "control", "control_"},
{"create__", "create", "create_"},
{"deactivate__", "deactivate", "deactivate_"},
{"derefers__", "derefers", "derefers_"},
{"disconnect__", "disconnect", "disconnect_"},
{"display__", "display", "display_"},
{"done__", "done", "done_"},
{"encode__", "encode", "encode_"},
{"enumerated__", "enumerated", "enumerated_"},
{"error__", "error", "error_"},
{"except__", "except", "except_"},
{"exception__", "exception", "exception_"},
{"execute__", "execute", "execute_"},
{"extends__", "extends", "extends_"},
{"extension__", "extension", "extension_"},
{"external__", "external", "external_"},
{"fail__", "fail", "fail_"},
{"from__", "from", "from_"},
{"function__", "function", "function_"},
{"getcall__", "getcall", "getcall_"},
{"getreply__", "getreply", "getreply_"},
{"getverdict__", "getverdict", "getverdict_"},
{"group__", "group", "group_"},
{"halt__", "halt", "halt_"},
{"hexstring__", "hexstring", "hexstring_"},
{"ifpresent__", "ifpresent", "ifpresent_"},
{"import__", "import", "import_"},
{"in__", "in", "in_"},
{"inconc__", "inconc", "inconc_"},
{"infinity__", "infinity", "infinity_"},
{"inout__", "inout", "inout_"},
{"integer__", "integer", "integer_"},
{"interleave__", "interleave", "interleave_"},
{"kill__", "kill", "kill_"},
{"killed__", "killed", "killed_"},
{"label__", "label", "label_"},
{"language__", "language", "language_"},
{"length__", "length", "length_"},
{"map__", "map", "map_"},
{"message__", "message", "message_"},
{"mixed__", "mixed", "mixed_"},
{"modifies__", "modifies", "modifies_"},
{"module__", "module", "module_"},
{"modulepar__", "modulepar", "modulepar_"},
{"mtc__", "mtc", "mtc_"},
{"noblock__", "noblock", "noblock_"},
{"none__", "none", "none_"},
{"not4b__", "not4b", "not4b_"},
{"nowait__", "nowait", "nowait_"},
{"null__", "null", "null_"},
{"objid__", "objid", "objid_"},
{"octetstring__", "octetstring", "octetstring_"},
{"of__", "of", "of_"},
{"omit__", "omit", "omit_"},
{"on__", "on", "on_"},
{"optional__", "optional", "optional_"},
{"or4b__", "or4b", "or4b_"},
{"out__", "out", "out_"},
{"override__", "override", "override_"},
{"param__", "param", "param_"},
{"pass__", "pass", "pass_"},
{"pattern__", "pattern", "pattern_"},
{"permutation__", "permutation", "permutation_"},
{"port__", "port", "port_"},
{"procedure__", "procedure", "procedure_"},
{"raise__", "raise", "raise_"},
{"read__", "read", "read_"},
{"receive__", "receive", "receive_"},
{"record__", "record", "record_"},
{"recursive__", "recursive", "recursive_"},
{"refers__", "refers", "refers_"},
{"repeat__", "repeat", "repeat_"},
{"reply__", "reply", "reply_"},
{"running__", "running", "running_"},
{"runs__", "runs", "runs_"},
{"select__", "select", "select_"},
{"send__", "send", "send_"},
{"sender__", "sender", "sender_"},
{"set__", "set", "set_"},
{"setstate__", "setstate", "setstate_"},
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
{"setverdict__", "setverdict", "setverdict_"},
{"signature__", "signature", "signature_"},
{"start__", "start", "start_"},
{"stop__", "stop", "stop_"},
{"subset__", "subset", "subset_"},
{"superset__", "superset", "superset_"},
{"system__", "system", "system_"},
{"testcase__", "testcase", "testcase_"},
{"timeout__", "timeout", "timeout_"},
{"timer__", "timer", "timer_"},
{"to__", "to", "to_"},
{"trigger__", "trigger", "trigger_"},
{"type__", "type", "type_"},
{"universal__", "universal", "universal_"},
{"unmap__", "unmap", "unmap_"},
{"value__", "value", "value_"},
{"present__", "present", "present_"},
{"var__", "var", "var_"},
{"variant__", "variant", "variant_"},
{"with__", "with", "with_"},
{"xor4b__", "xor4b", "xor4b_"},
/* other names that need to be mapped in a non-uniform manner */
/* major and minor are macros on some platforms; avoid generating
* a potentially troublesome C++ identifier */
{"major_", "major", "major"},
{"minor_", "minor", "minor"},
/* internal / error */
{"<error>", "<error>", "<error>"},
{"TTCN_internal_", "<internal>", "<internal>"},
/* the last must be all zeros */
{0, 0, 0}
}; // keywords
Botond Baranyi
committed
// keywords for the real-time testing feature
// (can be switched on or off with a command line option)
const char* const internal_data_t::realtime_keywords[][3] = {
{"now__", "now", "now_"},
{"realtime__", "realtime", "realtime_"},
{"timestamp__", "timestamp", "timestamp_"},
{0, 0, 0}
};
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
internal_data_t::internal_data_t()
: identifier_counter(0), string_invalid("<invalid>"), id_map_name(),
id_map_asn(), id_map_ttcn()
{
}
internal_data_t::~internal_data_t()
{
for(size_t i=0; i<id_map_name.size(); i++)
Identifier::id_data_t::delete_this(id_map_name.get_nth_elem(i));
id_map_name.clear();
for(size_t i=0; i<id_map_asn.size(); i++)
Identifier::id_data_t::delete_this(id_map_asn.get_nth_elem(i));
id_map_asn.clear();
for(size_t i=0; i<id_map_ttcn.size(); i++)
Identifier::id_data_t::delete_this(id_map_ttcn.get_nth_elem(i));
id_map_ttcn.clear();
}
void internal_data_t::add_keyword(const char* const keyword[3])
{
Identifier::id_data_t *id_data
=new Identifier::id_data_t(string(keyword[0]));
bool conflict=false;
// Pointers to already added (conflicting) keyword
const Identifier::id_data_t *id_data_name=0;
const Identifier::id_data_t *id_data_asn=0;
const Identifier::id_data_t *id_data_ttcn=0;
if(id_map_name.has_key(id_data->name)) {
conflict=true;
id_data_name=id_map_name[id_data->name];
}
else {
id_map_name.add(id_data->name, id_data);
id_data->ref_count++;
}
if(keyword[1]==0) {
id_data->asnname=string_invalid;
}
else {
// copy the string if possible to avoid memory allocation
if (id_data->name == keyword[1]) id_data->asnname = id_data->name;
else id_data->asnname = keyword[1];
if(id_map_asn.has_key(id_data->asnname)) {
conflict=true;
id_data_asn=id_map_asn[id_data->asnname];
}
else {
id_map_asn.add(id_data->asnname, id_data);
id_data->ref_count++;
}
}
if(keyword[2]==0) {
id_data->ttcnname=string_invalid;
}
else {
// copy the string if possible to avoid memory allocation
if (id_data->name == keyword[2]) id_data->ttcnname = id_data->name;
else if (id_data->asnname == keyword[2])
id_data->ttcnname = id_data->asnname;
else id_data->ttcnname = keyword[2];
if(id_map_ttcn.has_key(id_data->ttcnname)) {
conflict=true;
id_data_ttcn=id_map_ttcn[id_data->ttcnname];
}
else {
id_map_ttcn.add(id_data->ttcnname, id_data);
id_data->ref_count++;
}
}
if(conflict) {
Location loc;
loc.error
("This pre-defined identifier: %s",
id_data->get_names().c_str());
loc.error
("conflicts with previous:");
if(id_data_name)
loc.error
("[C++:] %s",
id_data_name->get_names().c_str());
if(id_data_asn)
loc.error
("[ASN:] %s",
id_data_asn->get_names().c_str());
if(id_data_ttcn)
loc.error
("[TTCN:] %s",
id_data_ttcn->get_names().c_str());
} // if conflict
Identifier::id_data_t::delete_this(id_data);
}
void internal_data_t::add_keywords()
{
{
Location loc;
Error_Context cntx(&loc, "While adding keywords");
for(size_t i=0; keywords[i][0]; i++)
add_keyword(keywords[i]);
Botond Baranyi
committed
if (realtime_features) {
for(size_t i=0; realtime_keywords[i][0] != 0; i++) {
add_keyword(realtime_keywords[i]);
}
}
}
/* Perhaps it were good to read a file which contains
user-defined mappings :) */
}
internal_data_t *internal_data_t::Instance()
{
if(!instance) {
instance=new internal_data_t();
instance->add_keywords();
}