diff options
author | Dimitri van Heesch <doxygen@gmail.com> | 2021-02-06 20:27:28 (GMT) |
---|---|---|
committer | Dimitri van Heesch <doxygen@gmail.com> | 2021-02-06 20:27:28 (GMT) |
commit | 5563447069c5b047a87d319b46fcfc23a88b03f9 (patch) | |
tree | 0d5a9351da28a0f754b565718b91bb30db92dcdd /src | |
parent | f86b22b1c22474296e90591363b5028bf2d71b1e (diff) | |
parent | 38fdb5cf1193c792153c139800c92c37a555f9d1 (diff) | |
download | Doxygen-5563447069c5b047a87d319b46fcfc23a88b03f9.zip Doxygen-5563447069c5b047a87d319b46fcfc23a88b03f9.tar.gz Doxygen-5563447069c5b047a87d319b46fcfc23a88b03f9.tar.bz2 |
Merge branch 'refactor_constexp'
Diffstat (limited to 'src')
-rw-r--r-- | src/bufstr.h | 24 | ||||
-rw-r--r-- | src/constexp.h | 13 | ||||
-rw-r--r-- | src/constexp.l | 6 | ||||
-rw-r--r-- | src/constexp.y | 43 | ||||
-rw-r--r-- | src/constexp_p.h | 18 | ||||
-rw-r--r-- | src/cppvalue.cpp | 33 | ||||
-rw-r--r-- | src/cppvalue.h | 30 | ||||
-rw-r--r-- | src/pre.l | 2 |
8 files changed, 77 insertions, 92 deletions
diff --git a/src/bufstr.h b/src/bufstr.h index e64a049..ca733ad 100644 --- a/src/bufstr.h +++ b/src/bufstr.h @@ -1,13 +1,13 @@ /****************************************************************************** * - * + * * * * Copyright (C) 1997-2015 by Dimitri van Heesch. * * Permission to use, copy, modify, and distribute this software and its - * documentation under the terms of the GNU General Public License is hereby - * granted. No representations are made about the suitability of this software + * documentation under the terms of the GNU General Public License is hereby + * granted. No representations are made about the suitability of this software * for any purpose. It is provided "as is" without express or implied warranty. * See the GNU General Public License for more details. * @@ -18,20 +18,18 @@ #ifndef _BUFSTR_H #define _BUFSTR_H -#include <qglobal.h> -#include <qcstring.h> -#include <stdlib.h> +#include <cstdlib> /*! @brief Buffer used to store strings - * + * * This buffer is used append characters and strings. It will automatically * resize itself, yet provide efficient random access to the content. */ -class BufStr +class BufStr { public: - BufStr(uint size) - : m_size(size), m_writeOffset(0), m_spareRoom(10240), m_buf(0) + BufStr(uint size) + : m_size(size), m_writeOffset(0), m_spareRoom(10240), m_buf(0) { m_buf = (char *)calloc(size,1); } @@ -95,8 +93,8 @@ class BufStr return m_buf; } uint curPos() const - { - return m_writeOffset; + { + return m_writeOffset; } void dropFromStart(uint bytes) { @@ -108,7 +106,7 @@ class BufStr private: void makeRoomFor(uint size) { - if (m_writeOffset+size>=m_size) + if (m_writeOffset+size>=m_size) { resize(m_size+size+m_spareRoom); } diff --git a/src/constexp.h b/src/constexp.h index 0b52e14..212387b 100644 --- a/src/constexp.h +++ b/src/constexp.h @@ -1,13 +1,10 @@ /****************************************************************************** * - * - * - * - * Copyright (C) 1997-2015 by Dimitri van Heesch. + * Copyright (C) 1997-2021 by Dimitri van Heesch. * * Permission to use, copy, modify, and distribute this software and its - * documentation under the terms of the GNU General Public License is hereby - * granted. No representations are made about the suitability of this software + * documentation under the terms of the GNU General Public License is hereby + * granted. No representations are made about the suitability of this software * for any purpose. It is provided "as is" without express or implied warranty. * See the GNU General Public License for more details. * @@ -19,14 +16,14 @@ #ifndef _CONSTEXP_H #define _CONSTEXP_H -#include <qcstring.h> +#include <string> class ConstExpressionParser { public: ConstExpressionParser(); ~ConstExpressionParser(); - bool parse(const char *fileName,int line,const QCString &expression); + bool parse(const char *fileName,int line,const std::string &expression); private: struct Private; Private *p; diff --git a/src/constexp.l b/src/constexp.l index 0f053bd..acff1eb 100644 --- a/src/constexp.l +++ b/src/constexp.l @@ -132,7 +132,7 @@ ConstExpressionParser::~ConstExpressionParser() delete p; } -bool ConstExpressionParser::parse(const char *fileName,int lineNr,const QCString &s) +bool ConstExpressionParser::parse(const char *fileName,int lineNr,const std::string &s) { struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner; @@ -146,13 +146,13 @@ bool ConstExpressionParser::parse(const char *fileName,int lineNr,const QCString yyextra->inputPosition = 0; constexpYYrestart( yyin, p->yyscanner ); - printlex(yy_flex_debug, TRUE, __FILE__, fileName); + printlex(yy_flex_debug, true, __FILE__, fileName); //printf("Expression: '%s'\n",s.data()); constexpYYparse(p->yyscanner); //printf("Result: %ld\n",(long)g_resultValue); - printlex(yy_flex_debug, FALSE, __FILE__, fileName); + printlex(yy_flex_debug, false, __FILE__, fileName); bool result = (long)yyextra->resultValue!=0; return result; diff --git a/src/constexp.y b/src/constexp.y index c4110f9..560b3c3 100644 --- a/src/constexp.y +++ b/src/constexp.y @@ -1,13 +1,10 @@ /****************************************************************************** * - * - * - * - * Copyright (C) 1997-2015 by Dimitri van Heesch. + * Copyright (C) 1997-2021 by Dimitri van Heesch. * * Permission to use, copy, modify, and distribute this software and its - * documentation under the terms of the GNU General Public License is hereby - * granted. No representations are made about the suitability of this software + * documentation under the terms of the GNU General Public License is hereby + * granted. No representations are made about the suitability of this software * for any purpose. It is provided "as is" without express or implied warranty. * See the GNU General Public License for more details. * @@ -28,8 +25,8 @@ int constexpYYerror(yyscan_t yyscanner, const char *s) { struct constexpYY_state* yyextra = constexpYYget_extra(yyscanner); - warn(yyextra->constExpFileName, yyextra->constExpLineNr, - "preprocessing issue while doing constant expression evaluation: %s: input='%s'",s,yyextra->inputString); + warn(yyextra->constExpFileName.c_str(), yyextra->constExpLineNr, + "preprocessing issue while doing constant expression evaluation: %s: input='%s'",s,yyextra->inputString.c_str()); return 0; } @@ -81,8 +78,8 @@ start: constant_expression constant_expression: logical_or_expression { $$ = $1; } - | logical_or_expression - TOK_QUESTIONMARK logical_or_expression + | logical_or_expression + TOK_QUESTIONMARK logical_or_expression TOK_COLON logical_or_expression { bool c = ($1.isInt() ? ((long)$1 != 0) : ((double)$1 != 0.0)); @@ -108,9 +105,9 @@ logical_and_expression: inclusive_or_expression inclusive_or_expression: exclusive_or_expression { $$ = $1; } - | inclusive_or_expression TOK_BITWISEOR + | inclusive_or_expression TOK_BITWISEOR exclusive_or_expression - { + { $$ = CPPValue( (long)$1 | (long)$3 ); } ; @@ -126,7 +123,7 @@ exclusive_or_expression: and_expression and_expression: equality_expression { $$ = $1; } | and_expression TOK_AMPERSAND equality_expression - { + { $$ = CPPValue( (long)$1 & (long)$3 ); } ; @@ -134,7 +131,7 @@ and_expression: equality_expression equality_expression: relational_expression { $$ = $1; } | equality_expression TOK_EQUAL relational_expression - { + { $$ = CPPValue( (long)((double)$1 == (double)$3) ); } | equality_expression TOK_NOTEQUAL relational_expression @@ -146,7 +143,7 @@ equality_expression: relational_expression relational_expression: shift_expression { $$ = $1; } | relational_expression TOK_LESSTHAN shift_expression - { + { $$ = CPPValue( (long)((double)$1 < (double)$3) ); } | relational_expression TOK_GREATERTHAN shift_expression @@ -169,7 +166,7 @@ shift_expression: additive_expression { $$ = $1; } | shift_expression TOK_SHIFTLEFT additive_expression { - $$ = CPPValue( (long)$1 << (long)$3 ); + $$ = CPPValue( (long)$1 << (long)$3 ); } | shift_expression TOK_SHIFTRIGHT additive_expression { @@ -185,7 +182,7 @@ additive_expression: multiplicative_expression { $$ = CPPValue( (double)$1 + (double)$3 ); } - else + else { $$ = CPPValue( (long)$1 + (long)$3 ); } @@ -196,7 +193,7 @@ additive_expression: multiplicative_expression { $$ = CPPValue( (double)$1 - (double)$3 ); } - else + else { $$ = CPPValue( (long)$1 - (long)$3 ); } @@ -206,7 +203,7 @@ additive_expression: multiplicative_expression multiplicative_expression: unary_expression { $$ = $1; } | multiplicative_expression TOK_STAR unary_expression - { + { if (!$1.isInt() || !$3.isInt()) { $$ = CPPValue( (double)$1 * (double)$3 ); @@ -217,7 +214,7 @@ multiplicative_expression: unary_expression } } | multiplicative_expression TOK_DIVIDE unary_expression - { + { if (!$1.isInt() || !$3.isInt()) { $$ = CPPValue( (double)$1 / (double)$3 ); @@ -230,7 +227,7 @@ multiplicative_expression: unary_expression } } | multiplicative_expression TOK_MOD unary_expression - { + { long value = $3; if (value==0) value=1; $$ = CPPValue( (long)$1 % value ); @@ -242,8 +239,8 @@ unary_expression: primary_expression | TOK_PLUS unary_expression { $$ = $1; } | TOK_MINUS unary_expression - { - if ($2.isInt()) + { + if ($2.isInt()) $$ = CPPValue(-(long)$2); else $$ = CPPValue(-(double)$2); diff --git a/src/constexp_p.h b/src/constexp_p.h index ad09b2d..1f3408b 100644 --- a/src/constexp_p.h +++ b/src/constexp_p.h @@ -1,10 +1,10 @@ /****************************************************************************** * - * Copyright (C) 1997-2019 by Dimitri van Heesch. + * Copyright (C) 1997-2021 by Dimitri van Heesch. * * Permission to use, copy, modify, and distribute this software and its - * documentation under the terms of the GNU General Public License is hereby - * granted. No representations are made about the suitability of this software + * documentation under the terms of the GNU General Public License is hereby + * granted. No representations are made about the suitability of this software * for any purpose. It is provided "as is" without express or implied warranty. * See the GNU General Public License for more details. * @@ -16,7 +16,7 @@ #ifndef _CONSTEXP_P_H #define _CONSTEXP_P_H -#include <qcstring.h> +#include <string> //! @file //! @brief Private interface between Parser (constexp.y) and Lexer (constexp.l) @@ -27,12 +27,12 @@ typedef void* yyscan_t; struct constexpYY_state { - QCString strToken; - CPPValue resultValue; - int constExpLineNr; - QCString constExpFileName; + std::string strToken; + CPPValue resultValue; + int constExpLineNr; + std::string constExpFileName; - const char *inputString; + std::string inputString; int inputPosition; }; constexpYY_state* constexpYYget_extra(yyscan_t yyscanner ); diff --git a/src/cppvalue.cpp b/src/cppvalue.cpp index 1543498..31f0ab5 100644 --- a/src/cppvalue.cpp +++ b/src/cppvalue.cpp @@ -1,13 +1,10 @@ /****************************************************************************** * - * - * - * - * Copyright (C) 1997-2015 by Dimitri van Heesch. + * Copyright (C) 1997-2021 by Dimitri van Heesch. * * Permission to use, copy, modify, and distribute this software and its - * documentation under the terms of the GNU General Public License is hereby - * granted. No representations are made about the suitability of this software + * documentation under the terms of the GNU General Public License is hereby + * granted. No representations are made about the suitability of this software * for any purpose. It is provided "as is" without express or implied warranty. * See the GNU General Public License for more details. * @@ -21,30 +18,30 @@ #include "cppvalue.h" #include "constexp.h" -CPPValue parseOctal(const QCString& token) +CPPValue parseOctal(const std::string& token) { long val = 0; - for (const char *p = token.data(); *p != 0; p++) + for (const char *p = token.c_str(); *p != 0; p++) { if (*p >= '0' && *p <= '7') val = val * 8 + *p - '0'; } return CPPValue(val); } -CPPValue parseDecimal(const QCString& token) +CPPValue parseDecimal(const std::string& token) { long val = 0; - for (const char *p = token.data(); *p != 0; p++) + for (const char *p = token.c_str(); *p != 0; p++) { if (*p >= '0' && *p <= '9') val = val * 10 + *p - '0'; } return CPPValue(val); } -CPPValue parseHexadecimal(const QCString& token) +CPPValue parseHexadecimal(const std::string& token) { long val = 0; - for (const char *p = token.data(); *p != 0; p++) + for (const char *p = token.c_str(); *p != 0; p++) { if (*p >= '0' && *p <= '9') val = val * 16 + *p - '0'; else if (*p >= 'a' && *p <= 'f') val = val * 16 + *p - 'a' + 10; @@ -54,7 +51,7 @@ CPPValue parseHexadecimal(const QCString& token) return CPPValue(val); } -CPPValue parseCharacter(const QCString& token) // does not work for '\n' and the alike +CPPValue parseCharacter(const std::string& token) // does not work for '\n' and the alike { if (token[1]=='\\') { @@ -80,16 +77,16 @@ CPPValue parseCharacter(const QCString& token) // does not work for '\n' and the case '6': // fall through case '7': // fall through return parseOctal(token); - case 'x': + case 'x': case 'X': return parseHexadecimal(token); - default: printf("Invalid escape sequence %s found!\n",token.data()); - return CPPValue(0L); + default: printf("Invalid escape sequence %s found!\n",token.data()); + return CPPValue(0L); } } return CPPValue((long)token[1]); } -CPPValue parseFloat(const QCString& token) +CPPValue parseFloat(const std::string& token) { - return CPPValue(atof(token)); + return CPPValue(std::stod(token)); } diff --git a/src/cppvalue.h b/src/cppvalue.h index cde033d..7732068 100644 --- a/src/cppvalue.h +++ b/src/cppvalue.h @@ -1,13 +1,10 @@ /****************************************************************************** * - * - * - * - * Copyright (C) 1997-2015 by Dimitri van Heesch. + * Copyright (C) 1997-2021 by Dimitri van Heesch. * * Permission to use, copy, modify, and distribute this software and its - * documentation under the terms of the GNU General Public License is hereby - * granted. No representations are made about the suitability of this software + * documentation under the terms of the GNU General Public License is hereby + * granted. No representations are made about the suitability of this software * for any purpose. It is provided "as is" without express or implied warranty. * See the GNU General Public License for more details. * @@ -19,16 +16,15 @@ #ifndef _CPPVALUE_H #define _CPPVALUE_H -#include <stdio.h> -#include <qglobal.h> -#include <qcstring.h> +#include <cstdio> +#include <string> /** A class representing a C-preprocessor value. */ class CPPValue { public: enum Type { Int, Float }; - + CPPValue(long val=0) : type(Int) { v.l = val; } CPPValue(double val) : type(Float) { v.d = val; } @@ -36,10 +32,10 @@ class CPPValue operator long () const { return type==Int ? v.l : (long)v.d; } bool isInt() const { return type == Int; } - + void print() const { - if (type==Int) + if (type==Int) printf("(%ld)\n",v.l); else printf("(%f)\n",v.d); @@ -53,10 +49,10 @@ class CPPValue } v; }; -extern CPPValue parseOctal(const QCString& token); -extern CPPValue parseDecimal(const QCString& token); -extern CPPValue parseHexadecimal(const QCString& token); -extern CPPValue parseCharacter(const QCString& token); -extern CPPValue parseFloat(const QCString& token); +extern CPPValue parseOctal(const std::string& token); +extern CPPValue parseDecimal(const std::string& token); +extern CPPValue parseHexadecimal(const std::string& token); +extern CPPValue parseCharacter(const std::string& token); +extern CPPValue parseFloat(const std::string& token); #endif @@ -2702,7 +2702,7 @@ static bool computeExpression(yyscan_t yyscanner,const QCString &expr) e = removeIdsAndMarkers(e); if (e.isEmpty()) return FALSE; //printf("parsing '%s'\n",e.data()); - return state->constExpParser.parse(state->yyFileName,state->yyLineNr,e); + return state->constExpParser.parse(state->yyFileName,state->yyLineNr,e.str()); } /*! expands the macro definition in \a name |