Merge pull request #1303 from jbj/hasQualifiedName

C++: Fix `getQualifiedName` performance issues
This commit is contained in:
Robert Marsh
2019-05-15 12:42:57 -07:00
committed by GitHub
50 changed files with 743 additions and 298 deletions

View File

@@ -0,0 +1,61 @@
void overloadedFunction(int);
void overloadedFunction(void *);
enum Enum { enumConstant };
enum class EnumClass { classEnumConstant };
class C {
void privateFunction();
public:
void publicFunction();
enum Enum { enumConstant };
enum class EnumClass { classEnumConstant };
class Nested {
friend class FriendOfNested;
Nested();
enum Enum { enumConstant };
};
};
int main() {
class LocalClass {
int localClassField;
};
return 0;
}
namespace ns {
int f();
class C;
}
typedef struct {
int structField;
} typedefStructName, *ptypedefStructName;
typedef C typedefC;
namespace templates {
template<typename T>
struct TemplateClass {
T x;
template<typename Ignored>
const T &getMember(Ignored ignored) const { return x; }
};
template<typename T, typename Ignored>
const T &getMember(TemplateClass<T> &tc, Ignored ignored) {
return tc.getMember(ignored);
}
long use() {
TemplateClass<unsigned long> tc = { 22 };
return getMember(tc, typedefC());
}
}

View File

@@ -0,0 +1,54 @@
| file://:0:0:0:0 | __va_list_tag | __va_list_tag | | | __va_list_tag | __va_list_tag |
| file://:0:0:0:0 | fp_offset | __va_list_tag::fp_offset | | __va_list_tag | fp_offset | (not global) |
| file://:0:0:0:0 | gp_offset | __va_list_tag::gp_offset | | __va_list_tag | gp_offset | (not global) |
| file://:0:0:0:0 | operator= | __va_list_tag::operator= | | __va_list_tag | operator= | (not global) |
| file://:0:0:0:0 | operator= | __va_list_tag::operator= | | __va_list_tag | operator= | (not global) |
| file://:0:0:0:0 | overflow_arg_area | __va_list_tag::overflow_arg_area | | __va_list_tag | overflow_arg_area | (not global) |
| file://:0:0:0:0 | reg_save_area | __va_list_tag::reg_save_area | | __va_list_tag | reg_save_area | (not global) |
| qualifiedNames.cpp:3:6:3:23 | overloadedFunction | overloadedFunction | | | overloadedFunction | overloadedFunction |
| qualifiedNames.cpp:4:6:4:23 | overloadedFunction | overloadedFunction | | | overloadedFunction | overloadedFunction |
| qualifiedNames.cpp:6:6:6:9 | Enum | Enum | | | Enum | Enum |
| qualifiedNames.cpp:6:13:6:24 | enumConstant | Enum::enumConstant | | Enum | enumConstant | (not global) |
| qualifiedNames.cpp:7:12:7:20 | EnumClass | EnumClass | | | EnumClass | EnumClass |
| qualifiedNames.cpp:7:24:7:40 | classEnumConstant | EnumClass::classEnumConstant | | EnumClass | classEnumConstant | (not global) |
| qualifiedNames.cpp:9:7:9:7 | C | C | | | C | C |
| qualifiedNames.cpp:9:7:9:7 | operator= | C::operator= | | C | operator= | (not global) |
| qualifiedNames.cpp:9:7:9:7 | operator= | C::operator= | | C | operator= | (not global) |
| qualifiedNames.cpp:10:8:10:22 | privateFunction | C::privateFunction | | C | privateFunction | (not global) |
| qualifiedNames.cpp:12:8:12:21 | publicFunction | C::publicFunction | | C | publicFunction | (not global) |
| qualifiedNames.cpp:14:8:14:11 | Enum | C::Enum | | C | Enum | (not global) |
| qualifiedNames.cpp:14:15:14:26 | enumConstant | C::Enum::enumConstant | | C::Enum | enumConstant | (not global) |
| qualifiedNames.cpp:15:14:15:22 | EnumClass | C::EnumClass | | C | EnumClass | (not global) |
| qualifiedNames.cpp:15:26:15:42 | classEnumConstant | C::EnumClass::classEnumConstant | | C::EnumClass | classEnumConstant | (not global) |
| qualifiedNames.cpp:17:9:17:9 | Nested | C::Nested::Nested | | C::Nested | Nested | (not global) |
| qualifiedNames.cpp:17:9:17:9 | Nested | C::Nested::Nested | | C::Nested | Nested | (not global) |
| qualifiedNames.cpp:17:9:17:9 | operator= | C::Nested::operator= | | C::Nested | operator= | (not global) |
| qualifiedNames.cpp:17:9:17:9 | operator= | C::Nested::operator= | | C::Nested | operator= | (not global) |
| qualifiedNames.cpp:17:9:17:14 | Nested | C::Nested | | C | Nested | (not global) |
| qualifiedNames.cpp:18:18:18:31 | FriendOfNested | FriendOfNested | | | FriendOfNested | FriendOfNested |
| qualifiedNames.cpp:19:5:19:10 | Nested | C::Nested::Nested | | C::Nested | Nested | (not global) |
| qualifiedNames.cpp:21:10:21:13 | Enum | C::Nested::Enum | | C::Nested | Enum | (not global) |
| qualifiedNames.cpp:21:17:21:28 | enumConstant | C::Nested::Enum::enumConstant | | C::Nested::Enum | enumConstant | (not global) |
| qualifiedNames.cpp:25:5:25:8 | main | main | | | main | main |
| qualifiedNames.cpp:33:7:33:7 | f | ns::f | ns | | f | (not global) |
| qualifiedNames.cpp:34:9:34:9 | C | ns::C | ns | | C | (not global) |
| qualifiedNames.cpp:37:16:37:16 | operator= | typedefStructName::operator= | | typedefStructName | operator= | (not global) |
| qualifiedNames.cpp:37:16:37:16 | operator= | typedefStructName::operator= | | typedefStructName | operator= | (not global) |
| qualifiedNames.cpp:37:16:37:32 | typedefStructName | typedefStructName | | | typedefStructName | typedefStructName |
| qualifiedNames.cpp:38:7:38:17 | structField | typedefStructName::structField | | typedefStructName | structField | (not global) |
| qualifiedNames.cpp:39:3:39:19 | typedefStructName | typedefStructName | | | typedefStructName | typedefStructName |
| qualifiedNames.cpp:39:23:39:40 | ptypedefStructName | ptypedefStructName | | | ptypedefStructName | ptypedefStructName |
| qualifiedNames.cpp:41:11:41:18 | typedefC | typedefC | | | typedefC | typedefC |
| qualifiedNames.cpp:45:10:45:10 | operator= | templates::TemplateClass<unsigned long>::operator= | templates | TemplateClass | operator= | (not global) |
| qualifiedNames.cpp:45:10:45:10 | operator= | templates::TemplateClass<unsigned long>::operator= | templates | TemplateClass | operator= | (not global) |
| qualifiedNames.cpp:45:10:45:22 | TemplateClass<T> | templates::TemplateClass<T> | templates | | TemplateClass | (not global) |
| qualifiedNames.cpp:45:10:45:22 | TemplateClass<T> | templates::TemplateClass<T> | templates | | TemplateClass | (not global) |
| qualifiedNames.cpp:45:10:45:22 | TemplateClass<unsigned long> | templates::TemplateClass<unsigned long> | templates | | TemplateClass | (not global) |
| qualifiedNames.cpp:46:7:46:7 | x | templates::TemplateClass<T>::x | templates | TemplateClass | x | (not global) |
| qualifiedNames.cpp:46:7:46:7 | x | templates::TemplateClass<unsigned long>::x | templates | TemplateClass | x | (not global) |
| qualifiedNames.cpp:49:14:49:14 | getMember | templates::TemplateClass<unsigned long>::getMember | templates | TemplateClass | getMember | (not global) |
| qualifiedNames.cpp:49:14:49:22 | getMember | templates::TemplateClass<T>::getMember | templates | TemplateClass | getMember | (not global) |
| qualifiedNames.cpp:49:14:49:22 | getMember | templates::TemplateClass<unsigned long>::getMember | templates | TemplateClass | getMember | (not global) |
| qualifiedNames.cpp:53:12:53:12 | getMember | templates::getMember | templates | | getMember | (not global) |
| qualifiedNames.cpp:53:12:53:20 | getMember | templates::getMember | templates | | getMember | (not global) |
| qualifiedNames.cpp:57:8:57:10 | use | templates::use | templates | | use | (not global) |

View File

@@ -0,0 +1,13 @@
import cpp
from
Declaration d, string namespaceQualifier, string typeQualifier, string baseName, string globalName
where
d.hasQualifiedName(namespaceQualifier, typeQualifier, baseName) and
(
d.hasGlobalName(globalName)
or
not d.hasGlobalName(_) and
globalName = "(not global)"
)
select d, d.getQualifiedName(), namespaceQualifier, typeQualifier, baseName, globalName

View File

@@ -0,0 +1,19 @@
| qualifiedNames.cpp:3:25:3:27 | p#0 |
| qualifiedNames.cpp:4:25:4:28 | p#0 |
| qualifiedNames.cpp:18:18:18:31 | Nested's friend |
| qualifiedNames.cpp:26:9:26:9 | operator= |
| qualifiedNames.cpp:26:9:26:9 | operator= |
| qualifiedNames.cpp:26:9:26:18 | LocalClass |
| qualifiedNames.cpp:27:9:27:23 | localClassField |
| qualifiedNames.cpp:44:21:44:21 | T |
| qualifiedNames.cpp:48:23:48:29 | Ignored |
| qualifiedNames.cpp:49:32:49:38 | ignored |
| qualifiedNames.cpp:49:32:49:38 | ignored |
| qualifiedNames.cpp:49:32:49:38 | ignored |
| qualifiedNames.cpp:52:21:52:21 | T |
| qualifiedNames.cpp:52:33:52:39 | Ignored |
| qualifiedNames.cpp:53:40:53:41 | tc |
| qualifiedNames.cpp:53:40:53:41 | tc |
| qualifiedNames.cpp:53:52:53:58 | ignored |
| qualifiedNames.cpp:53:52:53:58 | ignored |
| qualifiedNames.cpp:58:34:58:35 | tc |

View File

@@ -0,0 +1,13 @@
// This query lists the declarations that don't have a qualified name
import cpp
from Declaration d
where
(
not exists(d.getQualifiedName())
or
not d.hasQualifiedName(_, _, _)
) and
exists(d.getFile().getRelativePath())
select d