Skip to content

Commit

Permalink
PHP: parse and report interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
b4n committed Apr 12, 2013
1 parent a51f1a4 commit cba0b7d
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions php.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,17 @@ typedef enum {
K_CLASS,
K_DEFINE,
K_FUNCTION,
K_INTERFACE,
K_VARIABLE,
COUNT_KIND
} phpKind;

static kindOption PhpKinds[COUNT_KIND] = {
{ TRUE, 'c', "class", "classes" },
{ TRUE, 'd', "define", "constant definitions" },
{ TRUE, 'f', "function", "functions" },
{ TRUE, 'v', "variable", "variables" }
{ TRUE, 'c', "class", "classes" },
{ TRUE, 'd', "define", "constant definitions" },
{ TRUE, 'f', "function", "functions" },
{ TRUE, 'i', "interface", "interfaces" },
{ TRUE, 'v', "variable", "variables" }
};

typedef struct {
Expand Down Expand Up @@ -292,13 +294,14 @@ static void makeSimplePhpTag (tokenInfo *const token, phpKind kind, accessType a
}
}

static void makeClassTag (tokenInfo *const token, vString *const inheritance, implType impl)
static void makeClassOrIfaceTag (phpKind kind, tokenInfo *const token,
vString *const inheritance, implType impl)
{
if (PhpKinds[K_CLASS].enabled)
if (PhpKinds[kind].enabled)
{
tagEntryInfo e;

initPhpEntry (&e, token, K_CLASS, ACCESS_UNDEFINED);
initPhpEntry (&e, token, kind, ACCESS_UNDEFINED);

if (impl != IMPL_UNDEFINED)
e.extensionFields.implementation = implToString (impl);
Expand Down Expand Up @@ -680,7 +683,13 @@ static void readToken (tokenInfo *const token)

static void enterScope (tokenInfo *const token, vString *const scope, int parentKind);

static boolean parseClass (tokenInfo *const token)
/* parses a class or an interface:
* class Foo {}
* class Foo extends Bar {}
* class Foo extends Bar implements iFoo, iBar {}
* interface iFoo {}
* interface iBar extends iFoo {} */
static boolean parseClassOrIface (tokenInfo *const token, phpKind kind)
{
boolean readNext = TRUE;
implType impl = CurrentStatement.impl;
Expand Down Expand Up @@ -711,7 +720,7 @@ static boolean parseClass (tokenInfo *const token)
while (token->type != TOKEN_EOF &&
token->type != TOKEN_OPEN_CURLY);

makeClassTag (name, inheritance, impl);
makeClassOrIfaceTag (kind, name, inheritance, impl);

if (token->type == TOKEN_OPEN_CURLY)
enterScope (token, name->string, K_CLASS);
Expand Down Expand Up @@ -892,10 +901,11 @@ static void enterScope (tokenInfo *const parentToken, vString *const extraScope,
case TOKEN_KEYWORD:
switch (token->keyword)
{
case KEYWORD_class: readNext = parseClass (token); break;
case KEYWORD_function: readNext = parseFunction (token); break;
case KEYWORD_const: readNext = parseConstant (token); break;
case KEYWORD_define: readNext = parseDefine (token); break;
case KEYWORD_class: readNext = parseClassOrIface (token, K_CLASS); break;
case KEYWORD_interface: readNext = parseClassOrIface (token, K_INTERFACE); break;
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;
Expand Down

0 comments on commit cba0b7d

Please sign in to comment.