diff --git a/CMakeLists.txt b/CMakeLists.txt index 21094ebd0d..c7778710d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,6 +121,11 @@ if (CMAKE_SYSTEM_NAME MATCHES "Windows") endif() endif() +# needed for JavaCC +set(JAVA_CC_EXTRA_FLAGS "-DJAVACC_CHAR_TYPE=\"unsigned char\"") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${JAVA_CC_EXTRA_FLAGS}") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${JAVA_CC_EXTRA_FLAGS}") + if(POLICY CMP0063) cmake_policy(SET CMP0063 NEW) endif() diff --git a/src/qcstring.h b/src/qcstring.h index bee80bde85..272c7fd6a1 100644 --- a/src/qcstring.h +++ b/src/qcstring.h @@ -84,6 +84,7 @@ int qstricmp( const char *str1, const char *str2 ); int qstrnicmp( const char *str1, const char *str2, size_t len ); +using JavaCCString = std::basic_string; /** This is an alternative implementation of QCString. It provides basically * the same functions but uses std::string as the underlying string type @@ -102,6 +103,19 @@ class QCString QCString( std::string &&s) : m_rep(std::move(s)) {} + /** For converting a JavaCC string */ + QCString( const JavaCCString &s) + { + m_rep.resize(s.size()); + memcpy(m_rep.data(),s.data(),s.size()); + } + QCString &operator=( const JavaCCString &s) + { + m_rep.resize(s.size()); + memcpy(m_rep.data(),s.data(),s.size()); + return *this; + } + /** creates a string with room for size characters * @param[in] size the number of character to allocate (also counting the 0-terminator!) */ diff --git a/src/vhdljjparser.cpp b/src/vhdljjparser.cpp index df2769b613..5ee317d8b9 100644 --- a/src/vhdljjparser.cpp +++ b/src/vhdljjparser.cpp @@ -88,8 +88,8 @@ struct VHDLOutlineParser::Private void VHDLOutlineParser::Private::parseVhdlfile(const QCString &fileName, const char* inputBuffer,bool inLine) { - JAVACC_STRING_TYPE s =inputBuffer; - CharStream *stream = new CharStream(s.c_str(), (int)s.size(), 1, 1); + QCString s =inputBuffer; + CharStream *stream = new CharStream(reinterpret_cast(s.data()), (int)s.size(), 1, 1); VhdlParserTokenManager *tokenManager = new VhdlParserTokenManager(stream); VhdlTokenManagerErrorHandler *tokErrHandler=new VhdlTokenManagerErrorHandler(fileName.data()); vhdlParser=new VhdlParser(tokenManager); @@ -186,11 +186,14 @@ void VHDLOutlineParser::lineCount() p->yyLineNr++; } -void VHDLOutlineParser::lineCount(const char* text) +void VHDLOutlineParser::lineCount(const QCString &text) { - for (const char* c=text ; *c ; ++c ) + if (!text.isEmpty()) { - if (*c == '\n') p->yyLineNr++; + for (const char* c=text.data() ; *c ; ++c ) + { + if (*c == '\n') p->yyLineNr++; + } } } @@ -259,7 +262,7 @@ QCString VHDLOutlineParser::getNameID() return QCString().setNum(idCounter++); } -void VHDLOutlineParser::handleFlowComment(const char* doc) +void VHDLOutlineParser::handleFlowComment(const QCString &doc) { lineCount(doc); @@ -551,11 +554,9 @@ void VHDLOutlineParser::addVhdlType(const char *n,int startLine,int section, } } -void VHDLOutlineParser::createFunction(const char *imp,uint64_t spec,const char *fn) +void VHDLOutlineParser::createFunction(const QCString &impure,uint64_t spec,const QCString &fname) { VhdlParser::SharedState *s = &p->shared; - QCString impure(imp); - QCString fname(fn); s->current->spec=spec; s->current->section=Entry::FUNCTION_SEC; @@ -862,10 +863,11 @@ void VHDLOutlineParser::error_skipto(int kind) // "if"/"while". } -QCString filter2008VhdlComment(const char *s) +QCString filter2008VhdlComment(const QCString &s) { + if (s.length()<4) return s; GrowBuf growBuf; - const char *p=s+3; // skip /*! + const char *p=s.data()+3; // skip /*! char c='\0'; while (*p == ' ' || *p == '\t') p++; while ((c=*p++)) diff --git a/src/vhdljjparser.h b/src/vhdljjparser.h index 26b7964f80..d62bc62d05 100644 --- a/src/vhdljjparser.h +++ b/src/vhdljjparser.h @@ -43,15 +43,14 @@ class VHDLOutlineParser : public OutlineParserInterface void setLineParsed(int tok); int getLine(int tok); int getLine(); - void lineCount(const char*); + void lineCount(const QCString &); void lineCount(); void addProto(const char *s1,const char *s2,const char *s3,const char *s4,const char *s5,const char *s6); - //void addConfigureNode(const char* a,const char*b, bool,bool isLeaf,bool inlineConf); - void createFunction(const char *impure,uint64_t spec,const char *fname); + void createFunction(const QCString &impure,uint64_t spec,const QCString &fname); void addVhdlType(const char *n,int startLine,int section, uint64_t spec,const char* args,const char* type,Protection prot); void addCompInst(const char *n, const char* instName, const char* comp,int iLine); void handleCommentBlock(const QCString &doc,bool brief); - void handleFlowComment(const char*); + void handleFlowComment(const QCString &); void initEntry(Entry *e); void newEntry(); bool isFuncProcProced(); @@ -75,6 +74,6 @@ class VHDLOutlineParser : public OutlineParserInterface const EntryList &getVhdlInstList(); -QCString filter2008VhdlComment(const char *s); +QCString filter2008VhdlComment(const QCString &s); #endif diff --git a/vhdlparser/CMakeLists.txt b/vhdlparser/CMakeLists.txt index 7dd36bc5f9..2b6bfbc92a 100644 --- a/vhdlparser/CMakeLists.txt +++ b/vhdlparser/CMakeLists.txt @@ -34,6 +34,13 @@ add_custom_command( ) set_source_files_properties(${GENERATED_SRC}/VhdlParser_adj.cc PROPERTIES GENERATED 1) +add_custom_command( + COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/vhdlparser/vhdl_adj.py ${PROJECT_SOURCE_DIR}/vhdlparser/VhdlParserTokenManager.cc ${GENERATED_SRC}/VhdlParserTokenManager_adj.cc + DEPENDS ${PROJECT_SOURCE_DIR}/vhdlparser/VhdlParserTokenManager.cc ${PROJECT_SOURCE_DIR}/vhdlparser/vhdl_adj.py + OUTPUT ${GENERATED_SRC}/VhdlParserTokenManager_adj.cc +) +set_source_files_properties(${GENERATED_SRC}/VhdlParserTokenManager_adj.cc PROPERTIES GENERATED 1) + include_directories( ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/vhdlparser @@ -44,7 +51,7 @@ ParseException.cc Token.cc TokenMgrError.cc ${GENERATED_SRC}/VhdlParser_adj.cc -VhdlParserTokenManager.cc +${GENERATED_SRC}/VhdlParserTokenManager_adj.cc ) add_dependencies(vhdlparser generate_configvalues_header diff --git a/vhdlparser/JavaCC.h.in b/vhdlparser/JavaCC.h.in deleted file mode 100644 index 5889e93acf..0000000000 --- a/vhdlparser/JavaCC.h.in +++ /dev/null @@ -1,60 +0,0 @@ -/* Generated By:JavaCC: Do not edit this line. JavaCC.h Version 7.0 */ -/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ -#ifndef JAVACC_JAVACC_H_ -#define JAVACC_JAVACC_H_ - -#include -#include -#include -#include - -#ifndef JAVACC_CHAR_TYPE -#define JAVACC_CHAR_TYPE char -#endif - -#ifndef JAVACC_STRING_TYPE -#define JAVACC_STRING_TYPE std::basic_string -#endif - -#define JAVACC_SIMPLE_STRING std::basic_string - -typedef JAVACC_CHAR_TYPE JJChar; -typedef JAVACC_STRING_TYPE JJString; -typedef JAVACC_STRING_TYPE JJStringBuffer; -typedef JAVACC_SIMPLE_STRING JJSimpleString; - -// Abstraction on stream classes to read a block of data into a buffer. -class ReaderStream { -public: - // Read block of data into a buffer and return the actual number read. - virtual size_t read(JAVACC_CHAR_TYPE *buffer, int offset, size_t len) { return 0; } - virtual bool endOfInput() { return true; } - virtual ~ReaderStream() {} -}; - -const JAVACC_CHAR_TYPE EMPTY[] = { 0 }; - -#ifndef MAX -#define MAX(a,b) ((a)>=(b)?(a):(b)) -#endif -#ifndef MIN -#define MIN(a,b) ((a)<=(b)?(a):(b)) -#endif - -template -struct JJEnter -{ - JJEnter(T f_) : f{f_} {f();} - ~JJEnter(){} - T f; -}; -template -struct JJExit -{ - JJExit(T f_) : f{f_} {} - ~JJExit(){f();} - T f; -}; - -#endif -/* JavaCC - OriginalChecksum=b719dd5e5f87efc5315d14df0b701850 (do not edit this line) */ diff --git a/vhdlparser/VhdlParser.cc b/vhdlparser/VhdlParser.cc index b392af44e7..61ce96e357 100644 --- a/vhdlparser/VhdlParser.cc +++ b/vhdlparser/VhdlParser.cc @@ -144,7 +144,7 @@ return QCString(t->image); t = jj_consume_token(INERTIAL_T); } if (!hasError) { -s=t->image+" "; +s=QCString(t->image)+" "; } break; } @@ -9959,7 +9959,7 @@ if(s.isEmpty()) m_sharedState->currP=0; if(tok) s1=tok->image; - outlineParser()->createFunction(m_sharedState->currName.data(),VhdlDocGen::PROCESS,s1.data()); + outlineParser()->createFunction(m_sharedState->currName,VhdlDocGen::PROCESS,s1); outlineParser()->createFlow(); m_sharedState->currName=""; outlineParser()->newEntry(); @@ -12945,7 +12945,7 @@ void VhdlParser::subprogram_specification() {QCString s;Token *tok=0;Token *t; } if (!hasError) { m_sharedState->currP=VhdlDocGen::PROCEDURE; - outlineParser()->createFunction(s.data(),m_sharedState->currP,0); + outlineParser()->createFunction(s,m_sharedState->currP,0); m_sharedState->tempEntry=m_sharedState->current; m_sharedState->current->startLine=outlineParser()->getLine(PROCEDURE_T); m_sharedState->current->bodyLine=outlineParser()->getLine(PROCEDURE_T); @@ -13058,10 +13058,10 @@ m_sharedState->currP=VhdlDocGen::FUNCTION; } } if (!hasError) { -if(tok) - outlineParser()->createFunction(tok->image.c_str(),m_sharedState->currP,s.data()); +if (tok) + outlineParser()->createFunction(tok->image,m_sharedState->currP,s); else - outlineParser()->createFunction(0,m_sharedState->currP,s.data()); + outlineParser()->createFunction(QCString(),m_sharedState->currP,s); m_sharedState->tempEntry=m_sharedState->current; m_sharedState->current->startLine=outlineParser()->getLine(FUNCTION_T); diff --git a/vhdlparser/VhdlParserTokenManager.cc b/vhdlparser/VhdlParserTokenManager.cc index 9b704e51d7..21761ba7e6 100644 --- a/vhdlparser/VhdlParserTokenManager.cc +++ b/vhdlparser/VhdlParserTokenManager.cc @@ -3513,7 +3513,7 @@ void VhdlParserTokenManager::SkipLexicalActions(Token *matchedToken){ QCString doc(image.data()); int count=doc.contains("--!"); parser->outlineParser()->setMultCommentLine(); - parser->outlineParser()->lineCount(image.data()); + parser->outlineParser()->lineCount(image); if (count == 1) parser->outlineParser()->oneLineComment(doc); else @@ -3523,26 +3523,26 @@ void VhdlParserTokenManager::SkipLexicalActions(Token *matchedToken){ } case 7 : { image.append(input_stream->GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1))); - parser->outlineParser()->handleFlowComment(image.data()); + parser->outlineParser()->handleFlowComment(image); break; } case 8 : { image.append(input_stream->GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1))); - parser->outlineParser()->lineCount(image.data()); + parser->outlineParser()->lineCount(image); break; } case 9 : { image.append(input_stream->GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1))); { - QCString q = filter2008VhdlComment(image.data()); - parser->outlineParser()->lineCount(image.data()); + QCString q = filter2008VhdlComment(image); + parser->outlineParser()->lineCount(image); parser->outlineParser()->handleCommentBlock(QCString(q),TRUE);image.clear(); } break; } case 10 : { image.append(input_stream->GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1))); - parser->outlineParser()->lineCount(image.data());image.clear(); + parser->outlineParser()->lineCount(image);image.clear(); break; } default : diff --git a/vhdlparser/vhdl_adj.py b/vhdlparser/vhdl_adj.py index 8f549aaa80..ffb97065b5 100644 --- a/vhdlparser/vhdl_adj.py +++ b/vhdlparser/vhdl_adj.py @@ -13,11 +13,17 @@ # input used in their production; they are not affected by this license. import sys +import re + +message_re = re.compile('message\s*\+=\s*("[^"]*")') def main(): inputFile = open(sys.argv[1], 'r') outputFile = open(sys.argv[2], 'w') for line in inputFile: + # fix literal strings + line = re.sub(message_re,'message += reinterpret_cast(\\1)',line) + # fix missing return statements outputFile.write(line.replace("assert(false);","assert(false);return QCString();")) if __name__ == '__main__': diff --git a/vhdlparser/vhdlparser.jj b/vhdlparser/vhdlparser.jj index 0000367626..8b06e373fc 100644 --- a/vhdlparser/vhdlparser.jj +++ b/vhdlparser/vhdlparser.jj @@ -92,7 +92,7 @@ SKIP: QCString doc(image.data()); int count=doc.contains("--!"); parser->outlineParser()->setMultCommentLine(); - parser->outlineParser()->lineCount(image.data()); + parser->outlineParser()->lineCount(image); if (count == 1) parser->outlineParser()->oneLineComment(doc); else @@ -100,10 +100,10 @@ SKIP: } } - | { parser->outlineParser()->handleFlowComment(image.data());} + | { parser->outlineParser()->handleFlowComment(image);} | { - parser->outlineParser()->lineCount(image.data());} + parser->outlineParser()->lineCount(image);} } // VHDL 2008 comment /* .... */ @@ -113,14 +113,14 @@ SKIP : { { - QCString q = filter2008VhdlComment(image.data()); - parser->outlineParser()->lineCount(image.data()); + QCString q = filter2008VhdlComment(image); + parser->outlineParser()->lineCount(image); parser->outlineParser()->handleCommentBlock(QCString(q),TRUE);image.clear(); } } | { - parser->outlineParser()->lineCount(image.data());image.clear();} + parser->outlineParser()->lineCount(image);image.clear();} } /* KEYWORDS */ @@ -357,7 +357,7 @@ QCString actual_designator() : { t= { return QCString(t->image); } | -LOOKAHEAD([ ] expression()) [ t= {s=t->image+" ";}] str=expression() { return s+str; } +LOOKAHEAD([ ] expression()) [ t= {s=QCString(t->image)+" ";}] str=expression() { return s+str; } | LOOKAHEAD(5) str=subtype_indication() {return str;} | @@ -2544,7 +2544,7 @@ void process_statement() : {QCString s,s1,s2;Token *tok=0;Token *tok1=0;} m_sharedState->currP=0; if(tok) s1=tok->image; - outlineParser()->createFunction(m_sharedState->currName.data(),VhdlDocGen::PROCESS,s1.data()); + outlineParser()->createFunction(m_sharedState->currName,VhdlDocGen::PROCESS,s1); outlineParser()->createFlow(); m_sharedState->currName=""; outlineParser()->newEntry(); @@ -3136,7 +3136,7 @@ void subprogram_specification() : {QCString s;Token *tok=0;Token *t;} s=designator() { m_sharedState->currP=VhdlDocGen::PROCEDURE; - outlineParser()->createFunction(s.data(),m_sharedState->currP,0); + outlineParser()->createFunction(s,m_sharedState->currP,0); m_sharedState->tempEntry=m_sharedState->current; m_sharedState->current->startLine=outlineParser()->getLine(PROCEDURE_T); m_sharedState->current->bodyLine=outlineParser()->getLine(PROCEDURE_T); @@ -3150,10 +3150,10 @@ void subprogram_specification() : {QCString s;Token *tok=0;Token *t;} [ (tok= | tok=) ] t= { m_sharedState->currP=VhdlDocGen::FUNCTION;} s=designator() [subprogram_header()] { - if(tok) - outlineParser()->createFunction(tok->image.c_str(),m_sharedState->currP,s.data()); + if (tok) + outlineParser()->createFunction(tok->image,m_sharedState->currP,s); else - outlineParser()->createFunction(0,m_sharedState->currP,s.data()); + outlineParser()->createFunction(QCString(),m_sharedState->currP,s); m_sharedState->tempEntry=m_sharedState->current; m_sharedState->current->startLine=outlineParser()->getLine(FUNCTION_T);