diff --git a/compiler2/ttcn3/AST_ttcn3.cc b/compiler2/ttcn3/AST_ttcn3.cc index b6ca82993c060a892b82a9bd67a96a9065d8a87f..7b81b1b4f3dcd9bc5c4d5e4a8b73f933c22f0e94 100644 --- a/compiler2/ttcn3/AST_ttcn3.cc +++ b/compiler2/ttcn3/AST_ttcn3.cc @@ -6290,7 +6290,7 @@ namespace Ttcn { // ===== Def_Function // ================================= - Def_Function::Def_Function(Identifier *p_id, FormalParList *p_fpl, + Def_Function::Def_Function(bool p_deterministic, Identifier *p_id, FormalParList *p_fpl, Reference *p_runs_on_ref, Reference *p_mtc_ref, Reference *p_system_ref, Reference *p_port_ref, Type *p_return_type, @@ -6303,7 +6303,7 @@ namespace Ttcn { mtc_ref(p_mtc_ref), mtc_type(0), system_ref(p_system_ref), system_type(0), port_ref(p_port_ref), port_type(0), block(p_block), - is_startable(false), transparent(false) + is_startable(false), transparent(false), deterministic(p_deterministic) { if (!p_block) FATAL_ERROR("Def_Function::Def_Function()"); block->set_my_def(this); @@ -6390,6 +6390,11 @@ namespace Ttcn { checked = true; Error_Context cntxt(this, "In function definition `%s'", id->get_dispname().c_str()); + if (deterministic) { + note("Please ensure that the `%s' function complies with the requirements" + " in clause 16.1.4 of the TTCN-3 core language standard (ES 201 873-1)", + id->get_dispname().c_str()); + } // `runs on' clause and `port' clause are mutually exclusive if (runs_on_ref && port_ref) { runs_on_ref->error("A `runs on' and a `port' clause cannot be present at the same time."); @@ -6744,6 +6749,7 @@ namespace Ttcn { return_type->dump(level + 2); if (asstype == A_FUNCTION_RTEMP) DEBUG(level + 1, "Returns template"); } + DEBUG(level + 1, "Deterministic: %s", deterministic ? "true" : "false"); if (prototype != PROTOTYPE_NONE) DEBUG(level + 1, "Prototype: %s", get_prototype_name()); //DEBUG(level + 1, "Statement block:"); @@ -7044,6 +7050,12 @@ namespace Ttcn { default: FATAL_ERROR("Def_ExtFunction::chk()"); } + if (deterministic) { + note("Please ensure that the `%s' external function complies with the" + " requirements in clause 16.1.4 of the TTCN-3 core language" + " standard (ES 201 873-1)", + id->get_dispname().c_str()); + } } void Def_ExtFunction::chk_allowed_encode() @@ -7524,6 +7536,7 @@ namespace Ttcn { return_type->dump(level + 2); if(asstype == A_EXT_FUNCTION_RTEMP) DEBUG(level + 1, "Returns template"); } + DEBUG(level + 1, "Deterministic: %s", deterministic ? "true" : "false"); if (prototype != PROTOTYPE_NONE) DEBUG(level + 1, "Prototype: %s", get_prototype_name()); if (function_type != EXTFUNC_MANUAL) { diff --git a/compiler2/ttcn3/AST_ttcn3.hh b/compiler2/ttcn3/AST_ttcn3.hh index d3c2151b4933994ce6cec2ad749df91a852a6c63..4ef74952eda36369957726d8136b54c118650cdd 100644 --- a/compiler2/ttcn3/AST_ttcn3.hh +++ b/compiler2/ttcn3/AST_ttcn3.hh @@ -1434,6 +1434,7 @@ namespace Ttcn { bool is_startable; /** Opts out from location information */ bool transparent; + bool deterministic; NameBridgingScope bridgeScope; @@ -1446,6 +1447,7 @@ namespace Ttcn { * * Called from a single location in compiler.y * + * @param p_deterministic true if deterministic * @param p_id function name * @param p_fpl formal parameter list * @param p_runs_on_ref "runs on", else NULL @@ -1457,7 +1459,7 @@ namespace Ttcn { * @param p_template_restriction restriction type * @param p_block the body of the function */ - Def_Function(Identifier *p_id, FormalParList *p_fpl, + Def_Function(bool p_deterministic, Identifier *p_id, FormalParList *p_fpl, Reference *p_runs_on_ref, Reference *p_mtc_ref, Reference *p_system_ref, Reference *p_port_ref, Type *p_return_type, @@ -1539,6 +1541,7 @@ namespace Ttcn { Ttcn::ErrorBehaviorList *eb_list; // pretty or compact printing for json or xml Ttcn::PrintingType *printing; + bool deterministic; /// Copy constructor disabled Def_ExtFunction(const Def_ExtFunction& p); /// %Assignment disabled @@ -1548,19 +1551,21 @@ namespace Ttcn { * * Called from a single location in compiler.y * + * @param p_deterministic true if deterministic function * @param p_id the name * @param p_fpl formal parameters * @param p_return_type the return type * @param returns_template true if it returns a template * @param p_template_restriction restriction type */ - Def_ExtFunction(Identifier *p_id, FormalParList *p_fpl, + Def_ExtFunction(bool p_deterministic, Identifier *p_id, FormalParList *p_fpl, Type *p_return_type, bool returns_template, template_restriction_t p_template_restriction) : Def_Function_Base(true, p_id, p_fpl, p_return_type, returns_template, p_template_restriction), function_type(EXTFUNC_MANUAL), encoding_type(Type::CT_UNDEF), - encoding_options(0), eb_list(0), printing(0) { } + encoding_options(0), eb_list(0), printing(0), + deterministic(p_deterministic) { } ~Def_ExtFunction(); virtual Def_ExtFunction *clone() const; virtual void set_fullname(const string& p_fullname); diff --git a/compiler2/ttcn3/compiler.y b/compiler2/ttcn3/compiler.y index 675618d476df46927d5b474ae9911bdea39acefd..7265dc3541f9b7aa2589f0bb935d30378bcec810 100644 --- a/compiler2/ttcn3/compiler.y +++ b/compiler2/ttcn3/compiler.y @@ -923,7 +923,7 @@ static const string anyname("anytype"); *********************************************************************/ %type <bool_val> optAliveKeyword optOptionalKeyword optOverrideKeyword - optErrValueRaw optAllKeyword + optErrValueRaw optAllKeyword optDeterministicModifier %type <str> FreeText optLanguageSpec PatternChunk PatternChunkList %type <uchar_val> Group Plane Row Cell %type <id> FieldIdentifier FieldReference GlobalModuleId @@ -4196,15 +4196,15 @@ FunctionDef: // 164 optRunsOnSpec AltOrTcConfigSpec optPortSpec optReturnType optError StatementBlock { $5->set_location(infile, @4, @6); - $$ = new Def_Function($3, $5, $7, $8.mtcref, $8.systemref, $9, $10.type, $10.returns_template, + $$ = new Def_Function($2, $3, $5, $7, $8.mtcref, $8.systemref, $9, $10.type, $10.returns_template, $10.template_restriction, $12); $$->set_location(infile, @$); } ; optDeterministicModifier: - /* empty */ -| DeterministicKeyword /* just ignore it for now */ + /* empty */ { $$ = false; } +| DeterministicKeyword { $$ = true; } ; optFunctionFormalParList: // [167] @@ -5311,7 +5311,7 @@ ExtFunctionDef: // 276 '(' optFunctionFormalParList ')' optReturnType { $6->set_location(infile, @5, @7); - $$ = new Def_ExtFunction($4, $6, $8.type, $8.returns_template, + $$ = new Def_ExtFunction($3, $4, $6, $8.type, $8.returns_template, $8.template_restriction); $$->set_location(infile, @$); } diff --git a/function_test/Semantic_Analyser/Makefile.semantic b/function_test/Semantic_Analyser/Makefile.semantic index 99999127354ddaaeda8dfa8e18109b4f992b4e61..9d22c6583214b6f9afda94a9b586f186561bfb78 100644 --- a/function_test/Semantic_Analyser/Makefile.semantic +++ b/function_test/Semantic_Analyser/Makefile.semantic @@ -13,7 +13,7 @@ # ############################################################################## SADIRS := ver param template any_from pattern_ref float recof_index \ -port_translation mtc_and_system_clause port_map_connect +port_translation mtc_and_system_clause port_map_connect deterministic ifdef RT2 SADIRS += deprecated erroneous_attributes template_concat endif diff --git a/function_test/Semantic_Analyser/deterministic/.gitignore b/function_test/Semantic_Analyser/deterministic/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2d293255e6d2f314e34950e486a48630d873491 --- /dev/null +++ b/function_test/Semantic_Analyser/deterministic/.gitignore @@ -0,0 +1,2 @@ +!Makefile +!*.ttcn diff --git a/function_test/Semantic_Analyser/deterministic/Deterministic_OK.ttcn b/function_test/Semantic_Analyser/deterministic/Deterministic_OK.ttcn new file mode 100644 index 0000000000000000000000000000000000000000..6e262a715d8ded658d10212cf3514e22b95a4eef --- /dev/null +++ b/function_test/Semantic_Analyser/deterministic/Deterministic_OK.ttcn @@ -0,0 +1,25 @@ +/****************************************************************************** + * Copyright (c) 2000-2017 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 + * + ******************************************************************************/ + +module DeprecatedCompat_SE { //^In TTCN-3 module// + +function @deterministic f1() return integer { //In function definition// //Please ensure that the \`f1\' function complies with the requirements in clause// + return 1; +} + +function @deterministic f2(in integer x, out integer y) { //In function definition// //Please ensure that the \`f2\' function complies with the requirements in clause// + y := x + f1(); +} + +external function @deterministic ef(in integer x) return integer; //In external function definition// //Please ensure that the \`ef\' external function complies with the requirements in clause// + +} diff --git a/function_test/Semantic_Analyser/deterministic/Makefile b/function_test/Semantic_Analyser/deterministic/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..a05e33236190caf542f24aadd00fa95490feb7d2 --- /dev/null +++ b/function_test/Semantic_Analyser/deterministic/Makefile @@ -0,0 +1,12 @@ +############################################################################## +# Copyright (c) 2000-2017 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 +# +############################################################################## +include ../common.mk diff --git a/function_test/Semantic_Analyser/deterministic/t b/function_test/Semantic_Analyser/deterministic/t new file mode 100755 index 0000000000000000000000000000000000000000..3a4b58ec16cf2f1390a36c7a92f8823e3b94b425 --- /dev/null +++ b/function_test/Semantic_Analyser/deterministic/t @@ -0,0 +1,9 @@ +#!/usr/bin/perl +# note this is called through "perl -w" +use strict; + +my $self = $0; +$self =~ s!/t!!; + +exec('make check --no-print-directory -s -C ' . $self); + diff --git a/regression_test/compileonly/deterministic/M.ttcn b/regression_test/compileonly/deterministic/M.ttcn index 38040e53ced5cf072736434a7bfaa9dea725be8f..2ec4888f4f4ed71cd3d8d8ca2a611c46de7edda2 100644 --- a/regression_test/compileonly/deterministic/M.ttcn +++ b/regression_test/compileonly/deterministic/M.ttcn @@ -7,11 +7,11 @@ * * Contributors: * Baranyi, Botond + * Szabo, Bence Janos * ******************************************************************************/ // Tests for the '@deterministic' modifier for functions -// (which is currently ignored by the compiler, but must not cause errors) module M { function @deterministic f1() return integer {