Skip to content

Commit

Permalink
And fixes for more modern versions of Bison
Browse files Browse the repository at this point in the history
  • Loading branch information
rzulak committed Jan 16, 2019
1 parent e031f80 commit df3f58a
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 39 deletions.
27 changes: 25 additions & 2 deletions src/liboslcomp/oslgram.y
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand All @@ -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 {
%}
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/liboslcomp/osllex.l
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
22 changes: 6 additions & 16 deletions src/liboslcomp/osllexer_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -41,8 +30,9 @@ struct OSLLexer {
OSLCompilerImpl* compiler;
std::stack<TypeSpec> 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);

}
Expand Down
26 changes: 26 additions & 0 deletions src/liboslexec/osogram.y
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string>
#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
Expand All @@ -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 {
%}
Expand Down Expand Up @@ -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)
{
Expand Down
13 changes: 7 additions & 6 deletions src/liboslexec/osolex.l
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ HINTPATTERN \%{IDENT}(\{({IDORLITERAL}(\,{IDORLITERAL})*)?\})?
#include <OpenImageIO/filesystem.h>
#include "osoreader.h"
OSL_NAMESPACE_ENTER
namespace pvt {
struct OSOLexer;
}
OSL_NAMESPACE_EXIT
using namespace OSL;
using namespace OSL::pvt;
Expand All @@ -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)
%}
Expand Down
17 changes: 2 additions & 15 deletions src/liboslexec/osolexer_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
Expand Down

0 comments on commit df3f58a

Please sign in to comment.