u.expr.v3 = p.u.expr.v3 ? p.u.expr.v3->clone() : 0;
break;
case OPTYPE_LOG2STR:
+ case OPTYPE_ANY2UNISTR:
u.expr.logargs = p.u.expr.logargs->clone();
break;
default:
delete u.expr.v3;
break;
case OPTYPE_LOG2STR:
+ case OPTYPE_ANY2UNISTR:
delete u.expr.logargs;
break;
default:
u.expr.state = EXPR_NOT_CHECKED;
switch(p_optype) {
case OPTYPE_LOG2STR:
+ case OPTYPE_ANY2UNISTR:
if (!p_logargs) FATAL_ERROR("Value::Value()");
u.expr.logargs = p_logargs;
break;
case OPTYPE_LOG2STR:
u.expr.logargs->set_fullname(p_fullname+".<logargs>");
break;
+ case OPTYPE_ANY2UNISTR:
+ u.expr.logargs->set_fullname(p_fullname+".<logarg>");
+ break;
default:
FATAL_ERROR("Value::set_fullname_expr()");
} // switch
u.expr.v3->set_my_scope(p_scope);
break;
case OPTYPE_LOG2STR:
+ case OPTYPE_ANY2UNISTR:
u.expr.logargs->set_my_scope(p_scope);
break;
default:
u.expr.v3->set_code_section(p_code_section);
break;
case OPTYPE_LOG2STR:
+ case OPTYPE_ANY2UNISTR:
u.expr.logargs->set_code_section(p_code_section);
break;
default:
case OPTYPE_INT2UNICHAR:
case OPTYPE_OCT2UNICHAR:
case OPTYPE_ENCVALUE_UNICHAR:
+ case OPTYPE_ANY2UNISTR:
return Type::T_USTR;
case OPTYPE_INT2BIT:
case OPTYPE_HEX2BIT:
return "isbound()";
case OPTYPE_LOG2STR:
return "log2str()";
+ case OPTYPE_ANY2UNISTR:
+ return "any2unistr()";
case OPTYPE_TTCN2STRING:
return "ttcn2string()";
case OPTYPE_PROF_RUNNING:
void Value::chk_expr_operand_encode(ReferenceChain *refch,
Type::expected_value_t exp_val) {
- Error_Context cntxt(this, "In the parameter of encvalue()");
+ Error_Context cntxt(this, "In the parameter of %s",
+ u.expr.v_optype == OPTYPE_ENCVALUE_UNICHAR ? "encvalue_unichar()" : "encvalue()");
Type t_chk(Type::T_ERROR);
Type* t_type;
void Value::chk_expr_operands_decode(operationtype_t p_optype)
{
- Error_Context cntxt(this, "In the parameters of decvalue()"); //todo
+ Error_Context cntxt(this, "In the parameters of %s",
+ p_optype == OPTYPE_DECVALUE_UNICHAR ? "encvalue_unichar()" : "decvalue()");
Ttcn::Ref_base* ref = u.expr.r1;
Ttcn::FieldOrArrayRefs* t_subrefs = ref->get_subrefs();
Type* t_type = 0;
}
chk_expr_operands_replace();
break; }
- case OPTYPE_LOG2STR: {
+ case OPTYPE_LOG2STR:
+ case OPTYPE_ANY2UNISTR: {
Error_Context cntxt(this, "In the operand of operation `%s'", opname);
u.expr.logargs->chk();
if (!semantic_check_only) u.expr.logargs->join_strings();
case OPTYPE_MATCH: // v1 t2
case OPTYPE_ISCHOSEN_T:
case OPTYPE_LOG2STR:
+ case OPTYPE_ANY2UNISTR:
case OPTYPE_ENCODE:
case OPTYPE_DECODE:
case OPTYPE_ISBOUND:
case OPTYPE_ISCHOSEN_V:
return u.expr.v1->is_unfoldable(refch, exp_val);
case OPTYPE_LOG2STR:
+ case OPTYPE_ANY2UNISTR:
case OPTYPE_TTCN2STRING:
return true;
default:
refch.prev_state();
break;
case OPTYPE_LOG2STR:
+ case OPTYPE_ANY2UNISTR:
u.expr.logargs->chk_recursions(refch);
break;
default:
// boolvar := a_timer.running -- assume no self-ref
break;
break;
-
+
+ case OPTYPE_ANY2UNISTR:
case OPTYPE_LOG2STR: {// logargs
for (size_t i = 0, e = u.expr.logargs->get_nof_logargs(); i < e; ++i) {
const Ttcn::LogArgument *la = u.expr.logargs->get_logarg_byIndex(i);
switch (la->get_type()) {
case Ttcn::LogArgument::L_UNDEF:
case Ttcn::LogArgument::L_ERROR:
- FATAL_ERROR("log2str argument type");
+ FATAL_ERROR("%s argument type",
+ u.expr.v_optype == OPTYPE_ANY2UNISTR ? "any2unistr" : "log2str");
break; // not reached
case Ttcn::LogArgument::L_MACRO:
return ret_val; }
case OPTYPE_LOG2STR:
return string("log2str(...)");
+ case OPTYPE_ANY2UNISTR:
+ return string("any2unistr(...)");
case OPTYPE_MATCH: {
string ret_val("match(");
ret_val += u.expr.v1->get_stringRepr();
generate_code_expr_execute_refd(expr);
break;
case OPTYPE_LOG2STR:
+ case OPTYPE_ANY2UNISTR:
u.expr.logargs->generate_code_expr(expr);
break;
case OPTYPE_TTCN2STRING: {
case OPTYPE_VALUEOF: // ti1
return u.expr.ti1->has_single_expr();
case OPTYPE_LOG2STR:
+ case OPTYPE_ANY2UNISTR:
return u.expr.logargs->has_single_expr();
case OPTYPE_MATCH: // v1 t2
return u.expr.v1->has_single_expr() &&
%token decode_base64KeyWord
%token encvalue_unicharKeyWord
%token decvalue_unicharKeyWord
+%token any2unistrKeyWord
/* Multi-character operators */
$$ = new Value(Value::OPTYPE_LOG2STR, new LogArguments());
$$->set_location(infile, @$);
}
+| any2unistrKeyWord '(' LogItemList optError ')'
+ {
+ if ($3->get_nof_logargs() != 1) {
+ Location loc(infile, @1);
+ loc.error("The any2unistr function takes exactly one argument, not %lu.",
+ $3->get_nof_logargs());
+ delete $3;
+ $$ = new Value(Value::OPTYPE_ANY2UNISTR, new LogArguments());
+ $$->set_location(infile, @$);
+ } else {
+ $$ = new Value(Value::OPTYPE_ANY2UNISTR, $3);
+ $$->set_location(infile, @$);
+ }
+ }
| testcasenameKeyword '(' ')'
{
$$ = new Value(Value::OPTYPE_TESTCASENAME);
--- /dev/null
+/******************************************************************************
+ * Copyright (c) 2000-2016 Ericsson Telecom AB
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Szabo, Bence Janos – initial implementation
+ *
+ ******************************************************************************/
+module Any2Unistr
+{
+
+ type component EmptyCT {}
+
+ testcase tc_any2unistr() runs on EmptyCT {
+ var integer v_int1 := 5, v_int2;
+ var template integer vmw_int1 := ?;
+ var template integer vmw_int2 := -1 ifpresent;
+ var universal charstring v_chr1, v_chr2, v_chr3, v_chr4;
+ v_chr1 := any2unistr(v_int1); // after the assignment v_chr1 will be "5"
+ v_chr2 := any2unistr(v_int2); // after the assignment v_chr2 will be "<unbound>"
+ v_chr3 := any2unistr(vmw_int1); // after the assignment v_chr3 will be "?"
+ v_chr4 := any2unistr(vmw_int2); // after the assignment v_chr3 will be "-1 ifpresent"
+
+ var universal charstring v_chr1_exp, v_chr2_exp, v_chr3_exp, v_chr4_exp;
+ v_chr1_exp := "5";
+ v_chr2_exp := "<unbound>";
+ v_chr3_exp := "?";
+ v_chr4_exp := "-1 ifpresent";
+
+ if(match(v_chr1,v_chr1_exp) and match(v_chr2,v_chr2_exp) and
+ match(v_chr3,v_chr3_exp) and match(v_chr4,v_chr4_exp)) {
+ setverdict(pass);
+ } else {
+ setverdict(fail);
+ }
+ }
+
+ control
+ {
+ execute(tc_any2unistr());
+ }
+}