From df3f58a070e56fbaf8193731d510cb5c122b54fa Mon Sep 17 00:00:00 2001 From: rzulak Date: Wed, 16 Jan 2019 11:03:32 -0800 Subject: [PATCH] And fixes for more modern versions of Bison --- src/liboslcomp/oslgram.y | 27 +++++++++++++++++++++++++-- src/liboslcomp/osllex.l | 6 ++++++ src/liboslcomp/osllexer_pvt.h | 22 ++++++---------------- src/liboslexec/osogram.y | 26 ++++++++++++++++++++++++++ src/liboslexec/osolex.l | 13 +++++++------ src/liboslexec/osolexer_pvt.h | 17 ++--------------- 6 files changed, 72 insertions(+), 39 deletions(-) diff --git a/src/liboslcomp/oslgram.y b/src/liboslcomp/oslgram.y index 9b77986ca..3b7b2e728 100644 --- a/src/liboslcomp/oslgram.y +++ b/src/liboslcomp/oslgram.y @@ -37,7 +37,7 @@ FIXME: Should probably use the more modern version, but bison on OSX %define api.pure full %lex-param { void *scanner } %parse-param { void *scanner } -%param { OSLCompilerImpl *oslcompiler } +%param { OSLLexer *osllexer } */ %pure-parser @@ -49,9 +49,14 @@ FIXME: Should probably use the more modern version, but bison on OSX %{ // C++ declarations - #include "oslcomp_pvt.h" +OSL_NAMESPACE_ENTER +namespace pvt { +struct OSLLexer; +} +OSL_NAMESPACE_EXIT + using namespace OSL; using namespace OSL::pvt; @@ -74,6 +79,7 @@ using namespace OSL::pvt; #include "osllexer_pvt.h" #define oslcompiler osllexer->compiler +// Put as much as possible into the OSL::pvt namespace OSL_NAMESPACE_ENTER namespace pvt { %} @@ -1069,6 +1075,23 @@ string_literal_group %% +// Convert from the lexer's symbolic type (COLORTYPE, etc.) to a TypeDesc. +TypeDesc OSLLexer::type (int lex) +{ + switch (lex) { + case COLORTYPE : return TypeDesc::TypeColor; + case FLOATTYPE : return TypeDesc::TypeFloat; + case INTTYPE : return TypeDesc::TypeInt; + case MATRIXTYPE : return TypeDesc::TypeMatrix; + case NORMALTYPE : return TypeDesc::TypeNormal; + case POINTTYPE : return TypeDesc::TypePoint; + case STRINGTYPE : return TypeDesc::TypeString; + case VECTORTYPE : return TypeDesc::TypeVector; + case VOIDTYPE : return TypeDesc::NONE; + default : return TypeDesc::UNKNOWN; + } +} + void oslerror(YYLTYPE*, void*, OSLLexer* osllexer, const char* msg) { osllexer->error(msg); diff --git a/src/liboslcomp/osllex.l b/src/liboslcomp/osllex.l index 9932732ac..69be4d073 100644 --- a/src/liboslcomp/osllex.l +++ b/src/liboslcomp/osllex.l @@ -114,6 +114,12 @@ CPLUSCOMMENT \/\/.*\n #pragma GCC diagnostic ignored "-Wsign-compare" #endif +OSL_NAMESPACE_ENTER +namespace pvt { +struct OSLLexer; +} +OSL_NAMESPACE_EXIT + using namespace OSL; using namespace OSL::pvt; diff --git a/src/liboslcomp/osllexer_pvt.h b/src/liboslcomp/osllexer_pvt.h index e26931d53..ff97281ca 100644 --- a/src/liboslcomp/osllexer_pvt.h +++ b/src/liboslcomp/osllexer_pvt.h @@ -7,27 +7,16 @@ namespace pvt { struct OSLLexer { // Convert from the lexer's symbolic type (COLORTYPE, etc.) to a TypeDesc. - static inline TypeDesc type (int lex) - { - switch (lex) { - case COLORTYPE : return TypeDesc::TypeColor; - case FLOATTYPE : return TypeDesc::TypeFloat; - case INTTYPE : return TypeDesc::TypeInt; - case MATRIXTYPE : return TypeDesc::TypeMatrix; - case NORMALTYPE : return TypeDesc::TypeNormal; - case POINTTYPE : return TypeDesc::TypePoint; - case STRINGTYPE : return TypeDesc::TypeString; - case VECTORTYPE : return TypeDesc::TypeVector; - case VOIDTYPE : return TypeDesc::NONE; - default: return TypeDesc::UNKNOWN; - } - } + static inline TypeDesc type (int lex); + void function_start() { functions.push(compiler->current_typespec()); } + void function_end() { functions.pop(); } + TypeSpec current_funtion() { assert(!functions.empty() && "No function available"); return functions.top(); @@ -41,8 +30,9 @@ struct OSLLexer { OSLCompilerImpl* compiler; std::stack functions; // just for function_declaration }; -int osllex(YYSTYPE*, YYLTYPE*, void*, OSLLexer*); + int oslparse(void *scanner, OSLLexer *osllexer); +int osllex(YYSTYPE*, YYLTYPE*, void*, OSLLexer*); void oslerror(YYLTYPE*, void*, OSLLexer*, const char* msg); } diff --git a/src/liboslexec/osogram.y b/src/liboslexec/osogram.y index bb74ea7f0..4277d4692 100644 --- a/src/liboslexec/osogram.y +++ b/src/liboslexec/osogram.y @@ -41,6 +41,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include "osoreader.h" +OSL_NAMESPACE_ENTER +namespace pvt { +struct OSOLexer; +} +OSL_NAMESPACE_EXIT + +using namespace OSL; +using namespace OSL::pvt; + #ifdef __clang__ #pragma clang diagnostic ignored "-Wparentheses-equality" #endif @@ -61,6 +70,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define osoreader osolexer->reader +// Put as much as possible into the OSL::pvt namespace OSL_NAMESPACE_ENTER namespace pvt { %} @@ -323,6 +333,22 @@ hint %% +// Convert from the lexer's symbolic type (COLORTYPE, etc.) to a TypeDesc. +TypeDesc OSOLexer::type (int lex) { + switch (lex) { + case COLORTYPE : return TypeDesc::TypeColor; + case FLOATTYPE : return TypeDesc::TypeFloat; + case INTTYPE : return TypeDesc::TypeInt; + case MATRIXTYPE : return TypeDesc::TypeMatrix; + case NORMALTYPE : return TypeDesc::TypeNormal; + case POINTTYPE : return TypeDesc::TypePoint; + case STRINGTYPE : return TypeDesc::TypeString; + case VECTORTYPE : return TypeDesc::TypeVector; + case VOIDTYPE : return TypeDesc::NONE; + default : return TypeDesc::UNKNOWN; + } +} + void osoerror (YYLTYPE*, void*, OSOLexer* osolexer, const char* err) { diff --git a/src/liboslexec/osolex.l b/src/liboslexec/osolex.l index eb77f338f..9522f5889 100644 --- a/src/liboslexec/osolex.l +++ b/src/liboslexec/osolex.l @@ -103,6 +103,13 @@ HINTPATTERN \%{IDENT}(\{({IDORLITERAL}(\,{IDORLITERAL})*)?\})? #include #include "osoreader.h" + +OSL_NAMESPACE_ENTER +namespace pvt { +struct OSOLexer; +} +OSL_NAMESPACE_EXIT + using namespace OSL; using namespace OSL::pvt; @@ -124,12 +131,6 @@ using namespace OSL::pvt; #pragma GCC diagnostic ignored "-Wsign-compare" #endif -OSL_NAMESPACE_ENTER -namespace pvt { - int osolex(YYSTYPE* yylval_param, YYLTYPE* yylloc_param, void* yyscanner, OSOLexer* osolexer); -}; -OSL_NAMESPACE_EXIT - #define YY_DECL int OSL::pvt::osolex(YYSTYPE* yylval_param, YYLTYPE* yylloc_param, void* yyscanner, OSOLexer* osolexer) %} diff --git a/src/liboslexec/osolexer_pvt.h b/src/liboslexec/osolexer_pvt.h index eb504e615..1bac6062b 100644 --- a/src/liboslexec/osolexer_pvt.h +++ b/src/liboslexec/osolexer_pvt.h @@ -8,28 +8,15 @@ namespace pvt { struct OSOLexer { // Convert from the lexer's symbolic type (COLORTYPE, etc.) to a TypeDesc. - static inline TypeDesc type (int lex) { - switch (lex) { - case COLORTYPE : return TypeDesc::TypeColor; - case FLOATTYPE : return TypeDesc::TypeFloat; - case INTTYPE : return TypeDesc::TypeInt; - case MATRIXTYPE : return TypeDesc::TypeMatrix; - case NORMALTYPE : return TypeDesc::TypeNormal; - case POINTTYPE : return TypeDesc::TypePoint; - case STRINGTYPE : return TypeDesc::TypeString; - case VECTORTYPE : return TypeDesc::TypeVector; - case VOIDTYPE : return TypeDesc::NONE; - default: return TypeDesc::UNKNOWN; - } - } + static inline TypeDesc type (int lex); OSOReader* reader; TypeSpec typespec; OIIO::ustring name; }; -int osolex(YYSTYPE*, YYLTYPE*, void*, OSOLexer*); int osoparse(void *scanner, OSOLexer *osolexer); +int osolex(YYSTYPE*, YYLTYPE*, void*, OSOLexer*); void osoerror(YYLTYPE*, void*, OSOLexer*, const char* msg); }