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
* Baranyi, Botond
* Beres, Szabolcs
* Bibo, Zoltan
* Cserveni, Akos
* Delic, Adam
* Forstner, Matyas
* Gecse, Roland
* Kovacs, Ferenc
* Raduly, Csaba
* Szabados, Kristof
BenceJanosSzabo
committed
* Szabo, Bence Janos
* Szabo, Janos Zoltan – initial implementation
* Tatarka, Gabor
*
******************************************************************************/
#include "../common/dbgnew.hh"
#include "Setting.hh"
#include <stdio.h>
#include <stdarg.h>
#include "map.hh"
#include "Identifier.hh"
#include "CompilerError.hh"
#include "AST.hh"
#include "asn1/AST_asn1.hh"
#include "ttcn3/AST_ttcn3.hh"
#include "Value.hh"
#include "Int.hh"
#include "main.hh"
Botond Baranyi
committed
#include "ttcn3/Attributes.hh"
#include "ttcn3/Ttcnstuff.hh"
#include "ttcn3/Statement.hh"
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
namespace Common {
// =================================
// ===== Location
// =================================
map<string,void> *Location::source_file_names = NULL;
bool Location::transparency = false;
const char* Location::add_source_file_name(const string& file_name)
{
if (source_file_names==NULL)
source_file_names = new map<string,void>();
if (!source_file_names->has_key(file_name))
source_file_names->add(file_name, NULL);
return source_file_names->get_key(file_name).c_str();
}
void Location::delete_source_file_names()
{
if (source_file_names!=NULL)
{
source_file_names->clear();
delete source_file_names;
source_file_names = NULL;
}
}
Location::Location()
{
filename = NULL;
yyloc.first_line = 0;
yyloc.last_line = 0;
yyloc.first_column = 0;
yyloc.last_column = 0;
}
Kristof Szabados
committed
void Location::set_location(const char *p_filename, size_t p_lineno)
{
filename = p_filename;
yyloc.first_line = p_lineno;
yyloc.first_column = 0;
yyloc.last_line = p_lineno;
yyloc.last_column = 0;
}
void Location::set_location(const char *p_filename, const YYLTYPE& p_yyloc)
{
filename = p_filename;
yyloc = p_yyloc;
}
void Location::set_location(const char *p_filename, const YYLTYPE& p_firstloc,
const YYLTYPE& p_lastloc)
{
filename = p_filename;
yyloc.first_line = p_firstloc.first_line;
yyloc.first_column = p_firstloc.first_column;
yyloc.last_line = p_lastloc.last_line;
yyloc.last_column = p_lastloc.last_column;
}
Kristof Szabados
committed
void Location::set_location(const char *p_filename, size_t p_first_line,
size_t p_first_column, size_t p_last_line, size_t p_last_column)
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
{
filename = p_filename;
yyloc.first_line = p_first_line;
yyloc.first_column = p_first_column;
yyloc.last_line = p_last_line;
yyloc.last_column = p_last_column;
}
void Location::join_location(const Location& p)
{
// do nothing if this and p refer to different files
if (filename) {
if (!p.filename) return;
else if (strcmp(filename, p.filename)) return;
} else if (p.filename) return;
if (yyloc.last_line < p.yyloc.first_line ||
(yyloc.last_line == p.yyloc.first_line &&
yyloc.last_column <= p.yyloc.first_column)) {
// p is after this
yyloc.last_line = p.yyloc.last_line;
yyloc.last_column = p.yyloc.last_column;
} else if (yyloc.first_line > p.yyloc.last_line ||
(yyloc.first_line == p.yyloc.last_line &&
yyloc.first_column >= p.yyloc.last_column)) {
// p is before this
yyloc.first_line = p.yyloc.first_line;
yyloc.first_column = p.yyloc.first_column;
}
}
void Location::print_line_info(FILE *fp) const
{
if (yyloc.first_line > 0) {
// at least partial line/column information is available
if (output_only_linenum || (yyloc.first_line == yyloc.last_line &&
yyloc.first_column <= 0 && yyloc.last_column <= 0)) {
// print only the first line
fprintf(fp, "%lu", yyloc.first_line);
} else if (yyloc.last_line > yyloc.first_line) {
// multi-line area
if (yyloc.first_column >= 0 && yyloc.last_column >= 0) {
// all line/column fields are valid
if (gcc_compat) {
fprintf(fp, "%lu:%lu", yyloc.first_line, yyloc.first_column + 1);
fprintf(fp, "%lu.%lu-%lu.%lu", yyloc.first_line,
yyloc.first_column + 1, yyloc.last_line, yyloc.last_column);
}
} else {
// only the line numbers are valid
if (gcc_compat) {
fprintf(fp, "%lu", yyloc.first_line);
fprintf(fp, "%lu-%lu", yyloc.first_line, yyloc.last_line);
}
}
} else if (yyloc.first_line == yyloc.last_line) {
// single line area
if (yyloc.first_column >= 0 && yyloc.last_column > yyloc.first_column) {
if (gcc_compat) {
fprintf(fp, "%lu:%lu", yyloc.first_line, yyloc.first_column + 1);
}
else {
if (yyloc.last_column > yyloc.first_column + 1) {
// more characters are covered
fprintf(fp, "%lu.%lu-%lu", yyloc.first_line, yyloc.first_column + 1,
yyloc.last_column);
} else {
// only a single character is covered
fprintf(fp, "%lu.%lu", yyloc.first_line, yyloc.first_column + 1);
}
}
} else {
// the column information is invalid, print the line number only
fprintf(fp, "%lu", yyloc.first_line);
}
} else {
// the last line is smaller than the first line
// print only the first line
fprintf(fp, "%lu", yyloc.first_line);
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
}
} else {
// line information is not available
fputs("<unknown>", fp);
}
}
void Location::print_location(FILE *fp) const
{
if (filename) {
fputs(filename, fp);
if (yyloc.first_line > 0) {
// print the line information only if it is available
putc(':', fp);
print_line_info(fp);
}
fputs(": ", fp);
}
// do not print anything if the file name is unknown
}
void Location::error(const char *fmt, ...) const
{
va_list args;
va_start(args, fmt);
Error_Context::report_error(this, fmt, args);
va_end(args);
}
void Location::warning(const char *fmt, ...) const
{
va_list args;
va_start(args, fmt);
Error_Context::report_warning(this, fmt, args);
va_end(args);
}
void Location::note(const char *fmt, ...) const
{
va_list args;
va_start(args, fmt);
Error_Context::report_note(this, fmt, args);
va_end(args);
}
char *Location::create_location_object(char *str, const char *entitytype,
const char *entityname) const
{
if (!filename || yyloc.first_line <= 0)
FATAL_ERROR("Location::create_location_object()");
if (include_location_info && !transparency) {
bool tcov_enabled = tcov_file_name && in_tcov_files(get_filename());
str = mputstr(str,
!tcov_enabled ? "TTCN_Location current_location(\""
: "TTCN_Location_Statistics current_location(\"");
str = Code::translate_string(str, filename);
str = mputprintf(str,
!tcov_enabled ? "\", %lu, TTCN_Location::LOCATION_%s, \"%s\");\n"
: "\", %lu, TTCN_Location_Statistics::LOCATION_%s, \"%s\");\n", yyloc.first_line, entitytype, entityname);
if (tcov_enabled) {
effective_module_lines =
mputprintf(effective_module_lines, "%s%lu",
(effective_module_lines ? ", " : ""), yyloc.first_line);
effective_module_functions =
mputprintf(effective_module_functions, "%s\"%s\"",
(effective_module_functions ? ", " : ""), entityname);
}
if (is_file_profiled(filename)) {
// .ttcnpp -> .ttcn
size_t file_name_len = strlen(filename);
if ('p' == filename[file_name_len - 1] && 'p' == filename[file_name_len - 2]) {
file_name_len -= 2;
}
char* file_name2 = mcopystrn(filename, file_name_len);
str = mputprintf(str,
"TTCN3_Stack_Depth stack_depth;\n"
"ttcn3_prof.enter_function(\"%s\", %lu);\n", file_name2, yyloc.first_line);
insert_profiler_code_line(file_name2,
(0 == strcmp(entitytype, "CONTROLPART") ? "control" : entityname),
yyloc.first_line);
Free(file_name2);
}
return str;
}
char *Location::update_location_object(char *str) const
{
if (filename && yyloc.first_line > 0) {
if (include_location_info && !transparency) {
str = mputprintf(str, "current_location.update_lineno(%lu);\n",
const char* file_name = get_filename();
if (is_file_profiled(file_name)) {
// .ttcnpp -> .ttcn
size_t file_name_len = strlen(file_name);
if ('p' == file_name[file_name_len - 1] && 'p' == file_name[file_name_len - 2]) {
file_name_len -= 2;
}
char* file_name2 = mcopystrn(file_name, file_name_len);
str = mputprintf(str, "ttcn3_prof.execute_line(\"%s\", %lu);\n",
file_name2, yyloc.first_line);
insert_profiler_code_line(file_name2, NULL, yyloc.first_line);
Free(file_name2);
mputprintf(effective_module_lines, "%s%lu",
(effective_module_lines ? ", " : ""), yyloc.first_line);
}
str = mputprintf(str, "ttcn3_debugger.breakpoint_entry(%lu);\n", yyloc.first_line);
str = mputprintf(str, "#line %lu \"%s\"\n", yyloc.first_line, filename);
else str = mputprintf(str, "/* %s, line %lu */\n", filename,
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
461
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
yyloc.first_line);
}
return str;
}
// =================================
// ===== Node
// =================================
int Node::counter=0;
#ifdef MEMORY_DEBUG
static Node *list_head = 0, *list_tail = 0;
#endif
Node::Node()
{
#ifdef MEMORY_DEBUG
prev_node = list_tail;
next_node = 0;
if (list_tail) list_tail->next_node = this;
else list_head = this;
list_tail = this;
#endif
counter++;
}
Node::Node(const Node&)
: fullname()
{
#ifdef MEMORY_DEBUG
prev_node = list_tail;
next_node = 0;
if (list_tail) list_tail->next_node = this;
else list_head = this;
list_tail = this;
#endif
counter++;
}
Node::~Node()
{
counter--;
#ifdef MEMORY_DEBUG
if (prev_node) prev_node->next_node = next_node;
else list_head = next_node;
if (next_node) next_node->prev_node = prev_node;
else list_tail = prev_node;
#endif
}
void Node::chk_counter()
{
DEBUG(1, "Node::counter is %d", counter);
if(counter)
WARNING("%d nodes were not deleted."
" Please send a bug report including"
" the current input file(s).", counter);
#ifdef MEMORY_DEBUG
for (Node *iter = list_head; iter; iter = iter->next_node) {
fprintf(stderr, "Undeleted node: `%s' (address %p).\n",
iter->get_fullname().c_str(), static_cast<void*>(iter));
}
list_head = 0;
list_tail = 0;
#endif
}
void Node::set_fullname(const string& p_fullname)
{
fullname = p_fullname;
}
void Node::set_my_scope(Scope *)
{
}
void Node::dump(unsigned level) const
{
DEBUG(level, "Node: %s", fullname.c_str());
}
// =================================
// ===== Setting
// =================================
Setting::Setting(settingtype_t p_st)
: Node(), Location(),
st(p_st), my_scope(0), checked(false), recurs_checked(false)
{
}
void Setting::set_my_scope(Scope *p_scope)
{
my_scope = p_scope;
}
bool Setting::is_asn1() const
{
if (!my_scope) FATAL_ERROR("Setting::is_asn1()");
return my_scope->get_scope_mod()->get_moduletype() == Module::MOD_ASN;
}
string Setting::get_temporary_id() const
{
if (!my_scope) FATAL_ERROR("Setting::get_temporary_id()");
return my_scope->get_scope_mod_gen()->get_temporary_id();
}
void Setting::set_genname(const string& p_genname)
{
if (p_genname.empty()) FATAL_ERROR("Setting::set_genname()");
genname = p_genname;
}
void Setting::set_genname(const string& p_prefix, const string& p_suffix)
{
if (p_prefix.empty() || p_suffix.empty())
FATAL_ERROR("Setting::set_genname()");
genname = p_prefix;
// a single underscore character is needed as separator if neither p_prefix
// ends nor p_suffix begins with a single underscore character
size_t p_prefix_len = p_prefix.size();
if ((p_prefix[p_prefix_len - 1] != '_' ||
(p_prefix_len >= 2 && p_prefix[p_prefix_len - 2] == '_')) &&
(p_suffix[0] != '_' ||
(p_suffix.size() >= 2 && p_suffix[1] == '_'))) genname += '_';
genname += p_suffix;
}
const string& Setting::get_genname_own() const
{
if (genname.empty())
FATAL_ERROR("Setting::get_genname_own(): genname is not set in %s", \
get_fullname().c_str());
return genname;
}
string Setting::get_genname_own(Scope *p_scope) const
{
if (!p_scope || !my_scope) FATAL_ERROR("Setting::get_genname_own");
string ret_val;
Module *my_mod = my_scope->get_scope_mod_gen();
if (my_mod != p_scope->get_scope_mod_gen() &&
!Asn::Assignments::is_spec_asss(my_mod)) {
// when the definition is referred from another module
// the reference shall be qualified with the namespace of my module
ret_val = my_mod->get_modid().get_name();
ret_val += "::";
}
ret_val += get_genname_own();
return ret_val;
}
string Setting::create_stringRepr()
{
return string("<string representation not implemented for " +
get_fullname() + ">");
}
// =================================
// ===== Setting_Error
// =================================
Setting_Error* Setting_Error::clone() const
{
FATAL_ERROR("Setting_Error::clone");
}
// =================================
// ===== Governor
// =================================
// =================================
// ===== Governed
// =================================
// =================================
// ===== GovernedSimple
// =================================
Botond Baranyi
committed
GovernedSimple::~GovernedSimple()
{
delete err_descrs;
}
void GovernedSimple::add_err_descr(Ttcn::Statement* p_update_statement,
Ttcn::ErroneousDescriptor* p_err_descr)
{
if (p_err_descr != NULL) {
if (err_descrs == NULL) {
err_descrs = new Ttcn::ErroneousDescriptors;
}
err_descrs->add(p_update_statement, p_err_descr);
}
}
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
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
string GovernedSimple::get_lhs_name() const
{
string ret_val;
if (genname_prefix) ret_val += genname_prefix;
ret_val += get_genname_own();
return ret_val;
}
bool GovernedSimple::needs_init_precede(const GovernedSimple *refd) const
{
if (refd->code_generated) return false;
if (code_section == CS_UNKNOWN || refd->code_section == CS_UNKNOWN)
FATAL_ERROR("GovernedSimple::needs_init_precede()");
if (code_section != refd->code_section) return false;
if (get_my_scope()->get_scope_mod_gen() !=
refd->get_my_scope()->get_scope_mod_gen()) return false;
else return true;
}
bool GovernedSimple::is_toplevel() const
{
const string& name = get_genname_own();
const char *name_str = name.c_str();
size_t name_len = name.size();
for (size_t i = 0; i < name_len; i++) {
char c = name_str[i];
if ((c < 'A' || c > 'Z') && (c < 'a' ||c > 'z') &&
(c < '0' || c > '9') && c != '_') return false;
}
return true;
}
// =================================
// ===== GovdSet
// =================================
// =================================
// ===== Scope
// =================================
string Scope::get_scope_name() const
{
string s;
if (parent_scope) s = parent_scope->get_scope_name();
if (!scope_name.empty()) {
if (s.empty()) s = scope_name;
else {
s += '.';
s += scope_name;
}
}
return s;
}
string Scope::get_scopeMacro_name() const
{
if (!scopeMacro_name.empty()) return scopeMacro_name;
if (parent_scope) return parent_scope->get_scopeMacro_name();
return scopeMacro_name;
}
Ttcn::StatementBlock *Scope::get_statementblock_scope()
{
if (parent_scope) return parent_scope->get_statementblock_scope();
else return 0;
}
Ttcn::RunsOnScope *Scope::get_scope_runs_on()
{
if (parent_scope) return parent_scope->get_scope_runs_on();
else return 0;
}
BenceJanosSzabo
committed
Ttcn::PortScope *Scope::get_scope_port()
{
if (parent_scope) return parent_scope->get_scope_port();
else return 0;
}
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
Assignments *Scope::get_scope_asss()
{
if (parent_scope) return parent_scope->get_scope_asss();
else
FATAL_ERROR("The assignments scope is not visible from this scope: " \
"`%s'", get_scope_name().c_str());
return 0;
}
Module* Scope::get_scope_mod()
{
if(parent_scope) return parent_scope->get_scope_mod();
else FATAL_ERROR("The module scope is not visible from this scope: `%s'", \
get_scope_name().c_str());
return 0;
}
Module* Scope::get_scope_mod_gen()
{
if(parent_scope_gen) return parent_scope_gen->get_scope_mod_gen();
else if(parent_scope) return parent_scope->get_scope_mod_gen();
else FATAL_ERROR("The module scope is not visible from this scope: `%s'", \
get_scope_name().c_str());
return 0;
}
Ttcn::ClassTypeBody* Scope::get_scope_class()
{
if (parent_scope != NULL) {
return parent_scope->get_scope_class();
}
return NULL;
}
bool Scope::has_ass_withId(const Identifier& p_id)
{
if (parent_scope) return parent_scope->has_ass_withId(p_id);
else return false;
}
bool Scope::is_valid_moduleid(const Identifier& p_id)
{
if (parent_scope) return parent_scope->is_valid_moduleid(p_id);
else return false;
}
if (parent_scope) return parent_scope->get_mtc_system_comptype(is_system);
else return 0;
}
void Scope::chk_runs_on_clause(Assignment *p_ass, const Location& p_loc,
const char *p_what)
{
// component type of the referred definition
Type *refd_comptype = p_ass->get_RunsOnType();
// definitions without 'runs on' can be called from anywhere
if (!refd_comptype) return;
Ttcn::RunsOnScope *t_ros = get_scope_runs_on();
if (t_ros) {
Type *local_comptype = t_ros->get_component_type();
if (!refd_comptype->is_compatible(local_comptype, NULL, NULL)) {
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
// the 'runs on' clause of the referred definition is not compatible
// with that of the current scope (i.e. the referring definition)
p_loc.error("Runs on clause mismatch: A definition that runs on "
"component type `%s' cannot %s %s, which runs on `%s'",
local_comptype->get_typename().c_str(), p_what,
p_ass->get_description().c_str(),
refd_comptype->get_typename().c_str());
}
} else {
// the current scope unit (i.e. the referring definition) does not have
// 'runs on' clause
p_loc.error("A definition without `runs on' clause cannot %s %s, which "
"runs on component type `%s'", p_what, p_ass->get_description().c_str(),
refd_comptype->get_typename().c_str());
}
}
void Scope::chk_runs_on_clause(Type *p_fat, const Location& p_loc,
const char *p_what)
{
if (!p_fat) FATAL_ERROR("Scope::chk_runs_on_clause()");
Type *refd_comptype = p_fat->get_fat_runs_on_type();
// values of function/altstep types without 'runs on' clause
// or using 'runs on self' clause can be called from anywhere
if (!refd_comptype) return;
const char *typetype_name;
switch (p_fat->get_typetype()) {
case Type::T_FUNCTION:
typetype_name = "function";
break;
case Type::T_ALTSTEP:
typetype_name = "altstep";
break;
case Type::T_CLASS:
typetype_name = "class";
break;
default:
FATAL_ERROR("Scope::chk_runs_on_clause()");
typetype_name = 0;
}
Ttcn::RunsOnScope *t_ros = get_scope_runs_on();
if (t_ros) {
Type *local_comptype = t_ros->get_component_type();
if (!refd_comptype->is_compatible(local_comptype, NULL, NULL)) {
// the 'runs on' clause of the function/altstep type is not compatible
// with that of the current scope (i.e. the referring definition)
p_loc.error("Runs on clause mismatch: A definition that runs on "
"component type `%s' cannot %s a value of %s type `%s', which runs "
"on `%s'", local_comptype->get_typename().c_str(), p_what,
typetype_name, p_fat->get_typename().c_str(),
refd_comptype->get_typename().c_str());
}
} else {
// the current scope unit (i.e. the referring definition) does not have
// 'runs on' clause
p_loc.error("A definition without `runs on' clause cannot %s a value of "
"%s type `%s', which runs on component type `%s'", p_what,
typetype_name, p_fat->get_typename().c_str(),
refd_comptype->get_typename().c_str());
}
}
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
void Scope::chk_mtc_clause(Assignment *p_ass, const Location& p_loc,
const char *p_what, bool in_control_part)
{
// component type of the referred definition
Type *refd_comptype = p_ass->get_MtcType();
// definitions without 'mtc' can be called from anywhere
if (!refd_comptype) return;
if (in_control_part) {
p_loc.error("Function with mtc or system clause is not allowed in control part.");
return;
}
Type *t_comptype = get_mtc_system_comptype(false);
if (t_comptype) {
if (!refd_comptype->is_compatible_component_by_port(t_comptype)) {
// the 'mtc' clause of the referred definition is not compatible
// with that of the current scope (i.e. the referring definition)
p_loc.error("Mtc clause mismatch: A definition that runs on "
"component type `%s' cannot %s %s, which mtc clause is `%s'",
t_comptype->get_typename().c_str(), p_what,
p_ass->get_description().c_str(),
refd_comptype->get_typename().c_str());
}
}
}
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
void Scope::chk_mtc_clause(Type* p_type, const Location& p_loc)
{
// component type of the referred definition
Type* refd_comptype = p_type->get_class_type_body()->get_MtcType();
// definitions without 'mtc' can be called from anywhere
if (refd_comptype == NULL) {
return;
}
if (get_statementblock_scope()->get_my_def() == NULL) { // in control part
p_loc.error("Cannot create value of class type `%s', which has an `mtc' "
"clause, in the control part.", p_type->get_typename().c_str());
return;
}
Type* t_comptype = get_mtc_system_comptype(false);
if (t_comptype != NULL) {
if (!refd_comptype->is_compatible_component_by_port(t_comptype)) {
// the 'mtc' clause of the referred definition is not compatible
// with that of the current scope (i.e. the referring definition)
p_loc.error("Mtc clause mismatch: A definition that runs on component "
"type `%s' cannot create a value of class type `%s', which has `mtc' "
"component type `%s'",
t_comptype->get_typename().c_str(), p_type->get_typename().c_str(),
refd_comptype->get_typename().c_str());
}
}
}
void Scope::chk_system_clause(Assignment *p_ass, const Location& p_loc,
const char *p_what, bool in_control_part)
{
// component type of the referred definition
Type *refd_comptype = p_ass->get_SystemType();
// definitions without 'system' can be called from anywhere
if (!refd_comptype) return;
if (in_control_part) {
p_loc.error("Function with mtc or system clause is not allowed in control part.");
return;
}
Type *t_comptype = get_mtc_system_comptype(true);
if (t_comptype) {
if (!refd_comptype->is_compatible_component_by_port(t_comptype)) {
// the 'system' clause of the referred definition is not compatible
// with that of the current scope (i.e. the referring definition)
p_loc.error("System clause mismatch: A definition with system "
"component type `%s' cannot %s %s, which system clause is `%s'",
t_comptype->get_typename().c_str(), p_what,
p_ass->get_description().c_str(),
refd_comptype->get_typename().c_str());
}
}
}
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
void Scope::chk_system_clause(Type* p_type, const Location& p_loc)
{
// component type of the referred definition
Type* refd_comptype = p_type->get_class_type_body()->get_SystemType();
// definitions without 'system' can be called from anywhere
if (refd_comptype == NULL) {
return;
}
if (get_statementblock_scope()->get_my_def() == NULL) { // in control part
p_loc.error("Cannot create value of class type `%s', which has a `system' "
"clause, in the control part.", p_type->get_typename().c_str());
return;
}
Type* t_comptype = get_mtc_system_comptype(true);
if (t_comptype != NULL) {
if (!refd_comptype->is_compatible_component_by_port(t_comptype)) {
// the 'system' clause of the referred definition is not compatible
// with that of the current scope (i.e. the referring definition)
p_loc.error("System clause mismatch: A definition that runs on component "
"type `%s' cannot create a value of class type `%s', which has `system' "
"component type `%s'",
t_comptype->get_typename().c_str(), p_type->get_typename().c_str(),
refd_comptype->get_typename().c_str());
}
}
}
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
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
// =================================
// ===== Reference
// =================================
size_t Reference::_Reference_counter=0;
Setting_Error *Reference::setting_error = 0;
Reference::~Reference()
{
if (_Reference_counter <= 0) FATAL_ERROR("Reference::~Reference()");
else if (--_Reference_counter == 0) {
delete setting_error;
setting_error = 0;
}
}
void Reference::set_my_scope(Scope *p_scope)
{
my_scope = p_scope;
}
bool Reference::get_is_erroneous()
{
return is_erroneous;
}
Setting* Reference::get_refd_setting_error()
{
is_erroneous=true;
if(!setting_error)
setting_error=new Setting_Error();
return setting_error;
}
bool Reference::refers_to_st(Setting::settingtype_t p_st,
ReferenceChain*)
{
Setting *t_setting=get_refd_setting();
if(t_setting) return t_setting->get_st()==p_st;
else return p_st==Setting::S_ERROR;
}
void Reference::set_code_section(GovernedSimple::code_section_t)
{
}
Assignment* Reference::get_refd_assignment_last(bool check_parlist)
{
return this->get_refd_assignment(check_parlist);
}
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
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
Ttcn::FieldOrArrayRefs *Reference::get_subrefs()
{
return 0;
}
Ttcn::ActualParList *Reference::get_parlist()
{
return 0;
}
void Reference::dump(unsigned level) const
{
DEBUG(level, "Reference: %s", const_cast<Reference*>(this)->get_dispname().c_str());
}
// =================================
// ===== Ref_simple
// =================================
string Ref_simple::get_dispname()
{
string ret_val;
const Identifier *t_modid = get_modid();
if (t_modid) {
ret_val += t_modid->get_dispname();
ret_val += '.';
}
ret_val += get_id()->get_dispname();
return ret_val;
}
Setting* Ref_simple::get_refd_setting()
{
if(get_is_erroneous()) return get_refd_setting_error();
Assignment *ass = get_refd_assignment();
if (ass) return ass->get_Setting();
else return get_refd_setting_error();
}
Assignment* Ref_simple::get_refd_assignment(bool)
{
if (!refd_ass) {
if (!my_scope) FATAL_ERROR("Common::Ref_simple::get_refd_assignment()");
refd_ass = my_scope->get_ass_bySRef(this);
}
return refd_ass;
}
bool Ref_simple::has_single_expr()
{
return true;
}
// =================================
// ===== ReferenceChain
// =================================
ReferenceChain::ReferenceChain(const Location *p_loc, const char *p_str)
: my_loc(p_loc), err_str(p_str), report_error(true)
{
if(!p_loc)
FATAL_ERROR("ReferenceChain::ReferenceChain()");
}
ReferenceChain::~ReferenceChain()
{
reset();
}
ReferenceChain *ReferenceChain::clone() const
{
FATAL_ERROR("ReferenceChain::clone()");
return 0;
}
bool ReferenceChain::exists(const string& s) const
{
for (size_t i = 0; i < refs.size(); i++)
if (*refs[i]==s) return true;
return false;
}
bool ReferenceChain::add(const string& s)
{
if (!exists(s)) {
refs.add(new string(s));
return true;
}
if (report_error) {
if (err_str) {
my_loc->error("%s: Circular reference: %s", err_str,
get_dispstr(s).c_str());
} else {
my_loc->error("Circular reference: %s", get_dispstr(s).c_str());
}
} else {
errors.add(get_dispstr(s));
}
return false;
}
Botond Baranyi
committed
bool ReferenceChain::is_error_reporting_on() const {
return report_error;
}
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
void ReferenceChain::set_error_reporting(bool enable) {
report_error = enable;
}
size_t ReferenceChain::nof_errors() const {
return errors.size() - (err_stack.empty() ? 0 : *err_stack.top());
}
void ReferenceChain::report_errors()
{
if (!err_stack.empty() && *err_stack.top() > errors.size())
FATAL_ERROR("Common::ReferenceChain::report_errors()");
string err_msg;
if (err_str) {
err_msg += err_str;
err_msg += ": ";
}
for (size_t i = (err_stack.empty() ? 0 : *err_stack.top());
i < errors.size(); ++i) {
my_loc->error("%sCircular reference: %s",
err_msg.c_str(), errors[i].c_str());
}
}
void ReferenceChain::mark_error_state()
{
err_stack.push(new size_t(errors.size()));
}