1d4c6f1e6SMasatake YAMATO /* 2d4c6f1e6SMasatake YAMATO * Copyright (c) 1998-2002, Darren Hiebert 3d4c6f1e6SMasatake YAMATO * 4d4c6f1e6SMasatake YAMATO * This source code is released for free distribution under the terms of the 50ce38835Sviccuad * GNU General Public License version 2 or (at your option) any later version. 6d4c6f1e6SMasatake YAMATO * 7d4c6f1e6SMasatake YAMATO * External interface to entry.c 8d4c6f1e6SMasatake YAMATO */ 95474c2e5SMasatake YAMATO #ifndef CTAGS_MAIN_ENTRY_H 105474c2e5SMasatake YAMATO #define CTAGS_MAIN_ENTRY_H 11d4c6f1e6SMasatake YAMATO 12d4c6f1e6SMasatake YAMATO /* 13d4c6f1e6SMasatake YAMATO * INCLUDE FILES 14d4c6f1e6SMasatake YAMATO */ 15d4c6f1e6SMasatake YAMATO #include "general.h" /* must always come first */ 16c645eb4cSMasatake YAMATO #include "types.h" 17d4c6f1e6SMasatake YAMATO 188a3d009fSMasatake YAMATO #include <stdint.h> 19c314f261SMasatake YAMATO #include <time.h> 20d4c6f1e6SMasatake YAMATO 21cc2cd3ceSMasatake YAMATO #include "field.h" 2226355fc4SMasatake YAMATO #include "xtag.h" 23509a47dbSJiří Techet #include "mio.h" 243b6b66a2SMasatake YAMATO #include "ptrarray.h" 25f64f1867SMasatake YAMATO #include "nestlevel.h" 26d4c6f1e6SMasatake YAMATO 27d4c6f1e6SMasatake YAMATO /* 28d4c6f1e6SMasatake YAMATO * MACROS 29d4c6f1e6SMasatake YAMATO */ 30d4c6f1e6SMasatake YAMATO 31d4c6f1e6SMasatake YAMATO /* 32d4c6f1e6SMasatake YAMATO * DATA DECLARATIONS 33d4c6f1e6SMasatake YAMATO */ 34cc2cd3ceSMasatake YAMATO typedef struct sTagField { 35cc2cd3ceSMasatake YAMATO fieldType ftype; 36cc2cd3ceSMasatake YAMATO const char* value; 374e9e52c2SMasatake YAMATO bool valueOwner; /* used only in parserFieldsDynamic */ 38cc2cd3ceSMasatake YAMATO } tagField; 39d4c6f1e6SMasatake YAMATO 409062cbc8SMasatake YAMATO typedef uint64_t roleBitsType; 419062cbc8SMasatake YAMATO 42d4c6f1e6SMasatake YAMATO /* Information about the current tag candidate. 43d4c6f1e6SMasatake YAMATO */ 44135b4bc5SMasatake YAMATO struct sTagEntryInfo { 451a16f591SMasatake YAMATO unsigned int lineNumberEntry:1; /* pattern or line number entry */ 46800ba473SMasatake YAMATO unsigned int isFileScope :1; /* is tag visible only within input file? */ 471a16f591SMasatake YAMATO unsigned int isFileEntry :1; /* is this just an entry for a file name? */ 480e70b227SMasatake YAMATO unsigned int truncateLineAfterTag :1; /* truncate tag line at end of tag name? */ 49781d438bSMasatake YAMATO unsigned int placeholder :1; /* is used only for keeping corkIndex based scope chain. 501a16f591SMasatake YAMATO Put this entry to cork queue but 511a16f591SMasatake YAMATO don't print it to tags file. */ 528ee65243SMasatake YAMATO unsigned int skipAutoFQEmission:1; /* If a parser makes a fq tag for the 538ee65243SMasatake YAMATO current tag by itself, set this. */ 54b9636b4dSMasatake YAMATO unsigned int isPseudoTag:1; /* Used only in xref output. 55b9636b4dSMasatake YAMATO If a tag is a pseudo, set this. */ 56a80686c6SMasatake YAMATO unsigned int inCorkQueue:1; 571a16f591SMasatake YAMATO 58d4c6f1e6SMasatake YAMATO unsigned long lineNumber; /* line number of tag */ 59800ba473SMasatake YAMATO const char* pattern; /* pattern for locating input line 60d4c6f1e6SMasatake YAMATO * (may be NULL if not present) *//* */ 61a0c1e6d7SMasatake YAMATO unsigned int boundaryInfo; /* info about nested input stream */ 62509a47dbSJiří Techet MIOPos filePosition; /* file position of line containing tag */ 635b177cc6SMasatake YAMATO langType langType; /* language of input file */ 64800ba473SMasatake YAMATO const char *inputFileName; /* name of input file */ 65d4c6f1e6SMasatake YAMATO const char *name; /* name of the tag */ 66f92e6bf2SMasatake YAMATO int kindIndex; /* kind descriptor */ 678a3d009fSMasatake YAMATO uint8_t extra[ ((XTAG_COUNT) / 8) + 1 ]; 68fdf86b79SMasatake YAMATO uint8_t *extraDynamic; /* Dynamically allocated but freed by per parser TrashBox */ 6926355fc4SMasatake YAMATO 70d4c6f1e6SMasatake YAMATO struct { 71d4c6f1e6SMasatake YAMATO const char* access; 72d4c6f1e6SMasatake YAMATO const char* implementation; 73d4c6f1e6SMasatake YAMATO const char* inheritance; 7403a7d9efSMasatake YAMATO 753dbbc8deSMasatake YAMATO /* Which scopeKindIndex belong to. If the value is LANG_AUTO, 763dbbc8deSMasatake YAMATO the value for langType field of this structure is used as default value. 773dbbc8deSMasatake YAMATO LANG_AUTO is set automatically in initTagEntryInfo. */ 783dbbc8deSMasatake YAMATO langType scopeLangType; 79f92e6bf2SMasatake YAMATO int scopeKindIndex; 80015ab54cSMasatake YAMATO const char* scopeName; 813b5d9090SMasatake YAMATO int scopeIndex; /* cork queue entry for upper scope tag. 8203a7d9efSMasatake YAMATO This field is meaningful if the value 83f6027918SMasatake YAMATO is not CORK_NIL and scope[0] and scope[1] are 8403a7d9efSMasatake YAMATO NULL. */ 8503a7d9efSMasatake YAMATO 86d4c6f1e6SMasatake YAMATO const char* signature; 87d4c6f1e6SMasatake YAMATO 88d4c6f1e6SMasatake YAMATO /* type (union/struct/etc.) and name for a variable or typedef. */ 89d4c6f1e6SMasatake YAMATO const char* typeRef [2]; /* e.g., "struct" and struct name */ 90d4c6f1e6SMasatake YAMATO 9124b256e3SMasatake YAMATO #define ROLE_DEFINITION_INDEX -1 9224b256e3SMasatake YAMATO #define ROLE_DEFINITION_NAME "def" 939062cbc8SMasatake YAMATO #define ROLE_MAX_COUNT (sizeof(roleBitsType) * 8) 949062cbc8SMasatake YAMATO roleBitsType roleBits; /* for role of reference tag */ 9576a4ccb4SMasatake YAMATO 9676a4ccb4SMasatake YAMATO #ifdef HAVE_LIBXML 9776a4ccb4SMasatake YAMATO const char* xpath; 9876a4ccb4SMasatake YAMATO #endif 99d82a3cd2SMasatake YAMATO unsigned long endLine; 100c314f261SMasatake YAMATO time_t epoch; 101f0a23ab8SMasatake YAMATO #define NO_NTH_FIELD -1 102f0a23ab8SMasatake YAMATO short nth; 103d4c6f1e6SMasatake YAMATO } extensionFields; /* list of extension fields*/ 104a39098b3SMasatake YAMATO 10546ab94ccSMasatake YAMATO /* `usedParserFields' tracks how many parser own fields are 10646ab94ccSMasatake YAMATO used. If it is a few (less than PRE_ALLOCATED_PARSER_FIELDS), 10746ab94ccSMasatake YAMATO statically allocated parserFields is used. If more fields than 10846ab94ccSMasatake YAMATO PRE_ALLOCATED_PARSER_FIELDS is defined and attached, parserFieldsDynamic 10946ab94ccSMasatake YAMATO is used. */ 11046ab94ccSMasatake YAMATO unsigned int usedParserFields; 1110e5438a3SSzymon Tomasz Stefanek #define PRE_ALLOCATED_PARSER_FIELDS 5 112cc2cd3ceSMasatake YAMATO #define NO_PARSER_FIELD -1 113cc2cd3ceSMasatake YAMATO tagField parserFields [PRE_ALLOCATED_PARSER_FIELDS]; 1144e9e52c2SMasatake YAMATO ptrArray * parserFieldsDynamic; 115cc2cd3ceSMasatake YAMATO 116a39098b3SMasatake YAMATO /* Following source* fields are used only when #line is found 117a39098b3SMasatake YAMATO in input and --line-directive is given in ctags command line. */ 1185bd00ccbSMasatake YAMATO langType sourceLangType; 119a39098b3SMasatake YAMATO const char *sourceFileName; 120a39098b3SMasatake YAMATO unsigned long sourceLineNumberDifference; 121135b4bc5SMasatake YAMATO }; 122d4c6f1e6SMasatake YAMATO 1233afb5475SMasatake YAMATO typedef bool (* entryForeachFunc) (int corkIndex, 124363a6369SMasatake YAMATO tagEntryInfo * entry, 125363a6369SMasatake YAMATO void * data); 126948f988eSMasatake YAMATO 127d4c6f1e6SMasatake YAMATO /* 128d4c6f1e6SMasatake YAMATO * GLOBAL VARIABLES 129d4c6f1e6SMasatake YAMATO */ 130ccb510caSMasatake YAMATO 131d4c6f1e6SMasatake YAMATO 132d4c6f1e6SMasatake YAMATO /* 133d4c6f1e6SMasatake YAMATO * FUNCTION PROTOTYPES 134d4c6f1e6SMasatake YAMATO */ 135d508a2aaSMasatake YAMATO extern int makeTagEntry (const tagEntryInfo *const tag); 13698392b01SMasatake YAMATO extern void initTagEntry (tagEntryInfo *const e, const char *const name, 13716a2541cSMasatake YAMATO int kindIndex); 138e2755fdeSMasatake YAMATO extern void initRefTagEntry (tagEntryInfo *const e, const char *const name, 13916a2541cSMasatake YAMATO int kindIndex, int roleIndex); 140d86d3772SMasatake YAMATO 141d86d3772SMasatake YAMATO /* initForeignRefTagEntry() is for making a tag for the language X when parsing 142d86d3772SMasatake YAMATO * source code of Y language. 143d86d3772SMasatake YAMATO * From the view point of the language Y, we call the language X a foreign 144d86d3772SMasatake YAMATO * language. 145d86d3772SMasatake YAMATO * 146d86d3772SMasatake YAMATO * When making a tag for a foreign with this function, you must declare the 147d86d3772SMasatake YAMATO * language X in the parser of Y with DEPTYPE_FOREIGNER dependency. 148d86d3772SMasatake YAMATO */ 149501796e2SMasatake YAMATO extern void initForeignTagEntry (tagEntryInfo *const e, const char *const name, 150501796e2SMasatake YAMATO langType type, 151501796e2SMasatake YAMATO int kindIndex); 1520f2baf3cSMasatake YAMATO extern void initForeignRefTagEntry (tagEntryInfo *const e, const char *const name, 1530f2baf3cSMasatake YAMATO langType type, 1540f2baf3cSMasatake YAMATO int kindIndex, int roleIndex); 1559062cbc8SMasatake YAMATO extern void assignRole(tagEntryInfo *const e, int roleIndex); 1569062cbc8SMasatake YAMATO extern bool isRoleAssigned(const tagEntryInfo *const e, int roleIndex); 1579062cbc8SMasatake YAMATO 158509be916SMasatake YAMATO extern int makeQualifiedTagEntry (const tagEntryInfo *const e); 159d4c6f1e6SMasatake YAMATO 160d21b8e79SMasatake YAMATO extern void setTagPositionFromTag (tagEntryInfo *const dst, const tagEntryInfo *const src); 161d4c6f1e6SMasatake YAMATO 162f6027918SMasatake YAMATO #define CORK_NIL 0 1633afb5475SMasatake YAMATO tagEntryInfo *getEntryInCorkQueue (int n); 164885fbc2cSMasatake YAMATO tagEntryInfo *getEntryOfNestingLevel (const NestingLevel *nl); 165d508a2aaSMasatake YAMATO size_t countEntryInCorkQueue (void); 166d508a2aaSMasatake YAMATO 167363a6369SMasatake YAMATO /* If a parser sets (CORK_QUEUE and )CORK_SYMTAB to useCork, 168363a6369SMasatake YAMATO * the parsesr can use symbol lookup tables for the current input. 169363a6369SMasatake YAMATO * Each scope has a symbol lookup table. 170363a6369SMasatake YAMATO * To register an tag to the table, use registerEntry(). 171363a6369SMasatake YAMATO * registerEntry registers CORKINDEX to a symbol table of a parent tag 172363a6369SMasatake YAMATO * specified in the scopeIndex field of the tag specified with CORKINDEX. 173363a6369SMasatake YAMATO */ 1743afb5475SMasatake YAMATO void registerEntry (int corkIndex); 175fe516ceeSMasatake YAMATO void unregisterEntry (int corkIndex); 176363a6369SMasatake YAMATO 177363a6369SMasatake YAMATO /* foreachEntriesInScope is for traversing the symbol table for a table 178363a6369SMasatake YAMATO * specified with CORKINDEX. If CORK_NIL is given, this function traverses 179363a6369SMasatake YAMATO * top-level entries. If name is NULL, this function traverses all entries 180363a6369SMasatake YAMATO * under the scope. 181a3a96dcfSMasatake YAMATO * 182db72c557SMasatake YAMATO * If FUNC returns false, this function returns false immediately 183db72c557SMasatake YAMATO * even if more entires in the scope. 1847c0f811aSMasatake YAMATO * If FUNC never returns false, this function returns true. 1857c0f811aSMasatake YAMATO * If FUNC is not called because no node for NAME in the symbol table, 1867c0f811aSMasatake YAMATO * this function returns true. 187363a6369SMasatake YAMATO */ 1883afb5475SMasatake YAMATO bool foreachEntriesInScope (int corkIndex, 189363a6369SMasatake YAMATO const char *name, /* or NULL */ 190363a6369SMasatake YAMATO entryForeachFunc func, 191363a6369SMasatake YAMATO void *data); 192363a6369SMasatake YAMATO 19375029907SMasatake YAMATO /* Return the cork index for NAME in the scope specified with CORKINDEX. 19475029907SMasatake YAMATO * Even if more than one entries for NAME are in the scope, this function 19575029907SMasatake YAMATO * just returns one of them. Returning CORK_NIL means there is no entry 19675029907SMasatake YAMATO * for NAME. 19775029907SMasatake YAMATO */ 1983afb5475SMasatake YAMATO int anyEntryInScope (int corkIndex, 199*aaaac7eeSMasatake YAMATO const char *name, 200*aaaac7eeSMasatake YAMATO bool onlyDefinitionTag); 20175029907SMasatake YAMATO 2028495757aSMasatake YAMATO int anyKindEntryInScope (int corkIndex, 203*aaaac7eeSMasatake YAMATO const char *name, int kind, 204*aaaac7eeSMasatake YAMATO bool onlyDefinitionTag); 2058495757aSMasatake YAMATO 2068495757aSMasatake YAMATO int anyKindsEntryInScope (int corkIndex, 2078495757aSMasatake YAMATO const char *name, 208*aaaac7eeSMasatake YAMATO const int * kinds, int count, 209*aaaac7eeSMasatake YAMATO bool onlyDefinitionTag); 2108495757aSMasatake YAMATO 211b8a2bc77SMasatake YAMATO int anyKindsEntryInScopeRecursive (int corkIndex, 212b8a2bc77SMasatake YAMATO const char *name, 213*aaaac7eeSMasatake YAMATO const int * kinds, int count, 214*aaaac7eeSMasatake YAMATO bool onlyDefinitionTag); 215b8a2bc77SMasatake YAMATO 21626355fc4SMasatake YAMATO extern void markTagExtraBit (tagEntryInfo *const tag, xtagType extra); 217ebbfee1eSDavid Yu Yang extern void unmarkTagExtraBit (tagEntryInfo *const tag, xtagType extra); 218ce990805SThomas Braun extern bool isTagExtraBitMarked (const tagEntryInfo *const tag, xtagType extra); 21926355fc4SMasatake YAMATO 220522de3f2SMasatake YAMATO /* If any extra bit is on, return true. */ 221522de3f2SMasatake YAMATO extern bool isTagExtra (const tagEntryInfo *const tag); 222522de3f2SMasatake YAMATO 22399fdd164SMasatake YAMATO /* Functions for attaching parser specific fields 224464894a0SMasatake YAMATO * 225322d6c7bSMasatake YAMATO * Which function you should use? 226322d6c7bSMasatake YAMATO * ------------------------------ 22799fdd164SMasatake YAMATO * Case A: 228464894a0SMasatake YAMATO * 22999fdd164SMasatake YAMATO * If your parser uses the Cork API, and your parser called 23099fdd164SMasatake YAMATO * makeTagEntry () already, you can use both 23199fdd164SMasatake YAMATO * attachParserFieldToCorkEntry () and attachParserField (). Your 23299fdd164SMasatake YAMATO * parser has the cork index returned from makeTagEntry (). With the 23399fdd164SMasatake YAMATO * cork index, your parser can call attachParserFieldToCorkEntry (). 23499fdd164SMasatake YAMATO * If your parser already call getEntryInCorkQueue () to get the tag 23599fdd164SMasatake YAMATO * entry for the cork index, your parser can call attachParserField () 23699fdd164SMasatake YAMATO * with passing true for `inCorkQueue' parameter. attachParserField () 23799fdd164SMasatake YAMATO * is a bit faster than attachParserFieldToCorkEntry (). 23899fdd164SMasatake YAMATO * 23999fdd164SMasatake YAMATO * attachParserField () and attachParserFieldToCorkEntry () duplicates 24099fdd164SMasatake YAMATO * the memory object specified with `value' and stores the duplicated 24199fdd164SMasatake YAMATO * object to the entry on the cork queue. So the parser must/can free 24299fdd164SMasatake YAMATO * the original one passed to the functions after calling. The cork 24399fdd164SMasatake YAMATO * queue manages the life of the duplicated object. It is not the 24499fdd164SMasatake YAMATO * parser's concern. 24599fdd164SMasatake YAMATO * 24699fdd164SMasatake YAMATO * 24799fdd164SMasatake YAMATO * Case B: 24899fdd164SMasatake YAMATO * 24999fdd164SMasatake YAMATO * If your parser called one of initTagEntry () family but didn't call 25099fdd164SMasatake YAMATO * makeTagEntry () for a tagEntry yet, use attachParserField () with 25199fdd164SMasatake YAMATO * false for `inCorkQueue' whether your parser uses the Cork API or 25299fdd164SMasatake YAMATO * not. 25399fdd164SMasatake YAMATO * 25499fdd164SMasatake YAMATO * The parser (== caller) keeps the memory object specified with `value' 25599fdd164SMasatake YAMATO * till calling makeTagEntry (). The parser must free the memory object 25699fdd164SMasatake YAMATO * after calling makeTagEntry () if it is allocated dynamically in the 25799fdd164SMasatake YAMATO * parser side. 258322d6c7bSMasatake YAMATO * 259322d6c7bSMasatake YAMATO * Interpretation of VALUE 260322d6c7bSMasatake YAMATO * ----------------------- 261322d6c7bSMasatake YAMATO * For FIELDTYPE_STRING: 262322d6c7bSMasatake YAMATO * Both json writer and xref writer prints it as-is. 263322d6c7bSMasatake YAMATO * 264322d6c7bSMasatake YAMATO * For FIELDTYPE_STRING|FIELDTYPE_BOOL: 265322d6c7bSMasatake YAMATO * If VALUE points "" (empty C string), the json writer prints it as 266322d6c7bSMasatake YAMATO * false, and the xref writer prints it as -. 267322d6c7bSMasatake YAMATO * If VALUE points a non-empty C string, Both json writer and xref 268322d6c7bSMasatake YAMATO * writer print it as-is. 269322d6c7bSMasatake YAMATO * 270322d6c7bSMasatake YAMATO * For FIELDTYPE_BOOL 271322d6c7bSMasatake YAMATO * The json writer always prints true. 272322d6c7bSMasatake YAMATO * The xref writer always prints the name of field. 273322d6c7bSMasatake YAMATO * Set "" explicitly though the value pointed by VALUE is not referred, 274322d6c7bSMasatake YAMATO * 275322d6c7bSMasatake YAMATO * 276322d6c7bSMasatake YAMATO * The other data type and the combination of types are not implemented yet. 277322d6c7bSMasatake YAMATO * 278464894a0SMasatake YAMATO */ 279aa4def17SMasatake YAMATO extern void attachParserField (tagEntryInfo *const tag, bool inCorkQueue, fieldType ftype, const char* value); 2806a2bcd99SMasatake YAMATO extern void attachParserFieldToCorkEntry (int index, fieldType ftype, const char* value); 281317283cbSMasatake YAMATO extern const char* getParserFieldValueForType (tagEntryInfo *const tag, fieldType ftype); 282cc2cd3ceSMasatake YAMATO 283a7c2b428SMasatake YAMATO extern int makePlaceholder (const char *const name); 2848c8223f5SMasatake YAMATO extern void markTagPlaceholder (tagEntryInfo *e, bool placeholder); 285a7c2b428SMasatake YAMATO 28649d54591SMasatake YAMATO /* Marking all tag entries entries under the scope specified 28749d54591SMasatake YAMATO * with index recursively. 28849d54591SMasatake YAMATO * 28949d54591SMasatake YAMATO * The parser calling this function enables CORK_SYMTAB. 29049d54591SMasatake YAMATO * Entries to be marked must be registered to the scope 29149d54591SMasatake YAMATO * specified with index or its descendant scopes with 29249d54591SMasatake YAMATO * registerEntry (). 29349d54591SMasatake YAMATO * 29449d54591SMasatake YAMATO * Call makePlaceholder () at the start of your parser for 29549d54591SMasatake YAMATO * making the root scope where the entries are registered. 29649d54591SMasatake YAMATO */ 29749d54591SMasatake YAMATO extern void markAllEntriesInScopeAsPlaceholder (int index); 29849d54591SMasatake YAMATO 2995474c2e5SMasatake YAMATO #endif /* CTAGS_MAIN_ENTRY_H */ 300