1+ private import semmle.code.cpp.Declaration as D
12/**
23 * INTERNAL: Do not use. Provides classes and predicates for getting names of
34 * declarations, especially qualified names. Import this library `private` and
@@ -37,8 +38,7 @@ abstract class Declaration extends @declaration {
3738 string toString ( ) { result = "QualifiedName Declaration" }
3839
3940 /** Gets the name of this declaration. */
40- cached
41- abstract string getName ( ) ;
41+ final string getName ( ) { result = this .( D:: Declaration ) .getName ( ) }
4242
4343 string getTypeQualifierWithoutArgs ( ) {
4444 exists ( UserType declaringType |
@@ -133,8 +133,6 @@ abstract class Declaration extends @declaration {
133133}
134134
135135class Variable extends Declaration , @variable {
136- override string getName ( ) { none ( ) }
137-
138136 VariableDeclarationEntry getADeclarationEntry ( ) { result .getDeclaration ( ) = this }
139137}
140138
@@ -147,7 +145,6 @@ class TemplateVariable extends Variable {
147145class LocalScopeVariable extends Variable , @localscopevariable { }
148146
149147class LocalVariable extends LocalScopeVariable , @localvariable {
150- override string getName ( ) { localvariables ( this , _, result ) }
151148}
152149
153150/**
@@ -174,75 +171,20 @@ class Parameter extends LocalScopeVariable, @parameter {
174171 int index ;
175172
176173 Parameter ( ) { params ( this , function , index , _) }
177-
178- /**
179- * Gets the canonical name, or names, of this parameter.
180- *
181- * The canonical names are the first non-empty category from the
182- * following list:
183- * 1. The name given to the parameter at the function's definition or
184- * (for catch block parameters) at the catch block.
185- * 2. A name given to the parameter at a function declaration.
186- * 3. The name "p#i" where i is the index of the parameter.
187- */
188- override string getName ( ) {
189- exists ( VariableDeclarationEntry vde |
190- vde = getANamedDeclarationEntry ( ) and result = vde .getName ( )
191- |
192- vde .isDefinition ( ) or not getANamedDeclarationEntry ( ) .isDefinition ( )
193- )
194- or
195- not exists ( getANamedDeclarationEntry ( ) ) and
196- result = "p#" + index .toString ( )
197- }
198-
199- VariableDeclarationEntry getANamedDeclarationEntry ( ) {
200- result = getAnEffectiveDeclarationEntry ( ) and exists ( result .getName ( ) )
201- }
202-
203- /**
204- * Gets a declaration entry corresponding to this declaration.
205- *
206- * This predicate is the same as getADeclarationEntry(), except that for
207- * parameters of instantiated function templates, gives the declaration
208- * entry of the prototype instantiation of the parameter (as
209- * non-prototype instantiations don't have declaration entries of their
210- * own).
211- */
212- VariableDeclarationEntry getAnEffectiveDeclarationEntry ( ) {
213- if function .( Function ) .isConstructedFrom ( _)
214- then
215- exists ( Function prototypeInstantiation |
216- prototypeInstantiation .getParameter ( index ) = result .getVariable ( ) and
217- function .( Function ) .isConstructedFrom ( prototypeInstantiation )
218- )
219- else result = getADeclarationEntry ( )
220- }
221174}
222175
223176class GlobalOrNamespaceVariable extends Variable , @globalvariable {
224- override string getName ( ) { globalvariables ( this , _, result ) }
225- }
226-
227- class MemberVariable extends Variable , @membervariable {
228- MemberVariable ( ) { this .isMember ( ) }
229-
230- override string getName ( ) { membervariables ( this , _, result ) }
231177}
232178
233179// Unlike the usual `EnumConstant`, this one doesn't have a
234180// `getDeclaringType()`. This simplifies the recursive computation of type
235181// qualifier names since it can assume that any declaration with a
236182// `getDeclaringType()` should use that type in its type qualifier name.
237183class EnumConstant extends Declaration , @enumconstant {
238- override string getName ( ) { enumconstants ( this , _, _, _, result , _) }
239-
240184 UserType getDeclaringEnum ( ) { enumconstants ( this , result , _, _, _, _) }
241185}
242186
243187class Function extends Declaration , @function {
244- override string getName ( ) { functions ( this , result , _) }
245-
246188 predicate isConstructedFrom ( Function f ) { function_instantiation ( this , f ) }
247189
248190 Parameter getParameter ( int n ) { params ( result , this , n , _) }
@@ -258,8 +200,6 @@ class TemplateFunction extends Function {
258200}
259201
260202class UserType extends Declaration , @usertype {
261- override string getName ( ) { result = getUserTypeNameWithArgs ( this ) }
262-
263203 predicate isLocal ( ) { enclosingfunction ( this , _) }
264204
265205 // Gets a member of this class, if it's a class.
@@ -291,10 +231,6 @@ class TemplateClass extends UserType {
291231}
292232
293233class FriendDecl extends Declaration , @frienddecl {
294- override string getName ( ) {
295- result = getUserTypeNameWithArgs ( this .getDeclaringClass ( ) ) + "'s friend"
296- }
297-
298234 UserType getDeclaringClass ( ) { frienddecls ( this , result , _, _) }
299235}
300236
0 commit comments