Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c-based: fix to handle edge case #3796

Merged
merged 1 commit into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Units/parser-java.r/java_enum.java.d/expected.tags
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ FIRST_VALUE input.java /^ FIRST_VALUE,$/;" e enum:C.TrivialEnum file: end:3
FancyEnum input.java /^ FancyEnum(int i) {$/;" m class:C.FancyEnum end:11
FancyEnum input.java /^ public enum FancyEnum {$/;" g class:C end:14
SECOND_VALUE input.java /^ SECOND_VALUE$/;" e enum:C.TrivialEnum file: end:4
StringEnum input.java /^ private StringEnum(String _s) {$/;" m class:StringEnum file: end:25
StringEnum input.java /^public enum StringEnum {$/;" g end:28
TrivialEnum input.java /^ public enum TrivialEnum {$/;" g class:C end:5
X input.java /^ X("X"),$/;" e enum:StringEnum file: end:19
Y input.java /^ Y("Y"),$/;" e enum:StringEnum file: end:20
Z input.java /^ Z("Z");$/;" e enum:StringEnum file: end:21
i input.java /^ private int i;$/;" f class:C.FancyEnum file: end:8
m input.java /^ void m() {$/;" m class:C.FancyEnum end:13
s input.java /^ private final String s;$/;" f class:StringEnum file: end:27
13 changes: 13 additions & 0 deletions Units/parser-java.r/java_enum.java.d/input.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,16 @@ void m() {
}
}
}

public enum StringEnum {

X("X"),
Y("Y"),
Z("Z");

private StringEnum(String _s) {
s = _s;
}

private final String s;
}
32 changes: 6 additions & 26 deletions parsers/c-based.c
Original file line number Diff line number Diff line change
Expand Up @@ -1486,28 +1486,8 @@
while (matchLevel > 0 && (c = skipToNonWhite ()) != EOF)
{
if (CollectingSignature)
{
if (c <= 0xff)
vStringPut (Signature, c);
else
{
char marker = '"';
cStringPut (Signature, c);

switch (c)
{
case CHAR_SYMBOL:
marker = '\'';
/* Fall through */
case STRING_SYMBOL:
vStringPut (Signature, marker);
vStringCat (Signature, cppGetLastCharOrStringContents ());
vStringPut (Signature, marker);
break;
default:
AssertNotReached();
}
}
}
if (c == begin)
{
++matchLevel;
Expand Down Expand Up @@ -1592,11 +1572,11 @@

do
{
vStringPut (name, c);
cStringPut (name, c);
if (CollectingSignature)
{
if (!first)
vStringPut (Signature, c);
cStringPut (Signature, c);
first = false;
}
c = cppGetc ();
Expand Down Expand Up @@ -1725,7 +1705,7 @@
vStringPut (name, ' ');
whiteSpace = false;
}
vStringPut (name, c);
cStringPut (name, c);
}
c = cppGetc ();
} while (! isOneOf (c, "(;") && c != EOF);
Expand All @@ -1735,7 +1715,7 @@
vStringPut (name, ' '); /* always separate operator from keyword */
do
{
vStringPut (name, c);
vStringPut (name, c); /* acceptable are all ascii */

Check warning on line 1718 in parsers/c-based.c

View check run for this annotation

Codecov / codecov/patch

parsers/c-based.c#L1718

Added line #L1718 was not covered by tests
c = cppGetc ();
} while (isOneOf (c, acceptable));
}
Expand Down Expand Up @@ -2316,8 +2296,8 @@
do
{
int c = skipToNonWhite ();
vStringPut (Signature, c);

cStringPut (Signature, c);
switch (c)
{
case '^':
Expand Down
37 changes: 37 additions & 0 deletions parsers/cpreprocessor.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,20 @@
/* This puts a character back into the input queue for the input File. */
extern void cppUngetc (const int c)
{
if (c == STRING_SYMBOL || c == CHAR_SYMBOL)
{
Assert(Cpp.charOrStringContents != NULL);
cppUngetc(c == STRING_SYMBOL ? '"' : '\'');
cppUngetString(vStringValue(Cpp.charOrStringContents), vStringLength(Cpp.charOrStringContents));
cppUngetc(c == STRING_SYMBOL ? '"' : '\'');
vStringClear(Cpp.charOrStringContents);
return;
}
else if (c == EOF)
{
return;
}

if(!Cpp.ungetPointer)
{
// no unget data
Expand Down Expand Up @@ -1520,6 +1534,29 @@
vStringPut(condition, c);
}

extern void cStringPut (vString* string, const int c)
{
if (c <= 0xff)
vStringPut (string, c);
else
{
char marker = '"';
switch (c)
{
case CHAR_SYMBOL:
marker = '\'';
/* Fall through */
case STRING_SYMBOL:
vStringPut (string, marker);
vStringCat (string, cppGetLastCharOrStringContents ());
vStringPut (string, marker);
break;
default:
AssertNotReached();

Check warning on line 1555 in parsers/cpreprocessor.c

View check run for this annotation

Codecov / codecov/patch

parsers/cpreprocessor.c#L1554-L1555

Added lines #L1554 - L1555 were not covered by tests
}
}
}

/* This function returns the next character, stripping out comments,
* C pre-processor directives, and the contents of single and double
* quoted strings. In short, strip anything which places a burden upon
Expand Down
5 changes: 5 additions & 0 deletions parsers/cpreprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ extern void cppUngetString(const char * string,int len);
extern int cppGetc (void);
extern const vString * cppGetLastCharOrStringContents (void);

/*
* Replacement for vStringPut that can handle c > 0xff
*/
extern void cStringPut (vString * string, const int c);
jafl marked this conversation as resolved.
Show resolved Hide resolved

/* Notify the external parser state for the purpose of conditional
* branch choice. The CXX parser stores the block level here. */
extern void cppPushExternalParserBlock(void);
Expand Down
12 changes: 4 additions & 8 deletions parsers/cxx/cxx_parser_tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ static CXXCharTypeData g_aCharTable[128] =
0 ,
0
},
// 127 (0x7f) ''
// 127 (0x7f)
{ 0, 0, 0 }
};

Expand Down Expand Up @@ -1491,9 +1491,7 @@ bool cxxParserParseNextToken(void)
if(g_cxx.iChar == STRING_SYMBOL)
{
t->eType = CXXTokenTypeStringConstant;
vStringPut(t->pszWord,'"');
vStringCat(t->pszWord,cppGetLastCharOrStringContents());
vStringPut(t->pszWord,'"');
cStringPut(t->pszWord,g_cxx.iChar);
g_cxx.iChar = cppGetc();
t->bFollowedBySpace = cppIsspace(g_cxx.iChar);
return true;
Expand Down Expand Up @@ -1539,9 +1537,7 @@ bool cxxParserParseNextToken(void)
if(g_cxx.iChar == CHAR_SYMBOL)
{
t->eType = CXXTokenTypeCharacterConstant;
vStringPut(t->pszWord,'\'');
vStringCat(t->pszWord,cppGetLastCharOrStringContents());
vStringPut(t->pszWord,'\'');
cStringPut(t->pszWord,g_cxx.iChar);
g_cxx.iChar = cppGetc();
t->bFollowedBySpace = cppIsspace(g_cxx.iChar);
return true;
Expand Down Expand Up @@ -1683,7 +1679,7 @@ bool cxxParserParseNextToken(void)
}

t->eType = CXXTokenTypeUnknown;
vStringPut(t->pszWord,g_cxx.iChar);
cStringPut(t->pszWord,g_cxx.iChar);
g_cxx.iChar = cppGetc();
t->bFollowedBySpace = cppIsspace(g_cxx.iChar);

Expand Down