diff --git a/entry.c b/entry.c index aad0067..61ef009 100644 --- a/entry.c +++ b/entry.c @@ -761,6 +761,11 @@ static int addExtensionFields (const tagEntryInfo *const tag) length += fprintf (TagFile.fp, "%s\tsignature:%s", sep, tag->extensionFields.signature); + if (Option.extensionFields.docblock && + tag->extensionFields.docblock != NULL) + length += fprintf (TagFile.fp, "%s\tdocblock:%s", sep, + tag->extensionFields.docblock); + return length; #undef sep } diff --git a/entry.h b/entry.h index 0ba758f..b261c57 100644 --- a/entry.h +++ b/entry.h @@ -72,6 +72,7 @@ typedef struct sTagEntryInfo { const char* inheritance; const char* scope [2]; /* value and key */ const char* signature; + const char* docblock; /* type (union/struct/etc.) and name for a variable or typedef. */ const char* typeRef [2]; /* e.g., "struct" and struct name */ diff --git a/options.c b/options.c index e0d874f..4f9b6fb 100644 --- a/options.c +++ b/options.c @@ -119,7 +119,8 @@ optionValues Option = { FALSE, /* -fields=n */ TRUE, /* -fields=s */ FALSE, /* -fields=S */ - TRUE /* -fields=t */ + TRUE, /* -fields=t */ + FALSE /* -fields=d */ }, NULL, /* -I */ FALSE, /* -a */ @@ -208,7 +209,7 @@ static optionDescription LongOptionDescription [] = { {1," --extra=[+|-]flags"}, {1," Include extra tag entries for selected information (flags: \"fq\")."}, {1," --fields=[+|-]flags"}, - {1," Include selected extension fields (flags: \"afmikKlnsStz\") [fks]."}, + {1," Include selected extension fields (flags: \"afmikKlnsStzd\") [fks]."}, {1," --file-scope=[yes|no]"}, {1," Should tags scoped only for a single file (e.g. \"static\" tags"}, {1," be included in the output [yes]?"}, @@ -859,6 +860,7 @@ static void processFieldsOption ( case 'S': field->signature = mode; break; case 'z': field->kindKey = mode; break; case 't': field->typeRef = mode; break; + case 'd': field->docblock = mode; break; default: error(WARNING, "Unsupported parameter '%c' for \"%s\" option", c, option); diff --git a/options.h b/options.h index e2467f5..ec58848 100644 --- a/options.h +++ b/options.h @@ -78,6 +78,7 @@ struct sExtFields { /* extension field content control */ boolean scope; boolean signature; boolean typeRef; + boolean docblock; }; /* This stores the command line options. diff --git a/php.c b/php.c index f4ccd1a..48353dc 100644 --- a/php.c +++ b/php.c @@ -22,6 +22,7 @@ #include "routines.h" #include "debug.h" +#include #define SCOPE_SEPARATOR "::" @@ -237,6 +238,7 @@ static boolean InPhp = FALSE; /* whether we are between */ struct { accessType access; implType impl; + vString* docblock; } CurrentStatement; /* Current namespace */ @@ -280,8 +282,32 @@ static const char *implToString (const implType impl) return names[impl]; } +static void encodeDocBlock (vString *const encoded, vString const *docblock) +{ + int i, len; + char *buff, c; + buff = vStringValue (docblock); + len = strlen (buff); + + vStringClear (encoded); + + for (i = 0; i < len; ++i) { + c = buff[i]; + if (c == '\n') + vStringCatS (encoded, "\\n"); + else if (c == '\r') + vStringCatS (encoded, "\\r"); + else if (c == '\t') + vStringCatS (encoded, "\\t"); + else + vStringPut (encoded, c); + + } + vStringTerminate (encoded); +} + static void initPhpEntry (tagEntryInfo *const e, const tokenInfo *const token, - const phpKind kind, const accessType access) + const phpKind kind, const accessType access, vString *const docblock) { static vString *fullScope = NULL; int parentKind = -1; @@ -321,6 +347,10 @@ static void initPhpEntry (tagEntryInfo *const e, const tokenInfo *const token, e->extensionFields.scope[0] = PhpKinds[parentKind].name; e->extensionFields.scope[1] = vStringValue (fullScope); } + if (vStringLength (docblock) > 0) + { + e->extensionFields.docblock = vStringValue (docblock); + } } static void makeSimplePhpTag (const tokenInfo *const token, const phpKind kind, @@ -330,7 +360,7 @@ static void makeSimplePhpTag (const tokenInfo *const token, const phpKind kind, { tagEntryInfo e; - initPhpEntry (&e, token, kind, access); + initPhpEntry (&e, token, kind, access, CurrentStatement.docblock); makeTagEntry (&e); } } @@ -359,7 +389,7 @@ static void makeClassOrIfaceTag (const phpKind kind, const tokenInfo *const toke { tagEntryInfo e; - initPhpEntry (&e, token, kind, ACCESS_UNDEFINED); + initPhpEntry (&e, token, kind, ACCESS_UNDEFINED, CurrentStatement.docblock); if (impl != IMPL_UNDEFINED) e.extensionFields.implementation = implToString (impl); @@ -373,12 +403,12 @@ static void makeClassOrIfaceTag (const phpKind kind, const tokenInfo *const toke static void makeFunctionTag (const tokenInfo *const token, const vString *const arglist, const accessType access, const implType impl) -{ +{ if (PhpKinds[K_FUNCTION].enabled) { tagEntryInfo e; - initPhpEntry (&e, token, K_FUNCTION, access); + initPhpEntry (&e, token, K_FUNCTION, access, CurrentStatement.docblock); if (impl != IMPL_UNDEFINED) e.extensionFields.implementation = implToString (impl); @@ -514,6 +544,18 @@ static int skipToCharacter (const int c) return d; } +static int collectToCharacter (vString *const string, const int c) +{ + int d; + do + { + d = fileGetc (); + vStringPut (string, (char) d); + } while (d != EOF && d != c); + vStringTerminate (string); + return d; +} + static void parseString (vString *const string, const int delimiter) { while (TRUE) @@ -673,7 +715,7 @@ static int skipWhitespaces (int c) } /* - * + * * This is ugly, but the whole "