GitLab will be shut down on June 25 to move to a new facility. https://www.eclipsestatus.io/incidents/5ffy27gwcbx7

Commit 306edf68 authored by Adam Knapp's avatar Adam Knapp Committed by Gerrit Code Review
Browse files

Merge "Implemented multiplication of macros in the configuration file (bug 570921)"

parents dbc5ce69 407aea64
......@@ -288,6 +288,9 @@ MACRO_REFERENCE_INT \$"{"{WS}{TTCN3IDENTIFIER}{WS}(","{WS}integer{WS})?"}"
BEGIN(SC_define_structured);
return LCurly;
}
"*" { return MultiplyOp; }
} /* SC_define */
<SC_define_structured>
......
......@@ -59,10 +59,15 @@ static char* decode_secret_message(char* encoded);
char* str_val;
int last_literal;
} macro_val; /* 0 or 1 */
struct {
char* str;
double num;
} multiplication;
}
%token <str_val> FillerStuff "whitespace, newline or comment"
%token AssignmentChar ":= or ="
%token MultiplyOp "*"
%token LCurly "{"
%token RCurly "}"
%token <str_val> FString "sequence of characters"
......@@ -78,6 +83,7 @@ static char* decode_secret_message(char* encoded);
%type <str_val> StructuredValue
%type <str_val> StructuredValueList
%type <str_val> MacroRhs
%type <multiplication> Multiplication
%destructor { Free($$); }
FillerStuff
......@@ -97,6 +103,9 @@ MacroRhs
MacroAssignmentValueList
MacroAssignmentValue
%destructor { Free($$.str); }
Multiplication
%%
DefineSections:
......@@ -124,6 +133,10 @@ MacroRhs:
StructuredDefinition {
$$ = $1;
}
|
Multiplication {
$$ = $1.str;
}
;
StructuredDefinition:
......@@ -250,6 +263,38 @@ FillerStuffConcat:
}
;
Multiplication:
MacroAssignmentValue MultiplyOp MacroAssignmentValue {
char* ptr = NULL;
double num1 = strtod($1.str_val, &ptr);
if (ptr == NULL || *ptr != '\0') {
preproc_error_flag = 1;
config_preproc_error("First operand of multiplication is not a number: %s", $1.str_val);
}
double num2 = strtod($3.str_val, &ptr);
if (ptr == NULL || *ptr != '\0') {
preproc_error_flag = 1;
config_preproc_error("Second operand of multiplication is not a number: %s", $3.str_val);
}
Free($1.str_val);
Free($3.str_val);
$$.num = num1 * num2;
$$.str = mprintf("%lf", $$.num);
}
| Multiplication MultiplyOp MacroAssignmentValue {
char* ptr = NULL;
double num2 = strtod($3.str_val, &ptr);
if (ptr == NULL || *ptr != '\0') {
preproc_error_flag = 1;
config_preproc_error("Second operand of multiplication is not a number: %s", $3.str_val);
}
Free($1.str);
Free($3.str_val);
$$.num = $1.num * num2;
$$.str = mprintf("%lf", $$.num);
}
;
%%
/* BISON error reporting function */
......
......@@ -15,7 +15,7 @@ include $(TOPDIR)/Makefile.regression
unexport ABS_SRC
unexport SRCDIR
DIRS := macro_reference structured
DIRS := macro_reference structured expressions
# List of fake targets:
.PHONY: all dep clean run $(DIRS) $(addsuffix /, $(DIRS)) profile
......
##############################################################################
# Copyright (c) 2000-2021 Ericsson Telecom AB
# 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:
# Baranyi, Botond
#
##############################################################################
TOPDIR := ../../../
include $(TOPDIR)/Makefile.regression
MAKE_PROG := $(MAKE)
TTCN_FILE := expressions.ttcn
CFG := expressions.cfg
FILES := $(TTCN_FILE) $(CFG)
RUNNABLE := $(TTCN_FILE:.ttcn=)
DIR_SINGLE := dir_single_mode
DIR_PARALLEL := dir_parallel_mode
GENERATED_DIRS := $(DIR_SINGLE) $(DIR_PARALLEL)
COVERAGE_FLAG :=
ifeq ($(COVERAGE), yes)
COVERAGE_FLAG += -C
endif
ifdef DYN
ifeq ($(PLATFORM), WIN32)
export PATH:=$(PATH):$(TTCN3_DIR)/lib:$(ABS_SRC)/$(DIR_SINGLE):$(ABS_SRC)/$(DIR_PARALLEL):
else
export LD_LIBRARY_PATH:=$(LD_LIBRARY_PATH):$(ABS_SRC)/$(DIR_SINGLE):$(ABS_SRC)/$(DIR_PARALLEL):
endif
endif
# List of fake targets:
.PHONY: all clean run run_single run_parallel runall
all: $(GENERATED_DIRS)
$(DIR_SINGLE):
mkdir $@
cd $@ && for file in $(FILES); do ln -s ../$$file || exit; done
cd $@ && $(TTCN3_DIR)/bin/ttcn3_makefilegen $(COVERAGE_FLAG) $(SPLIT_FLAG) $(RT2_FLAG) -s ./* && $(MAKE_PROG) 'CXXFLAGS=$(CXXFLAGS)' 'LDFLAGS=$(LDFLAGS)'
$(DIR_PARALLEL):
mkdir $@
cd $@ && for file in $(FILES); do ln -s ../$$file || exit; done
cd $@ && $(TTCN3_DIR)/bin/ttcn3_makefilegen $(COVERAGE_FLAG) $(SPLIT_FLAG) $(RT2_FLAG) ./* && $(MAKE_PROG) 'CXXFLAGS=$(CXXFLAGS)' 'LDFLAGS=$(LDFLAGS)'
run: $(GENERATED_DIRS)
cd $(DIR_SINGLE) && ./$(RUNNABLE) $(CFG)
cd $(DIR_PARALLEL) && $(TTCN3_DIR)/bin/ttcn3_start $(RUNNABLE) $(CFG)
# To run all tests, possibly in parallel
run_single: $(DIR_SINGLE)
cd $(DIR_SINGLE) && ./$(RUNNABLE) $(CFG)
run_parallel: $(DIR_PARALLEL)
cd $(DIR_PARALLEL) && $(TTCN3_DIR)/bin/ttcn3_start $(RUNNABLE) $(CFG)
runall: run_single run_parallel
clean distclean:
rm -rf $(GENERATED_DIRS)
###############################################################################
# Copyright (c) 2000-2021 Ericsson Telecom AB
# 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:
# Baranyi, Botond
#
###############################################################################
[DEFINE]
DEF_1 := 10.0
DEF_2 :=
2.0
DEF_3 := 1.5
MUL_1 := ${DEF_1}*${DEF_2}
MUL_2 := ${DEF_1}*${DEF_2}*${DEF_3}
MUL_3 := ${DEF_1}*3*${DEF_2}*${DEF_3}
MUL_4 := ${DEF_1}*-1.0e2*${DEF_2}*${DEF_3}
[MODULE_PARAMETERS]
mul1 := ${MUL_1, float}
mul2 := ${MUL_2, float}
mul3 := ${MUL_3, float}
mul4 := ${MUL_4, float}
[EXECUTE]
expressions.control
/******************************************************************************
* Copyright (c) 2000-2021 Ericsson Telecom AB
* 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:
* Baranyi, Botond
*
******************************************************************************/
module expressions {
modulepar float mul1;
modulepar float mul2;
modulepar float mul3;
modulepar float mul4;
type component CT {}
testcase tc_multiply() runs on CT {
if (mul1 != 20.0) {
setverdict(fail, "mul1: ", mul1);
}
if (mul2 != 30.0) {
setverdict(fail, "mul2: ", mul1);
}
if (mul3 != 90.0) {
setverdict(fail, "mul3: ", mul1);
}
if (mul4 != -3000.0) {
setverdict(fail, "mul4: ", mul1);
}
setverdict(pass);
}
control {
execute(tc_multiply());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment