Skip to content

Commit

Permalink
Merge pull request #1968 from masatake/cxx-capture-parameter-s-defaul…
Browse files Browse the repository at this point in the history
…t-value-as-part-of-signature

Cxx capture parameter s default value as part of signature
  • Loading branch information
masatake committed Jan 7, 2019
2 parents 284610b + b50d191 commit b60a7b9
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 9 deletions.
7 changes: 7 additions & 0 deletions Units/parser-cxx.r/signature.cpp.d/expected.tags
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@ BAR::bar input.cpp /^char *BAR::bar (char *c, double d[]) const {}$/;" f class:B
bar input.cpp /^char *BAR::bar (char *c, double d[]) const {}$/;" f class:BAR typeref:typename:char * signature:(char * c,double d[]) const
foo input.cpp /^void foo (int a, char b) {}$/;" f typeref:typename:void signature:(int a,char b)
foobar input.cpp /^void foobar __ARGS ((int a, char b));$/;" p typeref:typename:void file: signature:(int a,char b)
params1 input.cpp /^void params1(const char * c = "blah");$/;" p typeref:typename:void file: signature:(const char * c="blah")
params2 input.cpp /^void params2(char x = 'x');$/;" p typeref:typename:void file: signature:(char x='x')
params3 input.cpp /^void params3(char x = ' ');$/;" p typeref:typename:void file: signature:(char x=' ')
params4 input.cpp /^void params4(char x = ',');$/;" p typeref:typename:void file: signature:(char x=',')
params5 input.cpp /^void params5(char x = '\\n');$/;" p typeref:typename:void file: signature:(char x='\\n')
params6 input.cpp /^void params6(char x = '\\t',int n = 10,const char * v = "a string with\\na newline");$/;" p typeref:typename:void file: signature:(char x='\\t',int n=10,const char * v="a string with\\na newline")
params7 input.cpp /^void params7(char x = ' ', \/\/ This is tab char$/;" p typeref:typename:void file: signature:(char x='\t',float p=3.14,const char * v="a string with a tab char:\t")
12 changes: 12 additions & 0 deletions Units/parser-cxx.r/signature.cpp.d/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,15 @@ void foo (int a, char b) {}
char *BAR::bar (char *c, double d[]) const {}

void foobar __ARGS ((int a, char b));


void params1(const char * c = "blah");
void params2(char x = 'x');
void params3(char x = ' ');
void params4(char x = ',');
void params5(char x = '\n');
void params6(char x = '\t',int n = 10,const char * v = "a string with\na newline");
void params7(char x = ' ', // This is tab char
float p = 3.14,
const char * v = "a string with a tab char: "
);
19 changes: 17 additions & 2 deletions main/field.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static const char *renderFieldInput (const tagEntryInfo *const tag, const char *
static const char *renderFieldInputNoEscape (const tagEntryInfo *const tag, const char *value, vString* b);
static const char *renderFieldCompactInputLine (const tagEntryInfo *const tag, const char *value, vString* b);
static const char *renderFieldSignature (const tagEntryInfo *const tag, const char *value, vString* b);
static const char *renderFieldSignatureNoEscape (const tagEntryInfo *const tag, const char *value, vString* b);
static const char *renderFieldScope (const tagEntryInfo *const tag, const char *value, vString* b);
static const char *renderFieldScopeNoEscape (const tagEntryInfo *const tag, const char *value, vString* b);
static const char *renderFieldTyperef (const tagEntryInfo *const tag, const char *value, vString* b);
Expand All @@ -68,6 +69,7 @@ static const char *renderFieldEnd (const tagEntryInfo *const tag, const char *va
static bool hasWhitespaceInName (const tagEntryInfo *const tag, const char *value);
static bool hasWhitespaceInInput (const tagEntryInfo *const tag, const char*value);
static bool hasWhitespaceInFieldScope (const tagEntryInfo *const tag, const char *value);
static bool hasWhitespaceInSignature (const tagEntryInfo *const tag, const char *value);

static bool isLanguageFieldAvailable (const tagEntryInfo *const tag);
static bool isTyperefFieldAvailable (const tagEntryInfo *const tag);
Expand Down Expand Up @@ -162,11 +164,12 @@ static fieldDefinition fieldDefinitionsExuberant [] = {
"Line number of tag definition",
FIELDTYPE_INTEGER,
renderFieldLineNumber),
DEFINE_FIELD_FULL ('S', "signature", false,
DEFINE_FIELD_FULL ('S', "signature", false,
"Signature of routine (e.g. prototype or parameter list)",
isSignatureFieldAvailable,
FIELDTYPE_STRING,
renderFieldSignature, NULL, NULL),
renderFieldSignature, renderFieldSignatureNoEscape,
hasWhitespaceInSignature),
DEFINE_FIELD_FULL ('s', NULL, true,
"Scope of tag definition (`p' can be used for printing its kind)",
NULL,
Expand Down Expand Up @@ -472,6 +475,18 @@ static const char *renderFieldSignature (const tagEntryInfo *const tag, const ch
tag, b);
}

static const char *renderFieldSignatureNoEscape (const tagEntryInfo *const tag, const char *value CTAGS_ATTR_UNUSED, vString* b)
{
return renderAsIs (b, WITH_DEFUALT_VALUE (tag->extensionFields.signature));
}

static bool hasWhitespaceInSignature (const tagEntryInfo *const tag, const char *value CTAGS_ATTR_UNUSED)
{
return (tag->extensionFields.signature && strpbrk(tag->extensionFields.signature, " \t"))
? true
: false;
}

static const char *renderFieldScope (const tagEntryInfo *const tag, const char *value CTAGS_ATTR_UNUSED, vString* b)
{
const char* scope;
Expand Down
7 changes: 7 additions & 0 deletions main/vstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,11 @@ CTAGS_INLINE void vStringPut (vString *const string, const int c)
string->buffer [++string->length] = '\0';
}

CTAGS_INLINE void vStringPutWithLimit (vString *const string, const int c,
unsigned int maxlen)
{
if (vStringLength (string) < maxlen || maxlen == 0)
vStringPut (string, c);
}

#endif /* CTAGS_MAIN_VSTRING_H */
48 changes: 45 additions & 3 deletions parsers/cpreprocessor.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ typedef struct sCppState {
int * ungetPointer; /* the current unget char: points in the middle of the buffer */
int ungetDataSize; /* the number of valid unget characters in the buffer */

/* the contents of the last SYMBOL_CHAR or SYMBOL_STRING */
vString * charOrStringContents;

bool resolveRequired; /* must resolve if/else/elif/endif branch */
bool hasAtLiteralStrings; /* supports @"c:\" strings */
bool hasCxxRawLiteralStrings; /* supports R"xxx(...)xxx" strings */
Expand Down Expand Up @@ -169,6 +172,7 @@ static cppState Cpp = {
.ungetBufferSize = 0,
.ungetPointer = NULL,
.ungetDataSize = 0,
.charOrStringContents = NULL,
.resolveRequired = false,
.hasAtLiteralStrings = false,
.hasCxxRawLiteralStrings = false,
Expand Down Expand Up @@ -237,6 +241,9 @@ static void cppInitCommon(langType clientLang,
Cpp.ungetBuffer = NULL;
Cpp.ungetPointer = NULL;

CXX_DEBUG_ASSERT(!Cpp.charOrStringContents,"This string should be null when CPP is not initialized");
Cpp.charOrStringContents = vStringNew();

Cpp.resolveRequired = false;
Cpp.hasAtLiteralStrings = hasAtLiteralStrings;
Cpp.hasCxxRawLiteralStrings = hasCxxRawLiteralStrings;
Expand Down Expand Up @@ -316,6 +323,12 @@ extern void cppTerminate (void)
Cpp.ungetBuffer = NULL;
}

if(Cpp.charOrStringContents)
{
vStringDelete(Cpp.charOrStringContents);
Cpp.charOrStringContents = NULL;
}

Cpp.clientLang = LANG_IGNORE;
}

Expand Down Expand Up @@ -982,19 +995,34 @@ static int skipOverDComment (void)
return c;
}

const vString * cppGetLastCharOrStringContents (void)
{
CXX_DEBUG_ASSERT(Cpp.charOrStringContents,"Shouldn't be called when CPP is not initialized");
return Cpp.charOrStringContents;
}

/* Skips to the end of a string, returning a special character to
* symbolically represent a generic string.
*/
static int skipToEndOfString (bool ignoreBackslash)
{
int c;

vStringClear(Cpp.charOrStringContents);

while ((c = cppGetcFromUngetBufferOrFile ()) != EOF)
{
if (c == BACKSLASH && ! ignoreBackslash)
cppGetcFromUngetBufferOrFile (); /* throw away next character, too */
{
vStringPutWithLimit (Cpp.charOrStringContents, c, 1024);
c = cppGetcFromUngetBufferOrFile (); /* throw away next character, too */
if (c != EOF)
vStringPutWithLimit (Cpp.charOrStringContents, c, 1024);
}
else if (c == DOUBLE_QUOTE)
break;
else
vStringPutWithLimit (Cpp.charOrStringContents, c, 1024);
}
return STRING_SYMBOL; /* symbolic representation of string */
}
Expand Down Expand Up @@ -1052,16 +1080,23 @@ static int skipToEndOfCxxRawLiteralString (void)
* special character to symbolically represent a generic character.
* Also detects Vera numbers that include a base specifier (ie. 'b1010).
*/
static int skipToEndOfChar (void)
static int skipToEndOfChar ()
{
int c;
int count = 0, veraBase = '\0';

vStringClear(Cpp.charOrStringContents);

while ((c = cppGetcFromUngetBufferOrFile ()) != EOF)
{
++count;
if (c == BACKSLASH)
cppGetcFromUngetBufferOrFile (); /* throw away next character, too */
{
vStringPutWithLimit (Cpp.charOrStringContents, c, 10);
c = cppGetcFromUngetBufferOrFile (); /* throw away next character, too */
if (c != EOF)
vStringPutWithLimit (Cpp.charOrStringContents, c, 10);
}
else if (c == SINGLE_QUOTE)
break;
else if (c == NEWLINE)
Expand All @@ -1072,13 +1107,20 @@ static int skipToEndOfChar (void)
else if (Cpp.hasSingleQuoteLiteralNumbers)
{
if (count == 1 && strchr ("DHOB", toupper (c)) != NULL)
{
veraBase = c;
vStringPutWithLimit (Cpp.charOrStringContents, c, 10);
}
else if (veraBase != '\0' && ! isalnum (c))
{
cppUngetc (c);
break;
}
else
vStringPutWithLimit (Cpp.charOrStringContents, c, 10);
}
else
vStringPutWithLimit (Cpp.charOrStringContents, c, 10);
}
return CHAR_SYMBOL; /* symbolic representation of character */
}
Expand Down
1 change: 1 addition & 0 deletions parsers/cpreprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ extern void cppEndStatement (void);
extern void cppUngetc (const int c);
extern void cppUngetString(const char * string,int len);
extern int cppGetc (void);
extern const vString * cppGetLastCharOrStringContents (void);

/* notify the external parser state for the purpose of conditional
branch choice. The CXX parser stores the block level here. */
Expand Down
7 changes: 3 additions & 4 deletions parsers/cxx/cxx_parser_tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@

static void cxxParserSkipToNonWhiteSpace(void)
{
if(!cppIsspace(g_cxx.iChar))
return;
do
while(cppIsspace(g_cxx.iChar))
g_cxx.iChar = cppGetc();
while(cppIsspace(g_cxx.iChar));
}

enum CXXCharType
Expand Down Expand Up @@ -1366,6 +1363,7 @@ bool cxxParserParseNextToken(void)
{
t->eType = CXXTokenTypeStringConstant;
vStringPut(t->pszWord,'"');
vStringCat(t->pszWord,cppGetLastCharOrStringContents());
vStringPut(t->pszWord,'"');
g_cxx.iChar = cppGetc();
t->bFollowedBySpace = cppIsspace(g_cxx.iChar);
Expand Down Expand Up @@ -1413,6 +1411,7 @@ bool cxxParserParseNextToken(void)
{
t->eType = CXXTokenTypeCharacterConstant;
vStringPut(t->pszWord,'\'');
vStringCat(t->pszWord,cppGetLastCharOrStringContents());
vStringPut(t->pszWord,'\'');
g_cxx.iChar = cppGetc();
t->bFollowedBySpace = cppIsspace(g_cxx.iChar);
Expand Down

0 comments on commit b60a7b9

Please sign in to comment.