Skip to content

Commit 293f11e

Browse files
authored
Merge pull request #3886 from masatake/cpp-refactor-issue-3772
Vera: revise the dataflow of cppGetc -> vStringPut
2 parents 39e3105 + 8d950a8 commit 293f11e

File tree

13 files changed

+75
-56
lines changed

13 files changed

+75
-56
lines changed

main/debug.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ extern void debugPutc (const int level, const int c)
5151
{
5252
if (debug (level) && c != EOF)
5353
{
54-
if (c == STRING_SYMBOL) printf ("\"string\"");
55-
else if (c == CHAR_SYMBOL) printf ("'c'");
56-
else putchar (c);
57-
54+
putchar (c);
5855
fflush (stdout);
5956
}
6057
}

main/entry.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ static size_t appendInputLine (int putc_func (char , void *), const char *const
687687
const int next = *(p + 1);
688688
const int c = *p;
689689

690-
if (c == CRETURN || c == NEWLINE)
690+
if (c == '\r' || c == '\n')
691691
break;
692692

693693
if (patternLengthLimit != 0 && length >= patternLengthLimit &&
@@ -701,10 +701,10 @@ static size_t appendInputLine (int putc_func (char , void *), const char *const
701701
}
702702
/* If character is '\', or a terminal '$', then quote it.
703703
*/
704-
if (c == BACKSLASH || c == (Option.backward ? '?' : '/') ||
705-
(c == '$' && (next == NEWLINE || next == CRETURN)))
704+
if (c == '\\' || c == (Option.backward ? '?' : '/') ||
705+
(c == '$' && (next == '\n' || next == '\r')))
706706
{
707-
putc_func (BACKSLASH, data);
707+
putc_func ('\\', data);
708708
++length;
709709
}
710710
putc_func (c, data);

main/field.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ static const char* renderCompactInputLine (vString *b, const char *const line)
863863

864864
/* Write everything up to, but not including, the newline.
865865
*/
866-
for (const char *p = line; *p != NEWLINE && *p != '\0'; ++p)
866+
for (const char *p = line; *p != '\n' && *p != '\0'; ++p)
867867
{
868868
int c = (unsigned char) *p;
869869
if (lineStarted || ! isspace (c)) /* ignore leading spaces */
@@ -875,11 +875,11 @@ static const char* renderCompactInputLine (vString *b, const char *const line)
875875

876876
/* Consume repeating white space.
877877
*/
878-
while (next = (unsigned char) *(p+1), isspace (next) && next != NEWLINE)
878+
while (next = (unsigned char) *(p+1), isspace (next) && next != '\n')
879879
++p;
880880
c = ' '; /* force space character for any white space */
881881
}
882-
if (c != CRETURN || *(p + 1) != NEWLINE)
882+
if (c != '\r' || *(p + 1) != '\n')
883883
vStringPut (b, c);
884884
}
885885
}

main/read.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,6 @@
2929
* DATA DECLARATIONS
3030
*/
3131

32-
enum eCharacters {
33-
/* white space characters */
34-
SPACE = ' ',
35-
NEWLINE = '\n',
36-
CRETURN = '\r',
37-
FORMFEED = '\f',
38-
TAB = '\t',
39-
VTAB = '\v',
40-
41-
/* some hard to read characters */
42-
DOUBLE_QUOTE = '"',
43-
SINGLE_QUOTE = '\'',
44-
BACKSLASH = '\\',
45-
46-
/* symbolic representations, above 0xFF not to conflict with any byte */
47-
STRING_SYMBOL = ('S' + 0xff),
48-
CHAR_SYMBOL = ('C' + 0xff)
49-
};
50-
51-
5232
/*
5333
* FUNCTION PROTOTYPES
5434
*/

parsers/asm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ static bool collectCppMacroArguments (ptrArray *args)
399399
ptrArrayAdd (args, cstr);
400400
s = vStringNew ();
401401
}
402-
else if (c == STRING_SYMBOL || c == CHAR_SYMBOL)
402+
else if (c == CPP_STRING_SYMBOL || c == CPP_CHAR_SYMBOL)
403403
vStringPut (s, ' ');
404404
else
405405
vStringPut (s, c);
@@ -425,7 +425,7 @@ static bool expandCppMacro (cppMacroInfo *macroInfo)
425425
while (1)
426426
{
427427
c = cppGetc ();
428-
if (c == STRING_SYMBOL || c == CHAR_SYMBOL || !isspace (c))
428+
if (c == CPP_STRING_SYMBOL || c == CPP_CHAR_SYMBOL || !isspace (c))
429429
break;
430430
}
431431

@@ -519,7 +519,7 @@ static const unsigned char *readLineViaCpp (const char *commentChars)
519519
cont:
520520
while ((c = cppGetc()) != EOF)
521521
{
522-
if (c == STRING_SYMBOL || c == CHAR_SYMBOL)
522+
if (c == CPP_STRING_SYMBOL || c == CPP_CHAR_SYMBOL)
523523
{
524524
/* c == CHAR_SYMBOL is subtle condition.
525525
* If the last char of IDENTIFIER is [0-9a-f],

parsers/c-based.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ static void skipToMatch (const char *const pair)
14851485
while (matchLevel > 0 && (c = skipToNonWhite ()) != EOF)
14861486
{
14871487
if (CollectingSignature)
1488-
cStringPut (Signature, c);
1488+
cppVStringPut (Signature, c);
14891489

14901490
if (c == begin)
14911491
{
@@ -1571,11 +1571,11 @@ static void readIdentifier (tokenInfo *const token, const int firstChar)
15711571

15721572
do
15731573
{
1574-
cStringPut (name, c);
1574+
cppVStringPut (name, c);
15751575
if (CollectingSignature)
15761576
{
15771577
if (!first)
1578-
cStringPut (Signature, c);
1578+
cppVStringPut (Signature, c);
15791579
first = false;
15801580
}
15811581
c = cppGetc ();
@@ -1704,7 +1704,7 @@ static void readOperator (statementInfo *const st)
17041704
vStringPut (name, ' ');
17051705
whiteSpace = false;
17061706
}
1707-
cStringPut (name, c);
1707+
cppVStringPut (name, c);
17081708
}
17091709
c = cppGetc ();
17101710
} while (! isOneOf (c, "(;") && c != EOF);
@@ -2296,7 +2296,7 @@ static int parseParens (statementInfo *const st, parenInfo *const info)
22962296
{
22972297
int c = skipToNonWhite ();
22982298

2299-
cStringPut (Signature, c);
2299+
cppVStringPut (Signature, c);
23002300
switch (c)
23012301
{
23022302
case '^':
@@ -2688,7 +2688,7 @@ static void parseGeneralToken (statementInfo *const st, const int c)
26882688
{
26892689
parseAtMarkStyleAnnotation (st);
26902690
}
2691-
else if (c == STRING_SYMBOL)
2691+
else if (c == CPP_STRING_SYMBOL)
26922692
{
26932693
setToken(st, TOKEN_NONE);
26942694
}

parsers/cpreprocessor.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,25 @@
3939
/*
4040
* DATA DECLARATIONS
4141
*/
42+
enum eCppCharacters {
43+
/* white space characters */
44+
SPACE = ' ',
45+
NEWLINE = '\n',
46+
CRETURN = '\r',
47+
FORMFEED = '\f',
48+
TAB = '\t',
49+
VTAB = '\v',
50+
51+
/* some hard to read characters */
52+
DOUBLE_QUOTE = '"',
53+
SINGLE_QUOTE = '\'',
54+
BACKSLASH = '\\',
55+
56+
/* symbolic representations, above 0xFF not to conflict with any byte */
57+
STRING_SYMBOL = CPP_STRING_SYMBOL,
58+
CHAR_SYMBOL = CPP_CHAR_SYMBOL
59+
};
60+
4261
typedef enum { COMMENT_NONE, COMMENT_C, COMMENT_CPLUS, COMMENT_D } Comment;
4362

4463
enum eCppLimits {
@@ -1533,7 +1552,7 @@ static void conditionMayPut (vString *condition, int c)
15331552
vStringPut(condition, c);
15341553
}
15351554

1536-
extern void cStringPut (vString* string, const int c)
1555+
extern void cppVStringPut (vString* string, const int c)
15371556
{
15381557
if (c <= 0xff)
15391558
vStringPut (string, c);
@@ -1953,7 +1972,7 @@ extern int cppGetc (void)
19531972
if (condition)
19541973
vStringDelete (condition);
19551974

1956-
DebugStatement ( debugPutc (DEBUG_CPP, c); )
1975+
DebugStatement ( cppDebugPutc (DEBUG_CPP, c); )
19571976
DebugStatement ( if (c == NEWLINE)
19581977
debugPrintf (DEBUG_CPP, "%6ld: ", getInputLineNumber () + 1); )
19591978

@@ -2635,3 +2654,17 @@ extern parserDefinition* CPreProParser (void)
26352654
def->useCork = CORK_QUEUE | CORK_SYMTAB;
26362655
return def;
26372656
}
2657+
2658+
#ifdef DEBUG
2659+
extern void cppDebugPutc (const int level, const int c)
2660+
{
2661+
if (debug (level) && c != EOF)
2662+
{
2663+
if (c == STRING_SYMBOL) printf ("\"string\"");
2664+
else if (c == CHAR_SYMBOL) printf ("'c'");
2665+
else putchar (c);
2666+
2667+
fflush (stdout);
2668+
}
2669+
}
2670+
#endif

parsers/cpreprocessor.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@
1313
* INCLUDE FILES
1414
*/
1515
#include "general.h" /* must always come first */
16+
17+
#include "debug.h"
1618
#include "ptrarray.h"
1719
#include "types.h"
1820
#include "vstring.h"
1921

2022
/*
2123
* MACROS
2224
*/
25+
/* symbolic representations, above 0xFF not to conflict with any byte */
26+
#define CPP_STRING_SYMBOL ('S' + 0xff)
27+
#define CPP_CHAR_SYMBOL ('C' + 0xff)
2328

2429
/*
2530
* cppIs... macros are for the value returned from cppGetc(). Don't
@@ -103,7 +108,7 @@ extern const vString * cppGetLastCharOrStringContents (void);
103108
/*
104109
* Replacement for vStringPut that can handle c > 0xff
105110
*/
106-
extern void cStringPut (vString * string, const int c);
111+
extern void cppVStringPut (vString * string, const int c);
107112

108113
/* Notify the external parser state for the purpose of conditional
109114
* branch choice. The CXX parser stores the block level here. */
@@ -149,4 +154,8 @@ extern void cppBuildMacroReplacementWithPtrArrayAndUngetResult(
149154
cppMacroInfo * macro,
150155
const ptrArray * args);
151156

157+
#ifdef DEBUG
158+
extern void cppDebugPutc (const int level, const int c);
159+
#endif
160+
152161
#endif /* CTAGS_MAIN_GET_H */

parsers/cxx/cxx_parser_tokenizer.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,10 +1530,10 @@ bool cxxParserParseNextToken(void)
15301530
return true;
15311531
}
15321532
#else
1533-
if(g_cxx.iChar == STRING_SYMBOL)
1533+
if(g_cxx.iChar == CPP_STRING_SYMBOL)
15341534
{
15351535
t->eType = CXXTokenTypeStringConstant;
1536-
cStringPut(t->pszWord,g_cxx.iChar);
1536+
cppVStringPut(t->pszWord,g_cxx.iChar);
15371537
g_cxx.iChar = cppGetc();
15381538
t->bFollowedBySpace = cppIsspace(g_cxx.iChar);
15391539
return true;
@@ -1576,10 +1576,10 @@ bool cxxParserParseNextToken(void)
15761576
return true;
15771577
}
15781578
#else
1579-
if(g_cxx.iChar == CHAR_SYMBOL)
1579+
if(g_cxx.iChar == CPP_CHAR_SYMBOL)
15801580
{
15811581
t->eType = CXXTokenTypeCharacterConstant;
1582-
cStringPut(t->pszWord,g_cxx.iChar);
1582+
cppVStringPut(t->pszWord,g_cxx.iChar);
15831583
g_cxx.iChar = cppGetc();
15841584
t->bFollowedBySpace = cppIsspace(g_cxx.iChar);
15851585
return true;
@@ -1721,7 +1721,7 @@ bool cxxParserParseNextToken(void)
17211721
}
17221722

17231723
t->eType = CXXTokenTypeUnknown;
1724-
cStringPut(t->pszWord,g_cxx.iChar);
1724+
cppVStringPut(t->pszWord,g_cxx.iChar);
17251725
g_cxx.iChar = cppGetc();
17261726
t->bFollowedBySpace = cppIsspace(g_cxx.iChar);
17271727

parsers/ldscript.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ static void readToken (tokenInfo *const token, void *data CTAGS_ATTR_UNUSED)
380380
if (prefix_count > 0)
381381
LDSCRIPT (token)->whitespacePrefixed = true;
382382
} while (c == ' ' || c== '\t' || c == '\f' || c == '\r' || c == '\n'
383-
|| c == STRING_SYMBOL || c == CHAR_SYMBOL);
383+
|| c == CPP_STRING_SYMBOL || c == CPP_CHAR_SYMBOL);
384384

385385
token->lineNumber = getInputLineNumber ();
386386
token->filePosition = getInputFilePosition ();

0 commit comments

Comments
 (0)