Commit df39b4c8 authored by BenceJanosSzabo's avatar BenceJanosSzabo
Browse files

Implemented that 'of' types or array can be indexed with a record of or array...


Implemented that 'of' types or array can be indexed with a record of or array of integer (Bug 511078)

Change-Id: Ia2f37216949b04a333ae7c2e87ce29c3f4a9fdbc
Signed-off-by: default avatarBenceJanosSzabo <bence.janos.szabo@ericsson.com>
parent 6ab91110
......@@ -1703,7 +1703,58 @@ namespace Common {
}
// check the index value
Value *index_value = ref->get_val();
if (t->typetype == T_ARRAY) {
index_value->set_lowerid_to_ref();
// pt is the type with the indexing is made, while t is the type on the
// indexing is applied.
Type* pt = index_value->get_expr_governor_last();
if (pt != NULL &&
// The indexer type is an array or record of
(pt->get_typetype() == T_ARRAY || pt->get_typetype() == T_SEQOF) &&
// The indexed type is a record of or set of or array
(t->get_typetype() == T_SEQOF || t->get_typetype() == T_SETOF || t->get_typetype() == T_ARRAY)) {
// The indexer type must be of type integer
if (pt->get_ofType()->get_type_refd_last()->get_typetype() != T_INT) {
ref->error("Only fixed length array or record of integer types are allowed for short-hand notation for nested indexes.");
return 0;
}
int len = 0;
// Get the length of the array or record of
if (pt->get_typetype() == T_ARRAY) {
len = (int)pt->get_dimension()->get_size();
} else if (pt->get_typetype() == T_SEQOF) {
SubType* sub = pt->get_sub_type();
if (sub == NULL) {
ref->error("The type `%s' must have single size length restriction when used as a short-hand notation for nested indexes.",
pt->get_typename().c_str());
return 0;
}
len = pt->get_sub_type()->get_length_restriction();
if (len == -1) {
ref->error("The type `%s' must have single size length restriction when used as a short-hand notation for nested indexes.",
pt->get_typename().c_str());
return 0;
}
}
embedded_type = embedded_type->get_type_refd_last();
int j = 0;
// Get the len - 1'th inner type
while (j < len - 1) {
switch (embedded_type->get_typetype()) {
case T_SEQOF:
case T_SETOF:
case T_ARRAY:
embedded_type = embedded_type->get_ofType()->get_type_refd_last();
break;
default:
ref->error("The type `%s' contains too many indexes (%i) in the short-hand notation for nested indexes.",
pt->get_typename().c_str(), len);
return 0;
}
j++;
}
} else if (t->typetype == T_ARRAY) {
// checking of array index is performed by the array dimension
t->u.array.dimension->chk_index(index_value, expected_index);
} else {
......
......@@ -369,9 +369,29 @@ namespace Ttcn {
}
} else {
// Generate code for array reference.
expr->expr = mputc(expr->expr, '[');
ref->get_val()->generate_code_expr(expr);
expr->expr = mputc(expr->expr, ']');
Value* v = ref->get_val();
Type * pt = v->get_expr_governor_last();
// If the value is indexed with an array or record of then generate
// the indexes of the array or record of into the code, one by one.
if (pt->get_typetype() == Type::T_ARRAY || pt->get_typetype() == Type::T_SEQOF) {
int len = 0, start = 0;
if (pt->get_typetype() == Type::T_ARRAY) {
len = (int)pt->get_dimension()->get_size();
start = pt->get_dimension()->get_offset();
} else if (pt->get_typetype() == Type::T_SEQOF) {
len = pt->get_sub_type()->get_length_restriction();
}
// Generate the indexes as [x][y]...
for (int j = start; j < start + len; j++) {
expr->expr = mputc(expr->expr, '[');
v->generate_code_expr(expr);
expr->expr = mputprintf(expr->expr, "[%i]]", j);
}
} else {
expr->expr = mputc(expr->expr, '[');
v->generate_code_expr(expr);
expr->expr = mputc(expr->expr, ']');
}
if (type) {
// Follow the embedded type.
switch (type->get_typetype()) {
......
......@@ -12,7 +12,7 @@
# Szabo, Bence Janos
#
##############################################################################
SADIRS := ver xer encode param template any_from pattern_ref float
SADIRS := ver xer encode param template any_from pattern_ref float recof_index
ifeq ($(RT2), yes)
SADIRS += deprecated
endif
......
##############################################################################
# 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:
# Bence Janos Szabo
#
##############################################################################
include ../common.mk
/******************************************************************************
* 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
*
******************************************************************************/
module recof_index_SE { //^In TTCN-3 module//
type record of record of integer RoRoI;
type record length(1..2) of integer RoI1;
type record length(3) of integer RoI2;
type record of integer RoI;
type record length(1) of float RoF1;
function f() { //^In function definition `f'//
var RoRoI v_rec := {{0, 1}, {2, 3}};
var RoI1 v_index := { 1 }
if (v_rec[v_index] == {2, 3}) { //^In if statement:// //error: The type \`@recof_index_SE\.RoI1\' must have single size length restriction when used as a short-hand notation for nested indexes\.//
}
var RoI2 v_index2 := { 1, 2, 3 }
if (v_rec[v_index2] == {2, 3}) { //^In if statement:// //error: The type \`@recof_index_SE.RoI2\' contains too many indexes \(3\) in the short-hand notation for nested indexes\.//
}
var integer v_arr[3] := { 1, 2, 3 }
if (v_rec[v_arr] == {2, 3}) { //^In if statement:// //error: The type \`integer\[3\]\' contains too many indexes \(3\) in the short-hand notation for nested indexes\.//
}
var RoF1 v_index3 := { 1.0 }
if (v_rec[v_index3] == {2, 3}) { //^In if statement:// //error\: Only fixed length array or record of integer types are allowed for short\-hand notation for nested indexes\.//
}
var integer v_arr2[0] := { } //In variable definition \`v_arr2\'\:// //error\: A positive integer value was expected as array size instead of \`0\'//
if (v_rec[v_arr2] == {2, 3}) {
}
var RoI v_index4 := { 1, 1 }
if (v_rec[v_index4] == {2, 3}) { //^In if statement:// //error\: The type \`\@recof_index_SE\.RoI\' must have single size length restriction when used as a short\-hand notation for nested indexes\.//
}
}
}
#!/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);
......@@ -47,7 +47,7 @@ macros visibility hexstrOper ucharstrOper objidOper CRTR00015758 slider \
XML ipv6 implicitOmit testcase_defparam transparent HQ16404 cfgFile \
all_from lazyEval tryCatch text2ttcn json junitlogger ttcn2json profiler templateOmit \
customEncoding makefilegen uidChars checkstate hostid templateIstemplatekind \
selectUnion templateExclusiveRange any_from templatePatternRef
selectUnion templateExclusiveRange any_from templatePatternRef indexWithRecofArray
ifdef DYN
DIRS += loggerplugin
......
This diff is collapsed.
##############################################################################
# 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
#
##############################################################################
TOPDIR := ..
include $(TOPDIR)/Makefile.regression
.SUFFIXES: .ttcn .hh
.PHONY: all clean dep run
TTCN3_LIB = ttcn3$(RT2_SUFFIX)$(DYNAMIC_SUFFIX)
TTCN3_MODULES = IndexWithRecofArray.ttcn
GENERATED_SOURCES = $(TTCN3_MODULES:.ttcn=.cc)
GENERATED_HEADERS = $(GENERATED_SOURCES:.cc=.hh)
ifdef CODE_SPLIT
GENERATED_SOURCES := $(foreach file, $(GENERATED_SOURCES:.cc=), $(addprefix $(file), .cc _seq.cc _set.cc _seqof.cc _setof.cc _union.cc))
else ifdef SPLIT_TO_SLICES
POSTFIXES := $(foreach file, $(SPLIT_TO_SLICES), $(addsuffix $(file), _part_))
POSTFIXES := $(foreach file, $(POSTFIXES), $(addprefix $(file), .cc))
GENERATED_SOURCES2 := $(foreach file, $(GENERATED_SOURCES:.cc=), $(addprefix $(file), $(POSTFIXES)))
GENERATED_SOURCES += $(GENERATED_SOURCES2)
endif
OBJECTS = $(GENERATED_SOURCES:.cc=.o)
TARGET = IndexWithRecofArray$(EXESUFFIX)
all: $(TARGET)
$(TARGET): $(GENERATED_SOURCES) $(USER_SOURCES)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ -L$(TTCN3_DIR)/lib -l$(TTCN3_LIB) -L$(OPENSSL_DIR)/lib -lcrypto $($(PLATFORM)_LIBS)
.ttcn.cc .ttcn.hh:
$(TTCN3_COMPILER) $<
clean distclean:
-rm -f $(TARGET) $(OBJECTS) $(GENERATED_HEADERS) \
$(GENERATED_SOURCES) *.log Makefile.bak
dep: $(GENERATED_SOURCES)
makedepend $(CPPFLAGS) $(GENERATED_SOURCES)
run: $(TARGET)
./$^
.NOTPARALLEL:
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