Skip to content
Snippets Groups Projects
Commit 39f0c4cf authored by Mark OLESEN's avatar Mark OLESEN
Browse files

BUG: flex symbol conflict (issue #494)

parent d27d69e3
No related merge requests found
...@@ -23,9 +23,10 @@ License ...@@ -23,9 +23,10 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
%{ %option prefix="yySTL"
%option yyclass="yySTLFlexLexer"
#undef yyFlexLexer %{
/* ------------------------------------------------------------------------ *\ /* ------------------------------------------------------------------------ *\
------ local definitions ------ local definitions
...@@ -35,9 +36,9 @@ License ...@@ -35,9 +36,9 @@ License
#include "OSspecific.H" #include "OSspecific.H"
using namespace Foam; using namespace Foam;
// Dummy yyFlexLexer::yylex() to keep the linker happy. It is not called // Dummy yyFlexLexer::yylex() to keep the linker happy. It is not called
//! \cond dummy //! \cond dummy
#if YY_FLEX_MAJOR_VERSION <= 2 && YY_FLEX_MINOR_VERSION <= 5 && YY_FLEX_SUBMINOR_VERSION < 34
int yyFlexLexer::yylex() int yyFlexLexer::yylex()
{ {
FatalErrorInFunction FatalErrorInFunction
...@@ -45,29 +46,29 @@ int yyFlexLexer::yylex() ...@@ -45,29 +46,29 @@ int yyFlexLexer::yylex()
<< abort(FatalError); << abort(FatalError);
return 0; return 0;
} }
#endif
//! \endcond //! \endcond
// Dummy yywrap to keep yylex happy at compile time. // Dummy yywrap to keep yylex happy at compile time.
// It is called by yylex but is not used as the mechanism to change file. // It is called by yylex but is not used as the mechanism to change file.
// See <<EOF>> // See <<EOF>>
//! \cond dummy //! \cond dummy
#if YY_FLEX_MINOR_VERSION < 6 && YY_FLEX_SUBMINOR_VERSION < 34 #if YY_FLEX_MAJOR_VERSION <= 2 && YY_FLEX_MINOR_VERSION <= 5 && YY_FLEX_SUBMINOR_VERSION < 34
extern "C" int yywrap() extern "C" int yywrap()
#else #else
int yyFlexLexer::yywrap() int yySTLFlexLexer::yywrap()
#endif #endif
{ {
return 1; return 1;
} }
//! \endcond //! \endcond
//- A lexer for parsing STL ASCII files. //- A lexer for parsing STL ASCII files.
// Returns DynamicList(s) of points and facets (zoneIds). // Returns DynamicList(s) of points and facets (zoneIds).
// The facets are within a solid/endsolid grouping // The facets are within a solid/endsolid grouping
class STLASCIILexer class STLASCIILexer
: :
public yyFlexLexer public yySTLFlexLexer
{ {
// Private data // Private data
...@@ -95,7 +96,7 @@ public: ...@@ -95,7 +96,7 @@ public:
//- The lexer function itself //- The lexer function itself
int lex(); int lex();
// Access // Access
//- Do all the solid groups appear in order? //- Do all the solid groups appear in order?
inline bool sorted() const inline bool sorted() const
...@@ -132,7 +133,7 @@ public: ...@@ -132,7 +133,7 @@ public:
STLASCIILexer::STLASCIILexer(istream* is, const label approxNpoints) STLASCIILexer::STLASCIILexer(istream* is, const label approxNpoints)
: :
yyFlexLexer(is), yySTLFlexLexer(is),
sorted_(true), sorted_(true),
groupID_(-1), groupID_(-1),
lineNo_(1), lineNo_(1),
...@@ -145,6 +146,7 @@ STLASCIILexer::STLASCIILexer(istream* is, const label approxNpoints) ...@@ -145,6 +146,7 @@ STLASCIILexer::STLASCIILexer(istream* is, const label approxNpoints)
------ cppLexer::yylex() ------ cppLexer::yylex()
\* ------------------------------------------------------------------------ */ \* ------------------------------------------------------------------------ */
#undef YY_DECL
#define YY_DECL int STLASCIILexer::lex() #define YY_DECL int STLASCIILexer::lex()
%} %}
...@@ -202,9 +204,9 @@ endsolid {space}("endsolid"|"ENDSOLID")({some_space}{word})* ...@@ -202,9 +204,9 @@ endsolid {space}("endsolid"|"ENDSOLID")({some_space}{word})*
// End of read character pointer returned by strtof // End of read character pointer returned by strtof
// char* endPtr; // char* endPtr;
STLpoint normal; label cmpt = 0; // Component index when reading vertex
STLpoint vertex; STLpoint vertex;
label cmpt = 0; // component index used for reading vertex // STLpoint normal;
static const char* stateNames[7] = static const char* stateNames[7] =
{ {
...@@ -237,154 +239,167 @@ endsolid {space}("endsolid"|"ENDSOLID")({some_space}{word})* ...@@ -237,154 +239,167 @@ endsolid {space}("endsolid"|"ENDSOLID")({some_space}{word})*
/* ------ Reading control header ------ */ /* ------ Reading control header ------ */
{solid} { {solid} {
BEGIN(readSolidName); BEGIN(readSolidName);
} }
<readSolidName>{string} { <readSolidName>{string} {
word name(Foam::string::validate<word>(YYText())); const word solidName(Foam::string::validate<word>(YYText()));
HashTable<label>::const_iterator fnd = lookup_.find(name); auto iter = lookup_.cfind(solidName);
if (fnd != lookup_.end()) if (iter.found())
{
if (groupID_ != iter.object())
{ {
if (groupID_ != fnd()) sorted_ = false; // Group appeared out of order
{ groupID_ = iter.object();
// group appeared out of order
sorted_ = false;
}
groupID_ = fnd();
} }
else }
else
{
groupID_ = sizes_.size();
if (lookup_.insert(solidName, groupID_))
{ {
groupID_ = sizes_.size(); names_.append(solidName);
lookup_.insert(name, groupID_);
names_.append(name);
sizes_.append(0); sizes_.append(0);
} }
BEGIN(INITIAL); else
{
FatalErrorInFunction<< "Duplicate solid-name: " << solidName
<< exit(FatalError);
}
} }
BEGIN(INITIAL);
}
<readSolidName>{space}\n { <readSolidName>{space}\n {
word name("solid"); const word solidName("solid"); // Could also use solid0, solid1, ...
HashTable<label>::const_iterator fnd = lookup_.find(name); auto iter = lookup_.cfind(solidName);
if (fnd != lookup_.end()) if (iter.found())
{
if (groupID_ != iter.object())
{ {
if (groupID_ != fnd()) sorted_ = false; // Group appeared out of order
{ groupID_ = iter.object();
// group appeared out of order
sorted_ = false;
}
groupID_ = fnd();
} }
else }
else
{
groupID_ = sizes_.size();
if (lookup_.insert(solidName, groupID_))
{ {
groupID_ = sizes_.size(); names_.append(solidName);
lookup_.insert(name, groupID_);
names_.append(name);
sizes_.append(0); sizes_.append(0);
} }
else
lineNo_++; {
BEGIN(INITIAL); FatalErrorInFunction<< "Duplicate solid-name: " << solidName
<< exit(FatalError);
}
} }
++lineNo_;
BEGIN(INITIAL);
}
{color} { {color} {
} /* ignore 'color' */
}
{facet} { {facet} {
BEGIN(readFacet); BEGIN(readFacet);
} }
<readFacet>{normal} { <readFacet>{normal} {
BEGIN(readNormal); BEGIN(readNormal);
} }
<readNormal>{point} { <readNormal>{point} {
/* /*
skip reading normals: skip reading normals:
normal.x() = strtof(YYText(), &endPtr); normal.x() = strtof(YYText(), &endPtr);
normal.y() = strtof(endPtr, &endPtr); normal.y() = strtof(endPtr, &endPtr);
normal.z() = strtof(endPtr, &endPtr); normal.z() = strtof(endPtr, &endPtr);
normals_.append(normal); normals_.append(normal);
*/ */
BEGIN(readFacet); BEGIN(readFacet);
} }
<readFacet>{outerloop} { <readFacet>{outerloop} {
BEGIN(readVertices); BEGIN(readVertices);
} }
<readVertices>{vertex} { <readVertices>{vertex} {
BEGIN(readVertex); BEGIN(readVertex);
} }
<readVertex>{space}{signedInteger}{space} { <readVertex>{space}{signedInteger}{space} {
vertex[cmpt++] = atol(YYText()); vertex[cmpt++] = atol(YYText());
if (cmpt == 3) if (cmpt == 3)
{ {
cmpt = 0; cmpt = 0;
points_.append(vertex); points_.append(vertex);
BEGIN(readVertices); BEGIN(readVertices);
}
} }
}
<readVertex>{space}{floatNum}{space} { <readVertex>{space}{floatNum}{space} {
vertex[cmpt++] = atof(YYText()); vertex[cmpt++] = atof(YYText());
if (cmpt == 3) if (cmpt == 3)
{ {
cmpt = 0; cmpt = 0;
points_.append(vertex); points_.append(vertex);
BEGIN(readVertices); BEGIN(readVertices);
}
} }
}
<readVertices>{endloop} { <readVertices>{endloop} {
BEGIN(readFacet); BEGIN(readFacet);
} }
<readFacet>{endfacet} { <readFacet>{endfacet} {
facets_.append(groupID_); facets_.append(groupID_);
sizes_[groupID_]++; sizes_[groupID_]++;
BEGIN(INITIAL); BEGIN(INITIAL);
} }
{endsolid} { {endsolid} {
} }
/* ------------------ Ignore remaining space and \n s. -------------------- */ /* ---------------- Ignore remaining spaces and newlines ------------------ */
<*>{space} {} <*>{space} {}
<*>\n { lineNo_++; } <*>\n { ++lineNo_; }
/* ------------------- Any other characters are errors -------------------- */ /* ------------------- Any other characters are errors -------------------- */
<*>. { <*>. {
startError_ = YYText(); startError_ = YYText();
yy_push_state(stlError); yy_push_state(stlError);
} }
/* ---------------------------- Error handler ----------------------------- */ /* ---------------------------- Error handler ----------------------------- */
<stlError>.* { <stlError>.* {
yy_pop_state(); yy_pop_state();
FatalErrorInFunction FatalErrorInFunction
<< "while " << stateNames[YY_START] << " on line " << lineNo_ << nl << "while " << stateNames[YY_START] << " on line " << lineNo_ << nl
<< " expected " << stateExpects[YY_START] << " expected " << stateExpects[YY_START]
<< " but found '" << startError_.c_str() << YYText() << "'" << " but found '" << startError_.c_str() << YYText() << "'"
<< exit(FatalError); << exit(FatalError);
} }
/* ------------------------ On EOF terminate ---------------------------- */ /* ------------------------ On EOF terminate ---------------------------- */
<<EOF>> { <<EOF>> {
yyterminate(); yyterminate();
} }
%% %%
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment