diff options
-rw-r--r-- | cpp/include/Slice/Parser.h | 35 | ||||
-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 |
5 files changed, 59 insertions, 39 deletions
diff --git a/cpp/include/Slice/Parser.h b/cpp/include/Slice/Parser.h index 519ef691921..17a357fee3c 100644 --- a/cpp/include/Slice/Parser.h +++ b/cpp/include/Slice/Parser.h @@ -109,36 +109,6 @@ typedef ::IceUtil::Handle<Enumerator> EnumeratorPtr; typedef ::IceUtil::Handle<Const> ConstPtr; typedef ::IceUtil::Handle<Unit> UnitPtr; -} - -// -// Stuff for flex and bison -// - -#define YYSTYPE Slice::GrammarBasePtr -#define YY_DECL int yylex(YYSTYPE* yylvalp) -YY_DECL; -int yyparse(); - -// -// 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) - -namespace Slice -{ - typedef std::list<TypePtr> TypeList; typedef std::list<ExceptionPtr> ExceptionList; typedef std::set<std::string> StringSet; @@ -708,6 +678,7 @@ class SLICE_API Enum : virtual public Constructed { public: + virtual void destroy(); EnumeratorList getEnumerators(); void setEnumerators(const EnumeratorList&); virtual ContainedType containedType() const; @@ -733,6 +704,7 @@ class SLICE_API Enumerator : virtual public Contained { public: + EnumPtr type() const; virtual bool uses(const ContainedPtr&) const; virtual ContainedType containedType() const; virtual std::string kindOf() const; @@ -741,6 +713,9 @@ protected: Enumerator(const ContainerPtr&, const std::string&); friend class SLICE_API Container; + friend class SLICE_API Enum; + + EnumPtr _type; }; // ---------------------------------------------------------------------- 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:]]+)) |