xref: /Universal-ctags/parsers/cxx/cxx_tag.h (revision d00bddf924a65af2169f33a172990e5419cafaf9)
1 #ifndef _cxxTag_h_
2 #define _cxxTag_h_
3 /*
4 *   Copyright (c) 2016, Szymon Tomasz Stefanek
5 *
6 *   This source code is released for free distribution under the terms of the
7 *   GNU General Public License version 2 or (at your option) any later version.
8 *
9 *   This module contains functions for parsing and scanning C++ source files
10 */
11 
12 #include "general.h"
13 
14 #include "kind.h"
15 #include "entry.h"
16 
17 #include "cxx_token.h"
18 
19 // Tag kinds common to all (sub)languages this parser supports
20 enum CXXTagCommonKind
21 {
22 	CXXTagKindMACRO,
23 	CXXTagKindENUMERATOR,
24 	CXXTagKindFUNCTION,
25 	CXXTagKindENUM,
26 	CXXTagKindINCLUDE,
27 	CXXTagKindLOCAL,
28 	CXXTagKindMEMBER,
29 	CXXTagKindPROTOTYPE,
30 	CXXTagKindSTRUCT,
31 	CXXTagKindTYPEDEF,
32 	CXXTagKindUNION,
33 	CXXTagKindVARIABLE,
34 	CXXTagKindEXTERNVAR,
35 	CXXTagKindPARAMETER,
36 	CXXTagKindLABEL,
37 	CXXTagKindMACROPARAM,
38 
39 	CXXTagCommonKindCount
40 };
41 
42 // Tags specific to the CPP language.
43 enum CXXTagCPPKind
44 {
45 	CXXTagCPPKindCLASS = CXXTagCommonKindCount,
46 	CXXTagCPPKindNAMESPACE,
47 	CXXTagCPPKindALIAS,
48 	CXXTagCPPKindNAME,
49 	CXXTagCPPKindUSING,
50 	CXXTagCPPKindTEMPLATEPARAM
51 };
52 
53 // The fields common to all (sub)languages this parser supports.
54 enum CXXTagCommonField
55 {
56 	CXXTagFieldProperties,
57 	CXXTagFieldMacrodef,
58 
59 	CXXTagCommonFieldCount
60 };
61 
62 // The fields specific to the CPP language.
63 enum CXXTagCPPField
64 {
65 	CXXTagCPPFieldTemplate = CXXTagCommonFieldCount,
66 	CXXTagCPPFieldLambdaCaptureList,
67 	CXXTagCPPFieldAliasedName,
68 	CXXTagCPPFieldTemplateSpecialization
69 };
70 
71 
72 fieldDefinition * cxxTagGetCPPFieldDefinitionifiers(void);
73 int cxxTagGetCPPFieldDefinitionifierCount(void);
74 
75 fieldDefinition * cxxTagGetCUDAFieldDefinitionifiers(void);
76 int cxxTagGetCUDAFieldDefinitionifierCount(void);
77 
78 fieldDefinition * cxxTagGetCFieldDefinitionifiers(void);
79 int cxxTagGetCFieldDefinitionifierCount(void);
80 
81 bool cxxTagFieldEnabled(unsigned int uField);
82 
83 kindDefinition * cxxTagGetCKindDefinitions(void);
84 int cxxTagGetCKindDefinitionCount(void);
85 
86 kindDefinition * cxxTagGetCUDAKindDefinitions(void);
87 int cxxTagGetCUDAKindDefinitionCount(void);
88 
89 kindDefinition * cxxTagGetCPPKindDefinitions(void);
90 int cxxTagGetCPPKindDefinitionCount(void);
91 
92 // Returns true if the specified tag kind is enabled in the current language
93 bool cxxTagKindEnabled(unsigned int uTagKind);
94 
95 // Begin composing a tag. The tag kind must correspond to the current language.
96 // Returns NULL if the tag should *not* be included in the output
97 // or the tag entry info that can be filled up with extension fields.
98 // Must be followed by cxxTagCommit() if it returns a non-NULL value.
99 // The pToken ownership is NOT transferred.
100 tagEntryInfo * cxxTagBegin(unsigned int uKind,CXXToken * pToken);
101 
102 // Set the type of the current tag from the specified token sequence
103 // (which must belong to the same chain!).
104 // Before setting the type this function will check that the specified
105 // range of tokens looks reasonable for a type name and if it looks
106 // suspicious will refuse to emit it.
107 // If the type is effectively set then the return value is a token that must
108 // be destroyed after cxxTagCommit() has been called.
109 CXXToken * cxxTagCheckAndSetTypeField(
110 		CXXToken * pTypeStart,
111 		CXXToken * pTypeEnd
112 	);
113 
114 typedef enum _CXXTagProperty
115 {
116 	// Function is virtual
117 	CXXTagPropertyVirtual = 1,
118 	// Function/variable is static
119 	CXXTagPropertyStatic = (1 << 1),
120 	// Function is inline
121 	CXXTagPropertyInline = (1 << 2),
122 	// Function is explicit
123 	CXXTagPropertyExplicit = (1 << 3),
124 	// Function/variable is extern
125 	CXXTagPropertyExtern = (1 << 4),
126 	// Function is const
127 	CXXTagPropertyConst = (1 << 5),
128 	// Function is pure virtual
129 	CXXTagPropertyPure = (1 << 6),
130 	// Function is marked as override
131 	CXXTagPropertyOverride = (1 << 7),
132 	// Function is marked as default
133 	CXXTagPropertyDefault = (1 << 8),
134 	// Function is marked as final
135 	CXXTagPropertyFinal = (1 << 9),
136 	// Function is marked as delete
137 	CXXTagPropertyDelete = (1 << 10),
138 	// Variable is marked as mutable
139 	// (C++ treats "mutable" as storage class)
140 	CXXTagPropertyMutable = (1 << 11),
141 	// Function (note: NOT variable) is marked as volatile as in "int a() volatile"
142 	// (Because for variables it's treated as part of type)
143 	CXXTagPropertyVolatile = (1 << 12),
144 	// Template specialization a<x>()
145 	CXXTagPropertyTemplateSpecialization = (1 << 13),
146 	// Template specialization of scope a<x>::b() (which implies TemplateSpec too)
147 	CXXTagPropertyScopeTemplateSpecialization = (1 << 14),
148 	// __attribute__((deprecated)) has been seen
149 	CXXTagPropertyDeprecated = (1 << 15),
150 	// scoped enum (C++11)
151 	CXXTagPropertyScopedEnum = (1 << 16),
152 	// function-try-block: int f() try { ... } catch { ... }
153 	CXXTagPropertyFunctionTryBlock = (1 << 17)
154 } CXXTagProperty;
155 
156 // Set the modifiers field of the tag.
157 // Returns a string that you must destroy after the call to cxxTagCommit()
158 // or NULL if the modifiers weren't set for some reason (no modifiers, field
159 // not enabled or similar...)
160 vString * cxxTagSetProperties(unsigned int uProperties);
161 
162 // Set a parser-local field.
163 // If bCopyValue is set to false then szValue is not copied and it must
164 // persist in memory until cxxTagCommit() is called.
165 // If bCopyValue is set to true then szValue is copied and it can be
166 // safely destroyed before cxxTagCommit() is called.
167 // bCopyValue == false is faster: use it whenever possible.
168 void cxxTagSetField(unsigned int uField,const char * szValue,bool bCopyValue);
169 
170 // Set a parser-local CPP field for a tag in cork queue.
171 // The szValue pointer is copied.
172 // Make sure that the field is enabled before calling this function.
173 void cxxTagSetCorkQueueField(
174 		int iIndex,
175 		unsigned int uField,
176 		const char * szValue
177 	);
178 
179 // Handle the template-related parts of the tag (class, function, variable)
180 void cxxTagHandleTemplateFields();
181 
182 // Commit the composed tag. Must follow a successful cxxTagBegin() call.
183 // Returns the index of the tag in the cork queue.
184 int cxxTagCommit(int *piCorkQueueIndexFQ);
185 
186 // Same as cxxTagBegin() eventually followed by cxxTagCommit()
187 void cxxTag(unsigned int uKind,CXXToken * pToken);
188 
189 typedef enum {
190 	CR_MACRO_UNDEF,
191 	CR_MACRO_CONDITION,
192 } cMacroRole;
193 
194 typedef enum {
195 	CR_HEADER_SYSTEM,
196 	CR_HEADER_LOCAL,
197 } cHeaderRole;
198 
199 // Initialize the parser state for the specified language.
200 // Must be called before attempting to access the kind options.
201 void cxxTagInitForLanguage(langType eLangType);
202 
203 #endif //!_cxxTag_h_
204