Skip to content

Commit

Permalink
Minimum flex version 2.6 and a bit of cleanup
Browse files Browse the repository at this point in the history
Fixes #43903
Fixes #43795
  • Loading branch information
m-kuhn committed Jun 24, 2021
1 parent 91ebc53 commit a20c909
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 254 deletions.
21 changes: 2 additions & 19 deletions CMakeLists.txt
Expand Up @@ -311,25 +311,8 @@ if(WITH_CORE)
set (USING_NINJA TRUE)
endif()

#############################################################
# check if lexer and parser are not missing
# http://www.mail-archive.com/cmake@cmake.org/msg02861.html

include(Flex)

FIND_FLEX()

if (NOT FLEX_EXECUTABLE)
message(FATAL_ERROR "Couldn't find Flex")
endif()

include(Bison)

FIND_BISON()

if (NOT BISON_EXECUTABLE)
message(FATAL_ERROR "Couldn't find Bison")
endif()
find_package(FLEX 2.6 REQUIRED)
find_package(BISON REQUIRED)

#############################################################
# search for dependencies
Expand Down
99 changes: 0 additions & 99 deletions cmake/Bison.cmake

This file was deleted.

92 changes: 0 additions & 92 deletions cmake/Flex.cmake

This file was deleted.

11 changes: 8 additions & 3 deletions src/analysis/CMakeLists.txt
@@ -1,9 +1,17 @@
#############################################################
# sources

BISON_TARGET(QgsRasterCalcParser raster/qgsrastercalcparser.yy ${CMAKE_CURRENT_BINARY_DIR}/qgsrastercalcparser.cpp COMPILE_FLAGS "-p raster_")
FLEX_TARGET(QgsRasterCalcLexer raster/qgsrastercalclexer.ll ${CMAKE_CURRENT_BINARY_DIR}/qgsrastercalclexer.cpp)
ADD_FLEX_BISON_DEPENDENCY(QgsRasterCalcLexer QgsRasterCalcParser)

set(QGIS_ANALYSIS_SRCS
qgsanalysis.cpp


${FLEX_QgsRasterCalcLexer_OUTPUTS}
${BISON_QgsRasterCalcParser_OUTPUTS}

georeferencing/qgsgcpgeometrytransformer.cpp
georeferencing/qgsgcptransformer.cpp
georeferencing/qgsleastsquares.cpp
Expand Down Expand Up @@ -408,9 +416,6 @@ if(HAVE_GSL)
include_directories(SYSTEM ${GSL_INCLUDE_DIR})
endif()

ADD_FLEX_FILES_PREFIX(QGIS_ANALYSIS_SRCS raster raster/qgsrastercalclexer.ll)
ADD_BISON_FILES_PREFIX(QGIS_ANALYSIS_SRCS raster raster/qgsrastercalcparser.yy)

if(NOT MSVC)
set_source_files_properties(
${CMAKE_BINARY_DIR}/src/analysis/qgsrastercalcparser.cpp
Expand Down
29 changes: 15 additions & 14 deletions src/analysis/raster/qgsrastercalclexer.ll
Expand Up @@ -20,6 +20,7 @@
%option nounput
%option case-insensitive
%option never-interactive
%option prefix="raster_"

// ensure that lexer will be 8-bit (and not just 7-bit)
%option 8bit
Expand Down Expand Up @@ -53,18 +54,18 @@ raster_band_ref_quoted \"(\\.|[^"])*\"
%%
"sqrt" { rasterlval.op = QgsRasterCalcNode::opSQRT; return FUNCTION;}
"sin" { rasterlval.op = QgsRasterCalcNode::opSIN; return FUNCTION;}
"cos" { rasterlval.op = QgsRasterCalcNode::opCOS; return FUNCTION;}
"tan" { rasterlval.op = QgsRasterCalcNode::opTAN; return FUNCTION;}
"asin" { rasterlval.op = QgsRasterCalcNode::opASIN; return FUNCTION;}
"acos" { rasterlval.op = QgsRasterCalcNode::opACOS; return FUNCTION;}
"atan" { rasterlval.op = QgsRasterCalcNode::opATAN; return FUNCTION;}
"ln" { rasterlval.op = QgsRasterCalcNode::opLOG; return FUNCTION;}
"log10" { rasterlval.op = QgsRasterCalcNode::opLOG10; return FUNCTION;}
"abs" { rasterlval.op = QgsRasterCalcNode::opABS; return FUNCTION;}
"min" { rasterlval.op = QgsRasterCalcNode::opMIN; return FUNCTION_2_ARGS;}
"max" { rasterlval.op = QgsRasterCalcNode::opMAX; return FUNCTION_2_ARGS;}
"sqrt" { raster_lval.op = QgsRasterCalcNode::opSQRT; return FUNCTION;}
"sin" { raster_lval.op = QgsRasterCalcNode::opSIN; return FUNCTION;}
"cos" { raster_lval.op = QgsRasterCalcNode::opCOS; return FUNCTION;}
"tan" { raster_lval.op = QgsRasterCalcNode::opTAN; return FUNCTION;}
"asin" { raster_lval.op = QgsRasterCalcNode::opASIN; return FUNCTION;}
"acos" { raster_lval.op = QgsRasterCalcNode::opACOS; return FUNCTION;}
"atan" { raster_lval.op = QgsRasterCalcNode::opATAN; return FUNCTION;}
"ln" { raster_lval.op = QgsRasterCalcNode::opLOG; return FUNCTION;}
"log10" { raster_lval.op = QgsRasterCalcNode::opLOG10; return FUNCTION;}
"abs" { raster_lval.op = QgsRasterCalcNode::opABS; return FUNCTION;}
"min" { raster_lval.op = QgsRasterCalcNode::opMIN; return FUNCTION_2_ARGS;}
"max" { raster_lval.op = QgsRasterCalcNode::opMAX; return FUNCTION_2_ARGS;}
"AND" { return AND; }
"OR" { return OR; }
Expand All @@ -77,7 +78,7 @@ raster_band_ref_quoted \"(\\.|[^"])*\"
[()] { return yytext[0]; }
{number} { rasterlval.number = atof(rastertext); return NUMBER; }
{number} { raster_lval.number = atof(raster_text); return NUMBER; }
{raster_band_ref} { return RASTER_BAND_REF; }
Expand All @@ -92,5 +93,5 @@ raster_band_ref_quoted \"(\\.|[^"])*\"
void set_raster_input_buffer(const char* buffer)
{
raster_scan_string(buffer);
raster__scan_string(buffer);
}
10 changes: 5 additions & 5 deletions src/analysis/raster/qgsrastercalcparser.yy
Expand Up @@ -30,15 +30,15 @@
QgsRasterCalcNode* parseRasterCalcString(const QString& str, QString& parserErrorMsg);

//! from lex.yy.c
extern int rasterlex();
extern char* rastertext;
extern int raster_lex();
extern char* raster_text;
extern void set_raster_input_buffer(const char* buffer);

//! variable where the parser error will be stored
QString rParserErrorMsg;

//! sets gParserErrorMsg
void rastererror(const char* msg);
void raster_error(const char* msg);

//! temporary list for nodes without parent (if parsing fails these nodes are removed)
QList<QgsRasterCalcNode*> gTmpNodes;
Expand Down Expand Up @@ -98,7 +98,7 @@ raster_exp:
| '+' raster_exp %prec UMINUS { $$ = $2; }
| '-' raster_exp %prec UMINUS { $$ = new QgsRasterCalcNode( QgsRasterCalcNode::opSIGN, $2, 0 ); joinTmpNodes($$, $2, 0); }
| NUMBER { $$ = new QgsRasterCalcNode($1); addToTmpNodes($$); }
| RASTER_BAND_REF { $$ = new QgsRasterCalcNode(QString::fromUtf8(rastertext)); addToTmpNodes($$); }
| RASTER_BAND_REF { $$ = new QgsRasterCalcNode(QString::fromUtf8(raster_text)); addToTmpNodes($$); }
;

%%
Expand Down Expand Up @@ -136,7 +136,7 @@ QgsRasterCalcNode* localParseRasterCalcString(const QString& str, QString& parse
Q_ASSERT(gTmpNodes.count() == 0);

set_raster_input_buffer(str.toUtf8().constData());
int res = rasterparse();
int res = raster_parse();

// list should be empty when parsing was OK
if (res == 0) // success?
Expand Down

0 comments on commit a20c909

Please sign in to comment.