1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2014 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 ///////////////////////////////////////////////////////////////////////////////
10 #include "../common/memory.h"
16 #include "openssl/bn.h"
21 #include "Verdicttype.hh"
22 #include "Bitstring.hh"
23 #include "Hexstring.hh"
24 #include "Octetstring.hh"
25 #include "Charstring.hh"
26 #include "Universal_charstring.hh"
30 size_t Module_Param_Id::get_index() const {
31 TTCN_error("Internal error: Module_Param_Id::get_index()");
35 char* Module_Param_Id::get_name() const {
36 TTCN_error("Internal error: Module_Param_Id::get_name()");
40 char* Module_Param_Id::get_current_name() const {
41 TTCN_error("Internal error: Module_Param_Id::get_current_name()");
45 bool Module_Param_Id::next_name(int offset
) {
46 TTCN_error("Internal error: Module_Param_Id::next_name()");
50 char* Module_Param_Name::get_str() const {
52 for (size_t i
= 0; i
< names
.size(); ++i
) {
53 bool is_index
= names
[i
][0] >= '0' && names
[i
][0] <= '9';
54 if (i
> 0 && !is_index
) {
55 result
= mputc(result
, '.');
58 result
= mputc(result
, '[');
60 result
= mputstr(result
, names
[i
]);
62 result
= mputc(result
, ']');
68 char* Module_Param_FieldName::get_str() const {
69 return mcopystr(name
);
72 char* Module_Param_Index::get_str() const {
73 return mprintf("[%lu]", (unsigned long)index
);
76 void Module_Param_Length_Restriction::log() const {
77 TTCN_Logger::log_event(" length(%lu", (unsigned long)min
);
79 TTCN_Logger::log_event_str("..");
80 if (!has_max
) TTCN_Logger::log_event_str("infinity");
81 else TTCN_Logger::log_event("%lu", (unsigned long)max
);
83 TTCN_Logger::log_event_str(")");
86 Module_Param_Id
* Module_Param::get_id() const {
90 const char* Module_Param::get_operation_type_str() const {
91 switch (operation_type
) {
92 case OT_ASSIGN
: return "assignment";
93 case OT_CONCAT
: return "concatenation";
94 default: return "<unknown operation>";
98 const char* Module_Param::get_operation_type_sign_str() const {
99 switch (operation_type
) {
100 case OT_ASSIGN
: return ":=";
101 case OT_CONCAT
: return "&=";
102 default: return "<unknown operation>";
106 void Module_Param::set_id(Module_Param_Id
* p_id
) {
107 if (id
) TTCN_error("Internal error: Module_Param::set_id()");
111 void Module_Param::set_length_restriction(Module_Param_Length_Restriction
* p_length_restriction
) {
112 if (length_restriction
!=NULL
) TTCN_error("Internal error: Module_Param::set_length_restriction()");
113 length_restriction
= p_length_restriction
;
116 void Module_Param::log(bool log_id
) const {
117 if (log_id
&& id
&& id
->is_explicit()) {
118 char* id_str
= id
->get_str();
119 TTCN_Logger::log_event_str(id_str
);
121 TTCN_Logger::log_event_str(get_operation_type_sign_str());
125 TTCN_Logger::log_event_str(" ifpresent");
127 if (length_restriction
!=NULL
) {
128 length_restriction
->log();
132 void Module_Param::basic_check(int check_bits
, const char* what
) const {
133 bool is_template
= check_bits
& BC_TEMPLATE
;
134 bool is_list
= check_bits
& BC_LIST
;
135 if (is_template
|| !is_list
) {
136 if (get_operation_type()!=OT_ASSIGN
) error("The %s of %ss is not allowed.", get_operation_type_str(), what
);
139 if (has_ifpresent
) error("%s cannot have an 'ifpresent' attribute", what
);
141 if (!is_template
|| !is_list
) {
142 if (length_restriction
!=NULL
) error("%s cannot have a length restriction", what
);
146 void Module_Param::add_elem(Module_Param
* /*value*/) {
147 TTCN_error("Internal error: Module_Param::add_elem()");
150 void Module_Param::add_list_with_implicit_ids(Vector
<Module_Param
*>* /*mp_list*/) {
151 TTCN_error("Internal error: Module_Param::add_list_with_implicit_ids()");
154 boolean
Module_Param::get_boolean() const {
155 TTCN_error("Internal error: Module_Param::get_boolean()");
159 size_t Module_Param::get_size() const {
160 TTCN_error("Internal error: Module_Param::get_size()");
164 Module_Param
* Module_Param::get_elem(size_t /*index*/) const {
165 TTCN_error("Internal error: Module_Param::get_elem()");
169 int Module_Param::get_string_size() const {
170 TTCN_error("Internal error: Module_Param::get_string_size()");
174 void* Module_Param::get_string_data() const {
175 TTCN_error("Internal error: Module_Param::get_string_data()");
179 int_val_t
* Module_Param::get_lower_int() const {
180 TTCN_error("Internal error: Module_Param::get_lower_int()");
184 int_val_t
* Module_Param::get_upper_int() const {
185 TTCN_error("Internal error: Module_Param::get_upper_int()");
189 double Module_Param::get_lower_float() const {
190 TTCN_error("Internal error: Module_Param::get_lower_float()");
194 double Module_Param::get_upper_float() const {
195 TTCN_error("Internal error: Module_Param::get_upper_float()");
199 bool Module_Param::has_lower_float() const {
200 TTCN_error("Internal error: Module_Param::has_lower_float()");
204 bool Module_Param::has_upper_float() const {
205 TTCN_error("Internal error: Module_Param::has_upper_float()");
209 universal_char
Module_Param::get_lower_uchar() const {
210 TTCN_error("Internal error: Module_Param::get_lower_uchar()");
211 return universal_char();
214 universal_char
Module_Param::get_upper_uchar() const {
215 TTCN_error("Internal error: Module_Param::get_upper_uchar()");
216 return universal_char();
219 int_val_t
* Module_Param::get_integer() const {
220 TTCN_error("Internal error: Module_Param::get_integer()");
224 double Module_Param::get_float() const {
225 TTCN_error("Internal error: Module_Param::get_float()");
229 char* Module_Param::get_pattern() const {
230 TTCN_error("Internal error: Module_Param::get_pattern()");
234 verdicttype
Module_Param::get_verdict() const {
235 TTCN_error("Internal error: Module_Param::get_verdict()");
239 char* Module_Param::get_enumerated() const {
240 TTCN_error("Internal error: Module_Param::get_enumerated()");
244 void Module_Param_NotUsed::log_value() const {
245 TTCN_Logger::log_event_str("-");
248 void Module_Param_Omit::log_value() const {
249 TTCN_Logger::log_event_str("omit");
252 Module_Param_Integer::Module_Param_Integer(int_val_t
* p
): integer_value(p
) {
253 if (integer_value
==NULL
) TTCN_error("Internal error: Module_Param_Integer::Module_Param_Integer()");
256 void Module_Param_Integer::log_value() const {
257 if (integer_value
->is_native()) {
258 INTEGER(integer_value
->get_val()).log();
261 integer
.set_val(*integer_value
);
266 void Module_Param_Float::log_value() const {
267 FLOAT(float_value
).log();
270 void Module_Param_Boolean::log_value() const {
271 BOOLEAN(boolean_value
).log();
274 void Module_Param_Verdict::log_value() const {
275 VERDICTTYPE(verdict_value
).log();
278 void Module_Param_Objid::log_value() const {
279 OBJID(n_chars
, chars_ptr
).log();
282 void Module_Param_Bitstring::log_value() const {
283 BITSTRING(n_chars
, chars_ptr
).log();
286 void Module_Param_Hexstring::log_value() const {
287 HEXSTRING(n_chars
, chars_ptr
).log();
290 void Module_Param_Octetstring::log_value() const {
291 OCTETSTRING(n_chars
, chars_ptr
).log();
294 void Module_Param_Charstring::log_value() const {
295 CHARSTRING(n_chars
, chars_ptr
).log();
298 void Module_Param_Universal_Charstring::log_value() const {
299 UNIVERSAL_CHARSTRING(n_chars
, chars_ptr
).log();
302 void Module_Param_Enumerated::log_value() const {
303 TTCN_Logger::log_event_str(enum_value
);
306 void Module_Param_Ttcn_Null::log_value() const {
307 TTCN_Logger::log_event_str("null");
310 void Module_Param_Ttcn_mtc::log_value() const {
311 TTCN_Logger::log_event_str("mtc");
314 void Module_Param_Ttcn_system::log_value() const {
315 TTCN_Logger::log_event_str("system");
318 void Module_Param_Asn_Null::log_value() const {
319 TTCN_Logger::log_event_str("NULL");
322 void Module_Param_Any::log_value() const {
323 TTCN_Logger::log_event_str("?");
326 void Module_Param_AnyOrNone::log_value() const {
327 TTCN_Logger::log_event_str("*");
330 void Module_Param_IntRange::log_bound(int_val_t
* bound
, bool is_lower
) {
332 if (is_lower
) TTCN_Logger::log_event_str("-");
333 TTCN_Logger::log_event_str("infinity");
334 } else if (bound
->is_native()) {
335 INTEGER(bound
->get_val()).log();
338 integer
.set_val(*bound
);
343 void Module_Param_IntRange::log_value() const {
344 TTCN_Logger::log_event_str("(");
345 log_bound(lower_bound
, true);
346 TTCN_Logger::log_event_str("..");
347 log_bound(upper_bound
, false);
348 TTCN_Logger::log_event_str(")");
351 void Module_Param_FloatRange::log_value() const {
352 TTCN_Logger::log_event_str("(");
353 if (has_lower
) FLOAT(lower_bound
).log();
354 else TTCN_Logger::log_event_str("-infinity");
355 TTCN_Logger::log_event_str("..");
356 if (has_upper
) FLOAT(upper_bound
).log();
357 else TTCN_Logger::log_event_str("infinity");
358 TTCN_Logger::log_event_str(")");
361 void Module_Param_StringRange::log_value() const {
362 TTCN_Logger::log_event_str("(");
363 UNIVERSAL_CHARSTRING(lower_bound
).log();
364 TTCN_Logger::log_event_str("..");
365 UNIVERSAL_CHARSTRING(upper_bound
).log();
366 TTCN_Logger::log_event_str(")");
369 void Module_Param_Pattern::log_value() const {
370 TTCN_Logger::log_event_str("pattern \"");
371 TTCN_Logger::log_event_str(pattern
);
372 TTCN_Logger::log_event_str("\"");
375 void Module_Param_Bitstring_Template::log_value() const {
376 BITSTRING_template((unsigned int)n_chars
, chars_ptr
).log();
379 void Module_Param_Hexstring_Template::log_value() const {
380 HEXSTRING_template((unsigned int)n_chars
, chars_ptr
).log();
383 void Module_Param_Octetstring_Template::log_value() const {
384 OCTETSTRING_template((unsigned int)n_chars
, chars_ptr
).log();
387 Module_Param_Compound::~Module_Param_Compound() {
388 for (size_t i
=0; i
<values
.size(); i
++) {
394 size_t Module_Param_Compound::get_size() const {
395 return values
.size();
398 Module_Param
* Module_Param_Compound::get_elem(size_t index
) const {
399 if (index
>=values
.size()) TTCN_error("Internal error: Module_Param::get_elem(): index overflow");
400 return values
[index
];
403 void Module_Param_Compound::log_value_vec(const char* begin_str
, const char* end_str
) const {
404 TTCN_Logger::log_event_str(begin_str
);
405 TTCN_Logger::log_event_str(" ");
406 for (size_t i
=0; i
<values
.size(); ++i
) {
407 if (i
>0) TTCN_Logger::log_event_str(", ");
410 if (!values
.empty()) TTCN_Logger::log_event_str(" ");
411 TTCN_Logger::log_event_str(end_str
);
414 void Module_Param_Compound::add_elem(Module_Param
* value
) {
415 value
->set_parent(this);
416 values
.push_back(value
);
419 void Module_Param_Compound::add_list_with_implicit_ids(Vector
<Module_Param
*>* mp_list
) {
420 for (size_t i
=0; i
<mp_list
->size(); i
++) {
421 Module_Param
* mp_current
= mp_list
->at(i
);
422 mp_current
->set_id(new Module_Param_Index(get_size(),false));
423 add_elem(mp_current
);
427 char* Module_Param::get_param_context() const {
429 if (parent
!= NULL
) {
430 result
= parent
->get_param_context();
433 char* id_str
= id
->get_str();
434 if (parent
!=NULL
&& !id
->is_index()) {
435 result
= mputc(result
, '.');
437 result
= mputstr(result
, id_str
);
443 void Module_Param::error(const char* err_msg
, ...) const {
444 if (Ttcn_String_Parsing::happening()) {
445 char* exception_str
= mcopystr("Error while setting parameter field '");
446 char* param_ctx
= get_param_context();
447 exception_str
= mputstr(exception_str
, param_ctx
);
449 exception_str
= mputstr(exception_str
, "': ");
451 va_start(p_var
, err_msg
);
452 char* error_msg_str
= mprintf_va_list(err_msg
, p_var
);
454 exception_str
= mputstr(exception_str
, error_msg_str
);
456 TTCN_error_begin("%s", exception_str
);
460 TTCN_Logger::begin_event(TTCN_Logger::ERROR_UNQUALIFIED
);
461 TTCN_Logger::log_event_str("Error while ");
462 switch (operation_type
) {
463 case OT_ASSIGN
: TTCN_Logger::log_event_str("setting"); break;
464 case OT_CONCAT
: TTCN_Logger::log_event_str("concatenating"); break;
465 default: TTCN_Logger::log_event_str("???");
467 TTCN_Logger::log_event_str(" parameter field '");
468 char* param_ctx
= get_param_context();
469 TTCN_Logger::log_event_str(param_ctx
);
471 switch (operation_type
) {
472 case OT_ASSIGN
: TTCN_Logger::log_event_str("' to '"); break;
473 case OT_CONCAT
: TTCN_Logger::log_event_str("' and '"); break;
474 default: TTCN_Logger::log_event_str("' ??? '");
477 TTCN_Logger::log_event_str("': ");
479 va_start(p_var
, err_msg
);
480 TTCN_Logger::log_event_va_list(err_msg
, p_var
);
482 TTCN_Logger::send_event_as_error();
483 TTCN_Logger::end_event();
487 bool Ttcn_String_Parsing::string_parsing
= false;