1 /*
2 *   Copyright (c) 1998-2002, Darren Hiebert
3 *
4 *   This source code is released for free distribution under the terms of the
5 *   GNU General Public License version 2 or (at your option) any later version.
6 *
7 *   External interface to entry.c
8 */
9 #ifndef CTAGS_MAIN_ENTRY_H
10 #define CTAGS_MAIN_ENTRY_H
11 
12 /*
13 *   INCLUDE FILES
14 */
15 #include "general.h"  /* must always come first */
16 #include "types.h"
17 
18 #include <stdint.h>
19 #include <stdio.h>
20 
21 #include "field.h"
22 #include "kind.h"
23 #include "vstring.h"
24 #include "xtag.h"
25 #include "mio.h"
26 #include "nestlevel.h"
27 #include "ctags-api.h"
28 
29 /*
30 *   MACROS
31 */
32 #define WHOLE_FILE  -1L
33 #define includeExtensionFlags()         (Option.tagFileFormat > 1)
34 
35 /*
36 *   DATA DECLARATIONS
37 */
38 typedef struct sTagField {
39 	fieldType  ftype;
40 	const char* value;
41 } tagField;
42 
43 /*  Information about the current tag candidate.
44  */
45 struct sTagEntryInfo {
46 	unsigned int lineNumberEntry:1;  /* pattern or line number entry */
47 	unsigned int isFileScope    :1;  /* is tag visible only within input file? */
48 	unsigned int isFileEntry    :1;  /* is this just an entry for a file name? */
49 	unsigned int truncateLineAfterTag :1;  /* truncate tag line at end of tag name? */
50 	unsigned int placeholder    :1;	 /* This is just a part of scope context.
51 					    Put this entry to cork queue but
52 					    don't print it to tags file. */
53 
54 	unsigned long lineNumber;     /* line number of tag */
55 	const char* pattern;	      /* pattern for locating input line
56 				       * (may be NULL if not present) *//*  */
57 	unsigned int boundaryInfo;    /* info about nested input stream */
58 	MIOPos      filePosition;     /* file position of line containing tag */
59 	langType langType;         /* language of input file */
60 	const char *inputFileName;   /* name of input file */
61 	const char *name;             /* name of the tag */
62 	int kindIndex;	      /* kind descriptor */
63 	unsigned char extra[ ((XTAG_COUNT) / 8) + 1 ];
64 
65 	struct {
66 		const char* access;
67 		const char* fileScope;
68 		const char* implementation;
69 		const char* inheritance;
70 
71 		/* Which scopeKindIndex belong to. If the value is LANG_AUTO,
72 		   the value for langType field of this structure is used as default value.
73 		   LANG_AUTO is set automatically in initTagEntryInfo. */
74 		langType    scopeLangType;
75 		int         scopeKindIndex;
76 		const char* scopeName;
77 		int         scopeIndex;   /* cork queue entry for upper scope tag.
78 					     This field is meaningful if the value
79 					     is not CORK_NIL and scope[0]  and scope[1] are
80 					     NULL. */
81 
82 		const char* signature;
83 
84 		/* type (union/struct/etc.) and name for a variable or typedef. */
85 		const char* typeRef [2];  /* e.g., "struct" and struct name */
86 
87 /* GEANY DIFF */
88 		const char *varType;
89 /* GEANY DIFF END */
90 
91 #define ROLE_INDEX_DEFINITION -1
92 		int roleIndex; /* for role of reference tag */
93 
94 #ifdef HAVE_LIBXML
95 		const char* xpath;
96 #endif
97 		unsigned long endLine;
98 	} extensionFields;  /* list of extension fields*/
99 
100 #define PRE_ALLOCATED_PARSER_FIELDS 5
101 #define NO_PARSER_FIELD -1
102 	unsigned int usedParserFields;
103 	tagField     parserFields [PRE_ALLOCATED_PARSER_FIELDS];
104 
105 	/* Following source* fields are used only when #line is found
106 	   in input and --line-directive is given in ctags command line. */
107 	langType sourceLangType;
108 	const char *sourceFileName;
109 	unsigned long sourceLineNumberDifference;
110 };
111 
112 
113 /*
114 *   GLOBAL VARIABLES
115 */
116 
117 
118 /*
119 *   FUNCTION PROTOTYPES
120 */
121 extern void freeTagFileResources (void);
122 extern const char *tagFileName (void);
123 extern void openTagFile (void);
124 extern void closeTagFile (const bool resize);
125 extern void  setupWriter (void);
126 extern void  teardownWriter (const char *inputFilename);
127 extern int makeTagEntry (const tagEntryInfo *const tag);
128 extern void initTagEntry (tagEntryInfo *const e, const char *const name,
129 			  int kindIndex);
130 extern void initRefTagEntry (tagEntryInfo *const e, const char *const name,
131 			     int kindIndex, int roleIndex);
132 extern void initTagEntryFull (tagEntryInfo *const e, const char *const name,
133 			      unsigned long lineNumber,
134 			      langType langType_,
135 			      MIOPos      filePosition,
136 			      const char *inputFileName,
137 			      int kindIndex,
138 			      int roleIndex,
139 			      const char *sourceFileName,
140 			      langType sourceLangType,
141 			      long sourceLineNumberDifference);
142 extern int makeQualifiedTagEntry (const tagEntryInfo *const e);
143 
144 extern unsigned long numTagsAdded(void);
145 extern void setNumTagsAdded (unsigned long nadded);
146 extern unsigned long numTagsTotal(void);
147 extern unsigned long maxTagsLine(void);
148 extern void invalidatePatternCache(void);
149 extern void tagFilePosition (MIOPos *p);
150 extern void setTagFilePosition (MIOPos *p);
151 extern const char* getTagFileDirectory (void);
152 extern void getTagScopeInformation (tagEntryInfo *const tag,
153 				    const char **kind, const char **name);
154 
155 /* Getting line associated with tag */
156 extern char *readLineFromBypassAnyway (vString *const vLine, const tagEntryInfo *const tag,
157 				   long *const pSeekValue);
158 
159 /* Generating pattern associated tag, caller must do eFree for the returned value. */
160 extern char* makePatternString (const tagEntryInfo *const tag);
161 
162 
163 /* language is optional: can be NULL. */
164 extern bool writePseudoTag (const ptagDesc *pdesc,
165 			       const char *const fileName,
166 			       const char *const pattern,
167 			       const char *const parserName);
168 
169 #define CORK_NIL 0
170 void          corkTagFile(void);
171 void          uncorkTagFile(void);
172 tagEntryInfo *getEntryInCorkQueue   (unsigned int n);
173 tagEntryInfo *getEntryOfNestingLevel (const NestingLevel *nl);
174 size_t        countEntryInCorkQueue (void);
175 
176 extern void makeFileTag (const char *const fileName);
177 
178 extern void    markTagExtraBit     (tagEntryInfo *const tag, xtagType extra);
179 extern bool isTagExtraBitMarked (const tagEntryInfo *const tag, xtagType extra);
180 
181 extern void attachParserField (tagEntryInfo *const tag, fieldType ftype, const char* value);
182 extern void attachParserFieldToCorkEntry (int index, fieldType ftype, const char* value);
183 
184 #ifdef CTAGS_LIB
185 extern void setTagEntryFunction(tagEntryFunction entry_function, void *user_data);
186 #endif
187 
188 #endif  /* CTAGS_MAIN_ENTRY_H */
189