diff options
author | Mark Spruiell <mes@zeroc.com> | 2003-10-22 00:56:51 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2003-10-22 00:56:51 +0000 |
commit | b88eaeca46e1beb3aa045a228d9c0ed7543ee9e7 (patch) | |
tree | b78d298625d784a172db2f270f355ecb3c68c918 /cpp/src | |
parent | adding line number support (diff) | |
download | ice-b88eaeca46e1beb3aa045a228d9c0ed7543ee9e7.tar.bz2 ice-b88eaeca46e1beb3aa045a228d9c0ed7543ee9e7.tar.xz ice-b88eaeca46e1beb3aa045a228d9c0ed7543ee9e7.zip |
removing bison stuff from Parser.h; adding type() accessor to Enum
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Slice/Grammar.y | 3 | ||||
-rw-r--r-- | cpp/src/Slice/GrammarUtil.h | 30 | ||||
-rw-r--r-- | cpp/src/Slice/Parser.cpp | 28 | ||||
-rw-r--r-- | cpp/src/Slice/Scanner.l | 2 |
4 files changed, 54 insertions, 9 deletions
diff --git a/cpp/src/Slice/Grammar.y b/cpp/src/Slice/Grammar.y index 01266703ecf..d341b47ea44 100644 --- a/cpp/src/Slice/Grammar.y +++ b/cpp/src/Slice/Grammar.y @@ -29,7 +29,7 @@ using namespace std; using namespace Slice; void -yyerror(const char* s) +slice_error(const char* s) { // yacc and recent versions of Bison use "syntax error" instead // of "parse error". @@ -47,6 +47,7 @@ yyerror(const char* s) %} %pure_parser +%name_prefix="slice_" // // All keyword tokens. Make sure to modify the "keyword" rule in this diff --git a/cpp/src/Slice/GrammarUtil.h b/cpp/src/Slice/GrammarUtil.h index ea89bacd7bb..685475b74aa 100644 --- a/cpp/src/Slice/GrammarUtil.h +++ b/cpp/src/Slice/GrammarUtil.h @@ -12,11 +12,10 @@ // // ********************************************************************** -#ifndef SLICE_GRAMMER_UTIL_H -#define SLICE_GRAMMER_UTIL_H +#ifndef SLICE_GRAMMAR_UTIL_H +#define SLICE_GRAMMAR_UTIL_H #include <Slice/Parser.h> -#include <map> namespace Slice { @@ -179,4 +178,29 @@ public: } +// +// Stuff for flex and bison +// + +#define YYSTYPE Slice::GrammarBasePtr +#define YY_DECL int slice_lex(YYSTYPE* yylvalp) +YY_DECL; +int slice_parse(); + +// +// I must set the initial stack depth to the maximum stack depth to +// disable bison stack resizing. The bison stack resizing routines use +// simple malloc/alloc/memcpy calls, which do not work for the +// YYSTYPE, since YYSTYPE is a C++ type, with constructor, destructor, +// assignment operator, etc. +// +#define YYMAXDEPTH 20000 // 20000 should suffice. Bison default is 10000 as maximum. +#define YYINITDEPTH YYMAXDEPTH // Initial depth is set to max depth, for the reasons described above. + +// +// Newer bison versions allow to disable stack resizing by defining +// yyoverflow. +// +#define yyoverflow(a, b, c, d, e, f) yyerror(a) + #endif diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp index 5b99481a082..bc110a0d4f0 100644 --- a/cpp/src/Slice/Parser.cpp +++ b/cpp/src/Slice/Parser.cpp @@ -14,12 +14,13 @@ #include <IceUtil/Functional.h> #include <Slice/Parser.h> +#include <Slice/GrammarUtil.h> using namespace std; using namespace Slice; -extern FILE* yyin; -extern int yydebug; +extern FILE* slice_in; +extern int slice_debug; namespace Slice { @@ -3148,6 +3149,13 @@ Slice::Dictionary::Dictionary(const ContainerPtr& container, const string& name, // Enum // ---------------------------------------------------------------------- +void +Slice::Enum::destroy() +{ + _enumerators.clear(); + SyntaxTreeBase::destroy(); +} + EnumeratorList Slice::Enum::getEnumerators() { @@ -3158,6 +3166,10 @@ void Slice::Enum::setEnumerators(const EnumeratorList& ens) { _enumerators = ens; + for(EnumeratorList::iterator p = _enumerators.begin(); p != _enumerators.end(); ++p) + { + (*p)->_type = this; + } } Contained::ContainedType @@ -3208,6 +3220,12 @@ Slice::Enum::Enum(const ContainerPtr& container, const string& name, bool local) // Enumerator // ---------------------------------------------------------------------- +EnumPtr +Slice::Enumerator::type() const +{ + return _type; +} + Contained::ContainedType Slice::Enumerator::containedType() const { @@ -4315,7 +4333,7 @@ Slice::Unit::includeFiles() const int Slice::Unit::parse(FILE* file, bool debug) { - yydebug = debug ? 1 : 0; + slice_debug = debug ? 1 : 0; assert(!Slice::unit); Slice::unit = this; @@ -4327,8 +4345,8 @@ Slice::Unit::parse(FILE* file, bool debug) _topLevelFile = ""; pushContainer(this); - yyin = file; - int status = yyparse(); + slice_in = file; + int status = slice_parse(); if(_errors) { status = EXIT_FAILURE; diff --git a/cpp/src/Slice/Scanner.l b/cpp/src/Slice/Scanner.l index 2a0be3d8c5f..1c00d815e6e 100644 --- a/cpp/src/Slice/Scanner.l +++ b/cpp/src/Slice/Scanner.l @@ -51,6 +51,8 @@ int checkKeyword(string&); %option noyywrap %option never-interactive +%option prefix="slice_" +%option outfile="lex.yy.c" identifier \\?[[:alpha:]_][[:alnum:]_]* integer_constant (\+|-)?((0[0-7]+)|(0x[[:xdigit:]]+)|([[:digit:]]+)) |