From 61040752b20704addeae0d434f67f977882abcaf Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Tue, 1 Sep 2020 21:40:55 +0200 Subject: some more work on parameter checking --- ecomp-c/ec.c | 52 +++++++++++++++++++--------------------------------- ecomp-c/test1.e | 4 ++-- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/ecomp-c/ec.c b/ecomp-c/ec.c index 8a2fd4a..2e5b288 100644 --- a/ecomp-c/ec.c +++ b/ecomp-c/ec.c @@ -1592,43 +1592,22 @@ static void parseWhileStatement( Scope *scope ) static void parseParameterList( Scope *scope, ExpressionNodeList *list ) { ExpressionNode *node; -/* -function insertBeginning(List list, Node newNode) - if list.firstNode == null - list.firstNode := newNode - list.lastNode := newNode - newNode.prev := null - newNode.next := null - else - newNode.next := list.firstNode - if list.firstNode.prev == null - newNode.prev := null -- (not always necessary) - list.firstNode := newNode - else - newNode.prev := list.firstNode.prev - list.firstNode.prev.next := newNode - list.firstNode.prev := newNode - -*/ Expect( S_lparen ); list->head = NULL; list->tail = NULL; do { node = parseExpression( scope ); - if( list->head == NULL && list->tail == NULL ) { - list->head = node; + + if( list->head == NULL ) { list->tail = node; } else { - node->next = list->head; - if( list->head->prev == NULL ) { - list->head = node; - } else { - node->prev = list->head->prev; - list->head->prev->next = node; - } list->head->prev = node; - } + } + + node->next = list->head; + list->head = node; + if( sym == S_comma ) { sym = getSym( ); } @@ -1671,14 +1650,14 @@ static void parseProcedureCall( Scope *scope ) /* check types */ if( nof_expected_params > 0 ) { - node = list.tail; + node = list.head; param = symbol->param; while( param != NULL ) { if( !is_compatible_type( node->actual_type, param->type ) ) { Abort( "Incompatible parameter type for parameter '%s' in procedure '%s', expecting type '%s', got '%s'", param->name, symbol->name, param->type->name, node->actual_type->name ); } - node = node->prev; + node = node->next; param = param->next; } } @@ -2217,7 +2196,7 @@ static void parseProcedureDeclaration( Scope *scope ) size_params = 0; } else if( sym == S_lparen ) { - Symbol *param, *copy, *defparam; + Symbol *param, *defparam; int offset; parseParameterDeclarationList( symbol->scope ); @@ -2272,13 +2251,20 @@ static void parseProcedureDeclaration( Scope *scope ) * of the definition of the procedure and not the one of the forward * declaration */ if( symbol->param == NULL ) { + Symbol *copy, *last = NULL; param = symbol->scope->symbol; while( param != NULL ) { if( param->class == SYMBOL_CLASS_VARIABLE ) { copy = copy_symbol( param ); + copy->next = NULL; copy->scope = NULL; - copy->next = symbol->param; - symbol->param = copy; + if( last == NULL ) { + symbol->param = copy; + last = symbol->param; + } else { + last->next = copy; + last = copy; + } } param = param->next; } diff --git a/ecomp-c/test1.e b/ecomp-c/test1.e index 907e595..23fdaad 100644 --- a/ecomp-c/test1.e +++ b/ecomp-c/test1.e @@ -52,10 +52,10 @@ var x : integer; begin - if( f ) { + if f do x := n + m; a1[4] := x; - } + end end begin -- cgit v1.2.3-54-g00ecf