Skip to content

Commit

Permalink
Merge pull request #1564 from masatake/overhaul-cpreproc-cxx-relation
Browse files Browse the repository at this point in the history
Overhaul cpreproc and cxx(and other client parsers)  relation
  • Loading branch information
masatake authored Oct 4, 2017
2 parents 7317871 + 90da35f commit 924c0ab
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
See #1514.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--languages=-CPreProcessor
--kinds-C=-d

Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
int
main(int argc)
{
return X;
return X;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
See #1514.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--languages=-CPreProcessor
--kinds-CPreProcessor=-d

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
X input.c /^#define X /;" d file:
main input.c /^main(int argc)$/;" f typeref:typename:int
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#define X 1

int
main(int argc)
{
return X;
}
1 change: 1 addition & 0 deletions Units/parser-cpreprocessor.r/disable-cpp-client.d/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
See #1514.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
X input.c /^#define X /;" d file:
main input.c /^main(int argc)$/;" f typeref:typename:int
7 changes: 7 additions & 0 deletions Units/parser-cpreprocessor.r/disable-cpp-client.d/input.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#define X 1

int
main(int argc)
{
return X;
}
1 change: 1 addition & 0 deletions Units/parser-cpreprocessor.r/disable-cpp-cpp.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--languages=-CPreProcessor
3 changes: 3 additions & 0 deletions Units/parser-cpreprocessor.r/disable-cpp-cpp.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0x00 input.dts /^ phandle = <0x00>;$/;" p label:label
label input.dts /^label: test {$/;" l
label2 input.dts /^ label2: chosen { } ;$/;" l label:label
12 changes: 12 additions & 0 deletions Units/parser-cpreprocessor.r/disable-cpp-cpp.d/input.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/dts-v1/;

#include "foo.dtsi"
#define bar 98

label: test {
dummy {
label2: chosen { } ;
phandle = <0x00>;
};
};
#undef bar
113 changes: 78 additions & 35 deletions parsers/cpreprocessor.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ enum eState {
*/
typedef struct sCppState {
langType lang;
langType clientLang;

int * ungetBuffer; /* memory buffer for unget characters */
int ungetBufferSize; /* the current unget buffer size */
Expand Down Expand Up @@ -157,26 +158,34 @@ void cppPopExternalParserBlock()


static cppState Cpp = {
LANG_IGNORE,
NULL, /* ungetBuffer */
0, /* ungetBufferSize */
NULL, /* ungetPointer */
0, /* ungetDataSize */
false, /* resolveRequired */
false, /* hasAtLiteralStrings */
false, /* hasCxxRawLiteralStrings */
false, /* hasSingleQuoteLiteralNumbers */
NULL, /* defineMacroKind */
.macroUndefRoleIndex = ROLE_INDEX_DEFINITION,
NULL, /* headerKind */
.lang = LANG_IGNORE,
.clientLang = LANG_IGNORE,
.ungetBuffer = NULL,
.ungetBufferSize = 0,
.ungetPointer = NULL,
.ungetDataSize = 0,
.resolveRequired = false,
.hasAtLiteralStrings = false,
.hasCxxRawLiteralStrings = false,
.hasSingleQuoteLiteralNumbers = false,
.defineMacroKind = NULL,
.macroUndefRoleIndex = ROLE_INDEX_DEFINITION,
.headerKind = NULL,
.headerSystemRoleIndex = ROLE_INDEX_DEFINITION,
.headerLocalRoleIndex = ROLE_INDEX_DEFINITION,
{
DRCTV_NONE, /* state */
false, /* accept */
NULL, /* tag name */
0, /* nestLevel */
{ {false,false,false,false} } /* ifdef array */
.directive = {
.state = DRCTV_NONE,
.accept = false,
.name = NULL,
.nestLevel = 0,
.ifdef = {
{
.ignoreAllBranches = false,
.singleBranch = false,
.singleBranch = false,
.ignoring = false,
}
}
} /* directive */
};

Expand All @@ -194,7 +203,8 @@ extern unsigned int cppGetDirectiveNestLevel (void)
return Cpp.directive.nestLevel;
}

extern void cppInit (const bool state, const bool hasAtLiteralStrings,
static void cppInitCommon(langType clientLang,
const bool state, const bool hasAtLiteralStrings,
const bool hasCxxRawLiteralStrings,
const bool hasSingleQuoteLiteralNumbers,
const kindDefinition *defineMacroKind,
Expand All @@ -216,6 +226,7 @@ extern void cppInit (const bool state, const bool hasAtLiteralStrings,
initializeParser (t);
}

Cpp.clientLang = clientLang;
Cpp.ungetBuffer = NULL;
Cpp.ungetPointer = NULL;

Expand Down Expand Up @@ -246,6 +257,22 @@ extern void cppInit (const bool state, const bool hasAtLiteralStrings,
Cpp.directive.name = vStringNewOrClear (Cpp.directive.name);
}

extern void cppInit (const bool state, const bool hasAtLiteralStrings,
const bool hasCxxRawLiteralStrings,
const bool hasSingleQuoteLiteralNumbers,
const kindDefinition *defineMacroKind,
int macroUndefRoleIndex,
const kindDefinition *headerKind,
int headerSystemRoleIndex, int headerLocalRoleIndex)
{
langType client = getInputLanguage ();

cppInitCommon (client, state, hasAtLiteralStrings,
hasCxxRawLiteralStrings, hasSingleQuoteLiteralNumbers,
defineMacroKind, macroUndefRoleIndex, headerKind,
headerSystemRoleIndex, headerLocalRoleIndex);
}

extern void cppTerminate (void)
{
if (Cpp.directive.name != NULL)
Expand All @@ -259,6 +286,8 @@ extern void cppTerminate (void)
eFree(Cpp.ungetBuffer);
Cpp.ungetBuffer = NULL;
}

Cpp.clientLang = LANG_IGNORE;
}

extern void cppBeginStatement (void)
Expand Down Expand Up @@ -560,19 +589,35 @@ static bool popConditional (void)
return isIgnore ();
}

static bool doesCPreProRunAsStandaloneParser (int kind)
{
if (kind == CPREPRO_HEADER)
return (Cpp.headerKind == CPreProKinds + CPREPRO_HEADER);
else if (kind == CPREPRO_MACRO)
return (Cpp.defineMacroKind == CPreProKinds + CPREPRO_MACRO);
else
{
AssertNotReached();
return true;
}
}

static int makeDefineTag (const char *const name, const char* const signature, bool undef)
{
const bool isFileScope = (bool) (! isInputHeaderFile ());

if (!isLanguageEnabled (Cpp.lang))
return CORK_NIL;
if (!isLanguageEnabled (
doesCPreProRunAsStandaloneParser(CPREPRO_MACRO)
? Cpp.lang
: Cpp.clientLang))
return CORK_NIL;

if (!Cpp.defineMacroKind)
return CORK_NIL;
if (isFileScope && !isXtagEnabled(XTAG_FILE_SCOPE))
return CORK_NIL;

if (Cpp.macroUndefRoleIndex == ROLE_INDEX_DEFINITION)
if (undef && (Cpp.macroUndefRoleIndex == ROLE_INDEX_DEFINITION))
return CORK_NIL;

if ( /* condition for definition tag */
Expand All @@ -584,7 +629,7 @@ static int makeDefineTag (const char *const name, const char* const signature, b
tagEntryInfo e;
int r;

if (Cpp.defineMacroKind == CPreProKinds + CPREPRO_MACRO)
if (doesCPreProRunAsStandaloneParser(CPREPRO_MACRO))
pushLanguage (Cpp.lang);

if (undef)
Expand All @@ -600,26 +645,24 @@ static int makeDefineTag (const char *const name, const char* const signature, b

r = makeTagEntry (&e);

if (Cpp.defineMacroKind == CPreProKinds + CPREPRO_MACRO)
if (doesCPreProRunAsStandaloneParser(CPREPRO_MACRO))
popLanguage ();

return r;
}
return CORK_NIL;
}

static bool doesCPreProRunAsStandaloneParser (void)
{
return (Cpp.headerKind == CPreProKinds + CPREPRO_HEADER);
}

static void makeIncludeTag (const char *const name, bool systemHeader)
{
tagEntryInfo e;
int role_index;

if (!isLanguageEnabled (Cpp.lang))
return;
if (!isLanguageEnabled (
doesCPreProRunAsStandaloneParser(CPREPRO_HEADER)
? Cpp.lang
: Cpp.clientLang))
return;

role_index = systemHeader? Cpp.headerSystemRoleIndex: Cpp.headerLocalRoleIndex;
if (role_index == ROLE_INDEX_DEFINITION)
Expand All @@ -629,15 +672,15 @@ static void makeIncludeTag (const char *const name, bool systemHeader)
&& isXtagEnabled (XTAG_REFERENCE_TAGS)
&& Cpp.headerKind->roles [ role_index ].enabled)
{
if (doesCPreProRunAsStandaloneParser ())
if (doesCPreProRunAsStandaloneParser (CPREPRO_HEADER))
pushLanguage (Cpp.lang);

initRefTagEntry (&e, name, Cpp.headerKind, role_index);
e.isFileScope = false;
e.truncateLineAfterTag = true;
makeTagEntry (&e);

if (doesCPreProRunAsStandaloneParser ())
if (doesCPreProRunAsStandaloneParser (CPREPRO_HEADER))
popLanguage ();
}
}
Expand Down Expand Up @@ -1239,8 +1282,8 @@ extern int cppGetc (void)

static void findCppTags (void)
{
cppInit (0, false, false, false,
NULL, 0, NULL, 0, 0);
cppInitCommon (Cpp.lang, 0, false, false, false,
NULL, 0, NULL, 0, 0);

findRegexTagsMainloop (cppGetc);

Expand Down

0 comments on commit 924c0ab

Please sign in to comment.