Skip to content

Commit

Permalink
issue #7436 Incorrect handling of block comments in VHDL
Browse files Browse the repository at this point in the history
The search for `/*` or /*!` ended at the last `*/` in a file and thus skipping other intermediate block end and new starts. Also the intermediate code was lost see as comment.
The filter pattern used was incorrect and should have been `<"/*" (~["*"])* "*" ("*" | ~["*","/"] (~["*"])* "*")* "/">` (thanks to https://javacc.org/contrib/C.jj).
Here also the space plus one or more `*` at the end beginning of the line are still incorporated as well as multiple `*` before the colosing `*/` this is also filtered.
  • Loading branch information
albert-github committed Dec 11, 2019
1 parent 2ed4583 commit 1a5bbad
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/growbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class GrowBuf
}
const char *get() { return str; }
int getPos() const { return pos; }
void setPos(const int newPos) { pos = newPos; }
char at(int i) const { return str[i]; }
private:
char *str;
Expand Down
35 changes: 34 additions & 1 deletion src/vhdljjparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "arguments.h"
#include "types.h"
#include "VhdlParserIF.h"
#include "growbuf.h"

using namespace vhdl::parser;
using namespace std;
Expand Down Expand Up @@ -169,7 +170,7 @@ void VhdlParser::lineCount(const char* text)
{
for (const char* c=text ; *c ; ++c )
{
yyLineNr += (*c == '\n') ;
if (*c == '\n') yyLineNr++;
}
}

Expand Down Expand Up @@ -744,3 +745,35 @@ const char *getVhdlFileName(void)
{
return vhdlFileName;
}

QCString filter2008VhdlComment(const char *s)
{
GrowBuf growBuf;
const char *p=s+3; // skip /*!
char c,pc='\0';
while (*p == ' ' || *p == '\t') p++;
while ((c=*p++))
{
growBuf.addChar(c);
if (c == '\n')
{
// special handling of space followed by * at beginning of line
while (*p == ' ' || *p == '\t') p++;
while (*p == '*') p++;
// special attention in case character at end is /
if (*p == '/') p++;
}
}
// special attention in case */ at end of last line
int len = growBuf.getPos();
if (growBuf.at(len-1) == '/' && growBuf.at(len-2) == '*')
{
len -= 2;
while (growBuf.at(len-1) == '*') len--;
c = growBuf.at(len-1);
while ((c = growBuf.at(len-1)) == ' ' || c == '\t') len--;
growBuf.setPos(len);
}
growBuf.addChar(0);
return growBuf.get();
}
2 changes: 1 addition & 1 deletion src/vhdljjparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ void vhdlscanFreeScanner();

const QList<VhdlConfNode>& getVhdlConfiguration();
const std::vector<std::shared_ptr<Entry> >&getVhdlInstList();

QCString filter2008VhdlComment(const char *s);
#endif
12 changes: 6 additions & 6 deletions vhdlparser/vhdlparser.jj
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,17 @@ SKIP:
// VHDL 2008 doxygen comment /*! .... */
SKIP :
{
<MULT_DOXYGEN_VHDL_COMMENT_2008 : "/*!" (~[])* "*/" >
<MULT_DOXYGEN_VHDL_COMMENT_2008 : "/*!" (~["*"])* "*" ("*" | ~["*","/"] (~["*"])* "*")* "/">
{
{
QCString q(image.data());
q.stripPrefix("/*!");
q.resize(q.length()-2);
QCString q = filter2008VhdlComment(image.data());
::vhdl::parser::VhdlParser::handleCommentBlock(q.data(),TRUE);image.clear();
}
}
| <MULT_VHDL_2008_COMMENT : "/*" (~[])* "*/" > {::vhdl::parser::VhdlParser::lineCount(image.data());image.clear();}
}
| <MULT_VHDL_2008_COMMENT : "/*" (~["*"])* "*" ("*" | ~["*","/"] (~["*"])* "*")* "/">
{
::vhdl::parser::VhdlParser::lineCount(image.data());image.clear();}
}

/* KEYWORDS */

Expand Down

0 comments on commit 1a5bbad

Please sign in to comment.