From d0a2a2ac6cf0b3ff0c070a83e72a301704493796 Mon Sep 17 00:00:00 2001 From: Adrian Thurston Date: Tue, 14 Apr 2020 10:16:51 +0000 Subject: correct prodNum as we combine productions to implement [...] refs #112 --- src/declare.cc | 14 +++++++++----- src/pdabuild.cc | 1 + src/pdacodegen.cc | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/declare.cc b/src/declare.cc index bc770c9e..5102746c 100644 --- a/src/declare.cc +++ b/src/declare.cc @@ -253,8 +253,8 @@ void Compiler::declareReVars() LangEl *declareLangEl( Compiler *pd, Namespace *nspace, const String &data, LangEl::Type type ) { - /* If the id is already in the dict, it will be placed in last found. If - * it is not there then it will be inserted and last found will be set to it. */ + /* If the id is already in the dict, it will be placed in last found. If it + * is not there then it will be inserted and last found will be set to it. */ TypeMapEl *inDict = nspace->typeMap.find( data ); if ( inDict != 0 ) error() << "language element '" << data << "' already defined as something else" << endp; @@ -488,10 +488,14 @@ void Namespace::declare( Compiler *pd ) while ( n->prodList->length() > 0 ) { Production *prod = n->prodList->detachFirst(); if ( prod->dotDotDot ) { - prod->prodNum = combined.length(); - combined.append( langEl->prodList ); + while ( langEl->prodList.length() ) { + Production *prod = langEl->prodList.detachFirst(); + prod->prodNum = combined.length(); + combined.append( prod ); + } } else { + prod->prodNum = combined.length(); combined.append( prod ); } } @@ -523,7 +527,7 @@ void Namespace::declare( Compiler *pd ) for ( TypeAliasList::Iter ta = typeAliasList; ta.lte(); ta++ ) declareTypeAlias( pd, this, ta->name, ta->typeRef ); - /* Go into child aliases. */ + /* Go into child namespaces. */ for ( NamespaceVect::Iter c = childNamespaces; c.lte(); c++ ) (*c)->declare( pd ); } diff --git a/src/pdabuild.cc b/src/pdabuild.cc index ae2d4e01..60a23c6b 100644 --- a/src/pdabuild.cc +++ b/src/pdabuild.cc @@ -1455,6 +1455,7 @@ void Compiler::makeRuntimeData() for ( int i = 0; i < nextLelId; i++ ) { LangEl *lel = langElIndex[i]; if ( lel != 0 ) { + assert( lel->id == i ); runtimeData->lel_info[i].name = lel->fullLit; runtimeData->lel_info[i].xml_tag = lel->xmlTag; runtimeData->lel_info[i].repeat = lel->isRepeat; diff --git a/src/pdacodegen.cc b/src/pdacodegen.cc index c96c9afc..44389b6f 100644 --- a/src/pdacodegen.cc +++ b/src/pdacodegen.cc @@ -23,6 +23,7 @@ #include #include +#include #include "compiler.h" #include "pdacodegen.h" @@ -165,7 +166,7 @@ void PdaCodeGen::writeRuntimeData( colm_sections *runtimeData, struct pda_tables out << "static struct lang_el_info " << lelInfo() << "[] = {\n"; for ( int i = 0; i < runtimeData->num_lang_els; i++ ) { struct lang_el_info *el = &runtimeData->lel_info[i]; - out << "\t{"; + out << "/* " << std::setw(4) << i << " */ {"; /* Name. */ out << " \""; -- cgit v1.2.1