diff options
-rw-r--r-- | src/compiler.cc | 37 | ||||
-rw-r--r-- | src/consinit.cc | 4 | ||||
-rw-r--r-- | src/parsetree.h | 13 | ||||
-rw-r--r-- | src/pdarun.c | 2 | ||||
-rw-r--r-- | src/pdarun.h | 2 | ||||
-rw-r--r-- | src/resolve.cc | 12 |
6 files changed, 55 insertions, 15 deletions
diff --git a/src/compiler.cc b/src/compiler.cc index d2588d14..e568de83 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -1145,7 +1145,11 @@ void Compiler::writeCommitStub() " struct pda_run *pda_run, parse_tree_t *pt )\n" "{\n" " commit_clear_parse_tree( prg, root, pda_run, pt->child );\n" - "}\n"; + "}\n" + "\n" + "long commit_union_sz() { return 0; }\n" + "\n"; + ; } void Compiler::writeCommit() @@ -1166,7 +1170,36 @@ void Compiler::writeCommit() "#include <string.h>\n" "#include <assert.h>\n" "\n" - "#include <iostream>\n" + "#include <iostream>\n"; + + for ( ReductionVect::Iter r = rootNamespace->reductions; r.lte(); r++ ) { + for ( ReduceNonTermList::Iter rdi = (*r)->reduceNonTerms; rdi.lte(); rdi++ ) { + *outStream << + "struct lel_" << rdi->nonTerm->uniqueType->langEl->fullName << "\n" + "{" << rdi->txt << "};\n"; + } + } + + *outStream << + "union commit_reduce_union\n" + "{\n"; + + for ( ReductionVect::Iter r = rootNamespace->reductions; r.lte(); r++ ) { + for ( ReduceNonTermList::Iter rdi = (*r)->reduceNonTerms; rdi.lte(); rdi++ ) { + LangEl *langEl = rdi->nonTerm->uniqueType->langEl; + *outStream << + " lel_" << langEl->fullName << " " << langEl->fullName << ";\n"; + } + } + + *outStream << + "};\n" + "\n"; + + *outStream << + "long commit_union_sz() { return sizeof( commit_reduce_union ); }\n"; + + *outStream << "\n" "void commit_forward_recurse( program_t *prg, tree_t **root,\n" " struct pda_run *pda_run, parse_tree_t *pt )\n" diff --git a/src/consinit.cc b/src/consinit.cc index 09ff48cc..7519f8bf 100644 --- a/src/consinit.cc +++ b/src/consinit.cc @@ -1,5 +1,5 @@ /* - * Copyright 2006-2012 Adrian Thurston <thurston@complang.org> + * Copyright 2006-2015 Adrian Thurston <thurston@complang.org> */ /* This file is part of Colm. @@ -42,6 +42,8 @@ extern "C" void commit_forward_recurse( program_t *prg, tree_t **root, commit_clear_parse_tree( prg, root, pda_run, pt->child ); } +extern "C" long commit_union_sz() { return 0; } + using std::cout; using std::cerr; using std::endl; diff --git a/src/parsetree.h b/src/parsetree.h index b4cbcf1f..4e4fa8ac 100644 --- a/src/parsetree.h +++ b/src/parsetree.h @@ -919,15 +919,15 @@ typedef BstSet< Namespace*, CmpOrd<Namespace*> > NamespaceSet; struct ReduceNonTerm { - ReduceNonTerm( const InputLoc &loc, TypeRef *nonterm, const String &txt ) + ReduceNonTerm( const InputLoc &loc, TypeRef *nonTerm, const String &txt ) : loc(loc), - nonterm(nonterm), + nonTerm(nonTerm), txt(txt) {} InputLoc loc; - TypeRef *nonterm; + TypeRef *nonTerm; String txt; ReduceNonTerm *prev, *next; @@ -935,15 +935,16 @@ struct ReduceNonTerm struct ReduceAction { - ReduceAction( const InputLoc &loc, TypeRef *nonterm, + ReduceAction( const InputLoc &loc, TypeRef *nonTerm, const String &prod, const String &txt ) : - loc(loc), nonterm(nonterm), prod(prod), + loc(loc), nonTerm(nonTerm), + prod(prod), txt(txt), production(0) {} InputLoc loc; - TypeRef *nonterm; + TypeRef *nonTerm; String prod; String txt; diff --git a/src/pdarun.c b/src/pdarun.c index 79a403ba..0a1da726 100644 --- a/src/pdarun.c +++ b/src/pdarun.c @@ -1201,7 +1201,7 @@ void colm_pda_init( program_t *prg, struct pda_run *pda_run, struct pda_tables * pda_run->reducer = reducer; if ( reducer ) { - init_pool_alloc( &pda_run->local_pool, sizeof(parse_tree_t) + sizeof(void*) * 8 ); + init_pool_alloc( &pda_run->local_pool, sizeof(parse_tree_t) + commit_union_sz() ); pda_run->parse_tree_pool = &pda_run->local_pool; } diff --git a/src/pdarun.h b/src/pdarun.h index 02cd7e14..ebfd7ea1 100644 --- a/src/pdarun.h +++ b/src/pdarun.h @@ -457,6 +457,8 @@ void commit_forward_recurse( program_t *prg, tree_t **root, void commit_reduce( program_t *prg, tree_t **root, struct pda_run *pda_run ); void commit_clear( program_t *prg, tree_t **root, struct pda_run *pda_run ); +long commit_union_sz(); + #ifdef __cplusplus } diff --git a/src/resolve.cc b/src/resolve.cc index 38c7b169..9dc91abf 100644 --- a/src/resolve.cc +++ b/src/resolve.cc @@ -885,9 +885,11 @@ void Compiler::resolvePrecedence() void Compiler::resolveReductionActions() { for ( ReductionVect::Iter r = rootNamespace->reductions; r.lte(); r++ ) { - for ( ReduceActionList::Iter rai = (*r)->reduceActions; rai.lte(); rai++ ) { - rai->nonterm->resolveType( this ); - } + for ( ReduceNonTermList::Iter rni = (*r)->reduceNonTerms; rni.lte(); rni++ ) + rni->nonTerm->resolveType( this ); + + for ( ReduceActionList::Iter rai = (*r)->reduceActions; rai.lte(); rai++ ) + rai->nonTerm->resolveType( this ); } } @@ -895,8 +897,8 @@ void Compiler::findReductionActionProds() { for ( ReductionVect::Iter r = rootNamespace->reductions; r.lte(); r++ ) { for ( ReduceActionList::Iter rai = (*r)->reduceActions; rai.lte(); rai++ ) { - rai->nonterm->resolveType( this ); - LangEl *langEl = rai->nonterm->uniqueType->langEl; + rai->nonTerm->resolveType( this ); + LangEl *langEl = rai->nonTerm->uniqueType->langEl; Production *prod = 0; for ( LelDefList::Iter ldi = langEl->defList; ldi.lte(); ldi++ ) { |