Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Mon, 15 Apr 2013 16:42:08 UTC Commit: f5d315809d0f219ad0e1770e0601b8c64f552ac6 https://github.com/geany/geany/commit/f5d315809d0f219ad0e1770e0601b8c64f552a...
Log Message: ----------- PHP: report visibility and implementation type
Report visibility (private/protected/public) and implementation (abstract or not) for every tag for which it makes sense.
Modified Paths: -------------- tagmanager/ctags/php.c
Modified: tagmanager/ctags/php.c 114 files changed, 103 insertions(+), 11 deletions(-) =================================================================== @@ -81,6 +81,19 @@ KEYWORD_xor } keywordId;
+typedef enum { + ACCESS_UNDEFINED, + ACCESS_PRIVATE, + ACCESS_PROTECTED, + ACCESS_PUBLIC, + COUNT_ACCESS +} accessType; + +typedef enum { + IMPL_UNDEFINED, + IMPL_ABSTRACT, + COUNT_IMPL +} implType;
typedef enum { K_CLASS, @@ -201,6 +214,12 @@
static boolean InPhp = FALSE; /* whether we are between <? ?> */
+/* current statement details */ +struct { + accessType access; + implType impl; +} CurrentStatement; +
static void buildPhpKeywordHash (void) { @@ -213,7 +232,33 @@ static void buildPhpKeywordHash (void) } }
-static void initPhpEntry (tagEntryInfo *e, const tokenInfo *const token, phpKind kind) +static const char *accessToString (const accessType access) +{ + static const char *const names[COUNT_ACCESS] = { + "undefined", + "private", + "protected", + "public" + }; + + Assert (access < COUNT_ACCESS); + + return names[access]; +} + +static const char *implToString (const implType impl) +{ + static const char *const names[COUNT_IMPL] = { + "undefined", + "abstract" + }; + + Assert (impl < COUNT_IMPL); + + return names[impl]; +} + +static void initPhpEntry (tagEntryInfo *e, const tokenInfo *const token, phpKind kind, accessType access) { initTagEntry (e, vStringValue (token->string));
@@ -222,6 +267,8 @@ static void initPhpEntry (tagEntryInfo *e, const tokenInfo *const token, phpKind e->kindName = PhpKinds[kind].name; e->kind = (char) PhpKinds[kind].letter;
+ if (access != ACCESS_UNDEFINED) + e->extensionFields.access = accessToString (access); if (vStringLength(token->scope) > 0) { Assert (token->parentKind >= 0); @@ -231,25 +278,43 @@ static void initPhpEntry (tagEntryInfo *e, const tokenInfo *const token, phpKind } }
-static void makeSimplePhpTag (tokenInfo *const token, phpKind kind) +static void makeSimplePhpTag (tokenInfo *const token, phpKind kind, accessType access) { if (PhpKinds[kind].enabled) { tagEntryInfo e;
- initPhpEntry (&e, token, kind); + initPhpEntry (&e, token, kind, access); makeTagEntry (&e); } }
-static void makeFunctionTag (tokenInfo *const token, vString *const arglist) +static void makeClassTag (tokenInfo *const token, implType impl) +{ + if (PhpKinds[K_CLASS].enabled) + { + tagEntryInfo e; + + initPhpEntry (&e, token, K_CLASS, ACCESS_UNDEFINED); + + if (impl != IMPL_UNDEFINED) + e.extensionFields.implementation = implToString (impl); + + makeTagEntry (&e); + } +} + +static void makeFunctionTag (tokenInfo *const token, vString *const arglist, + accessType access, implType impl) { if (PhpKinds[K_FUNCTION].enabled) { tagEntryInfo e;
- initPhpEntry (&e, token, K_FUNCTION); + initPhpEntry (&e, token, K_FUNCTION, access);
+ if (impl != IMPL_UNDEFINED) + e.extensionFields.implementation = implToString (impl); if (arglist) e.extensionFields.arglist = vStringValue (arglist);
@@ -604,6 +669,18 @@ static void readToken (tokenInfo *const token) } break; } + + if (token->type == TOKEN_SEMICOLON || + token->type == TOKEN_OPEN_CURLY || + token->type == TOKEN_CLOSE_CURLY) + { + /* reset current statement details on statement end, and when entering + * a deeper scope. + * it is a bit ugly to do this in readToken(), but it makes everything + * a lot simpler. */ + CurrentStatement.access = ACCESS_UNDEFINED; + CurrentStatement.impl = IMPL_UNDEFINED; + } }
static void enterScope (tokenInfo *const token, vString *const scope, int parentKind); @@ -611,6 +688,7 @@ static void readToken (tokenInfo *const token) static boolean parseClass (tokenInfo *const token) { boolean readNext = TRUE; + implType impl = CurrentStatement.impl; tokenInfo *name;
readToken (token); @@ -619,7 +697,7 @@ static boolean parseClass (tokenInfo *const token)
name = newToken (); copyToken (name, token, TRUE); - makeSimplePhpTag (name, K_CLASS); + makeClassTag (name, impl);
/* skip over possible "extends FOO, BAR" */ do @@ -642,6 +720,8 @@ static boolean parseClass (tokenInfo *const token) static boolean parseFunction (tokenInfo *const token) { boolean readNext = TRUE; + accessType access = CurrentStatement.access; + implType impl = CurrentStatement.impl; tokenInfo *name;
readToken (token); @@ -674,7 +754,7 @@ static boolean parseFunction (tokenInfo *const token) while (depth > 0 && c != EOF); vStringTerminate (arglist);
- makeFunctionTag (name, arglist); + makeFunctionTag (name, arglist, access, impl); vStringDelete (arglist);
readToken (token); /* normally it's an open brace */ @@ -704,7 +784,7 @@ static boolean parseConstant (tokenInfo *const token)
readToken (token); if (token->type == TOKEN_EQUAL_SIGN) - makeSimplePhpTag (name, K_DEFINE); + makeSimplePhpTag (name, K_DEFINE, ACCESS_UNDEFINED);
deleteToken (name);
@@ -726,7 +806,7 @@ static boolean parseDefine (tokenInfo *const token) if (token->type == TOKEN_STRING || token->type == TOKEN_IDENTIFIER) { - makeSimplePhpTag (token, K_DEFINE); + makeSimplePhpTag (token, K_DEFINE, ACCESS_UNDEFINED); readToken (token); }
@@ -755,8 +835,9 @@ static boolean parseDefine (tokenInfo *const token) * $var; */ static boolean parseVariable (tokenInfo *const token) { - boolean readNext = TRUE; tokenInfo *name; + boolean readNext = TRUE; + accessType access = CurrentStatement.access;
/* don't generate variable tags inside functions */ if (token->parentKind == K_FUNCTION) @@ -767,7 +848,7 @@ static boolean parseVariable (tokenInfo *const token)
readToken (token); if (token->type == TOKEN_EQUAL_SIGN || token->type == TOKEN_SEMICOLON) - makeSimplePhpTag (name, K_VARIABLE); + makeSimplePhpTag (name, K_VARIABLE, access); else readNext = FALSE;
@@ -808,6 +889,14 @@ static void enterScope (tokenInfo *const parentToken, vString *const extraScope, case KEYWORD_function: readNext = parseFunction (token); break; case KEYWORD_const: readNext = parseConstant (token); break; case KEYWORD_define: readNext = parseDefine (token); break; + + case KEYWORD_private: CurrentStatement.access = ACCESS_PRIVATE; break; + case KEYWORD_protected: CurrentStatement.access = ACCESS_PROTECTED; break; + case KEYWORD_public: CurrentStatement.access = ACCESS_PUBLIC; break; + case KEYWORD_var: CurrentStatement.access = ACCESS_PUBLIC; break; + + case KEYWORD_abstract: CurrentStatement.impl = IMPL_ABSTRACT; break; + default: break; } break; @@ -833,6 +922,9 @@ static void findPhpTags (void) tokenInfo *const token = newToken ();
InPhp = FALSE; + CurrentStatement.access = ACCESS_UNDEFINED; + CurrentStatement.impl = IMPL_UNDEFINED; + do { enterScope (token, NULL, -1);
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).