Skip to content

Fixed several C++ lexical / tokenize errors.#16

Merged
adangel merged 4 commits intoadangel:masterfrom
tiobe:tiobe/pmd-cpp-fixlexicalerrors
Jan 18, 2015
Merged

Fixed several C++ lexical / tokenize errors.#16
adangel merged 4 commits intoadangel:masterfrom
tiobe:tiobe/pmd-cpp-fixlexicalerrors

Conversation

@tiobe
Copy link
Copy Markdown

@tiobe tiobe commented Jan 13, 2015

For a detailed information of the fixes, see the commit messages.

Jan van Nunen added 4 commits January 13, 2015 11:36
This commit fixes a lexical error when a C++ file contains ASM with the
'@' character. The following code cannot be tokenized and triggers a
lexical error:

asm void eSPI_boot()
{
// setup stack pointer
lis r1, _stack_addr@h
ori r1, r1, _stack_addr@l
}

The error that occurs:

net.sourceforge.pmd.lang.ast.TokenMgrError: Lexical error in file
CODE_LOADED_FROM_STRING at line 4, column 22.  Encountered: "@" (64),
after : ""
…gle line comment that starts with "//*".

This commit fixes a lexical eror when a preprocessor directive is
followed by a single line comment that starts with "//*".

The following code could not be tokenized:

#define LSTFVLES_CPP  //*

It triggers the following error:

net.sourceforge.pmd.lang.ast.TokenMgrError: Lexical error in file
'foo.cpp' at line 2, column 0.  Encountered: <EOF> after : ""
…al L''.

This commit fixes a lexical error when a C++ file contains an empty
character literal L''. The following code could not be tokenized:

std::wstring wsMessage( sMessage.length(), L'');

It triggers the following error:

net.sourceforge.pmd.lang.ast.TokenMgrError: Lexical error in file
'foo.cpp' at line 1, column 46.  Encountered: "\'" (39), after : "\'"
…aracter inside a string or character.

The following 2 code snippets could not be tokenized:

1:  if (*pbuf == '\0x05'), the problem is the '\0' in the character
literal '\0x05'.
2:  szPath = m_sdcacheDir + _T("\    oMedia");, the problem is the '\ '
in the string literal "\    oMedia".

I relaxed the lexical grammar so a '\' (backslash) can escape any
character inside a string or character literal. We can relax the grammar
because CPD only needs the tokens, so it is no problem to accept
'invalid' string / character literals. (according to the ANSI C
standard).  Failing too fast because the tokenizer is too strict is
annoying because then we can't check the files for duplicated code.

Both snippets were taken from existing projects and be successfully
compiled, so for some C / C++ compilers it is valid code.
@buildhive
Copy link
Copy Markdown

Andreas Dangel » pmd #217 SUCCESS
This pull request looks good
(what's this?)

@adangel adangel merged commit c92dc97 into adangel:master Jan 18, 2015
@adangel
Copy link
Copy Markdown
Owner

adangel commented Jan 18, 2015

Thanks!

@tiobe tiobe deleted the tiobe/pmd-cpp-fixlexicalerrors branch January 21, 2015 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants