Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tobias Hunger
qt-creator
Commits
c4737c1f
Commit
c4737c1f
authored
Dec 01, 2009
by
Roberto Raggi
Browse files
Store the names in a set.
parent
c4d12742
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/shared/cplusplus/CheckDeclaration.cpp
View file @
c4737c1f
...
...
@@ -378,8 +378,9 @@ bool CheckDeclaration::visit(LinkageSpecificationAST *ast)
bool
CheckDeclaration
::
visit
(
NamespaceAST
*
ast
)
{
const
Identifier
*
id
=
identifier
(
ast
->
identifier_token
);
const
Name
*
namespaceName
=
control
()
->
nameId
(
id
);
const
Name
*
namespaceName
=
0
;
if
(
const
Identifier
*
id
=
identifier
(
ast
->
identifier_token
))
namespaceName
=
control
()
->
nameId
(
id
);
unsigned
sourceLocation
=
ast
->
firstToken
();
...
...
src/shared/cplusplus/Control.cpp
View file @
c4737c1f
...
...
@@ -129,6 +129,76 @@ template <> struct Compare<ArrayType>
}
};
template
<
>
struct
Compare
<
NameId
>
{
bool
operator
()(
const
NameId
&
name
,
const
NameId
&
otherName
)
const
{
return
name
.
identifier
()
<
otherName
.
identifier
();
}
};
template
<
>
struct
Compare
<
DestructorNameId
>
{
bool
operator
()(
const
DestructorNameId
&
name
,
const
DestructorNameId
&
otherName
)
const
{
return
name
.
identifier
()
<
otherName
.
identifier
();
}
};
template
<
>
struct
Compare
<
OperatorNameId
>
{
bool
operator
()(
const
OperatorNameId
&
name
,
const
OperatorNameId
&
otherName
)
const
{
return
name
.
kind
()
<
otherName
.
kind
();
}
};
template
<
>
struct
Compare
<
ConversionNameId
>
{
bool
operator
()(
const
ConversionNameId
&
name
,
const
ConversionNameId
&
otherName
)
const
{
return
name
.
type
()
<
otherName
.
type
();
}
};
template
<
>
struct
Compare
<
TemplateNameId
>
{
bool
operator
()(
const
TemplateNameId
&
name
,
const
TemplateNameId
&
otherName
)
const
{
const
Identifier
*
id
=
name
.
identifier
();
const
Identifier
*
otherId
=
otherName
.
identifier
();
if
(
id
==
otherId
)
return
std
::
lexicographical_compare
(
name
.
firstTemplateArgument
(),
name
.
lastTemplateArgument
(),
otherName
.
firstTemplateArgument
(),
otherName
.
lastTemplateArgument
());
return
id
<
otherId
;
}
};
template
<
>
struct
Compare
<
QualifiedNameId
>
{
bool
operator
()(
const
QualifiedNameId
&
name
,
const
QualifiedNameId
&
otherName
)
const
{
if
(
name
.
isGlobal
()
==
otherName
.
isGlobal
())
return
std
::
lexicographical_compare
(
name
.
firstName
(),
name
.
lastName
(),
otherName
.
firstName
(),
otherName
.
lastName
());
return
name
.
isGlobal
()
<
otherName
.
isGlobal
();
}
};
template
<
>
struct
Compare
<
SelectorNameId
>
{
bool
operator
()(
const
SelectorNameId
&
name
,
const
SelectorNameId
&
otherName
)
const
{
if
(
name
.
hasArguments
()
==
otherName
.
hasArguments
())
return
std
::
lexicographical_compare
(
name
.
firstName
(),
name
.
lastName
(),
otherName
.
firstName
(),
otherName
.
lastName
());
return
name
.
hasArguments
()
<
otherName
.
hasArguments
();
}
};
template
<
typename
_Tp
>
class
Table
:
public
std
::
set
<
_Tp
,
Compare
<
_Tp
>
>
{
...
...
@@ -139,13 +209,6 @@ public:
}
// end of anonymous namespace
template
<
typename
_Iterator
>
static
void
delete_map_entries
(
_Iterator
first
,
_Iterator
last
)
{
for
(;
first
!=
last
;
++
first
)
delete
first
->
second
;
}
template
<
typename
_Iterator
>
static
void
delete_array_entries
(
_Iterator
first
,
_Iterator
last
)
{
...
...
@@ -153,10 +216,6 @@ static void delete_array_entries(_Iterator first, _Iterator last)
delete
*
first
;
}
template
<
typename
_Map
>
static
void
delete_map_entries
(
const
_Map
&
m
)
{
delete_map_entries
(
m
.
begin
(),
m
.
end
());
}
template
<
typename
_Array
>
static
void
delete_array_entries
(
const
_Array
&
a
)
{
delete_array_entries
(
a
.
begin
(),
a
.
end
());
}
...
...
@@ -172,14 +231,6 @@ public:
~
Data
()
{
// names
delete_map_entries
(
nameIds
);
delete_map_entries
(
destructorNameIds
);
delete_map_entries
(
operatorNameIds
);
delete_map_entries
(
conversionNameIds
);
delete_map_entries
(
qualifiedNameIds
);
delete_map_entries
(
templateNameIds
);
// symbols
delete_array_entries
(
symbols
);
}
...
...
@@ -188,77 +239,41 @@ public:
{
if
(
!
id
)
return
0
;
std
::
map
<
const
Identifier
*
,
const
NameId
*>::
iterator
it
=
nameIds
.
lower_bound
(
id
);
if
(
it
==
nameIds
.
end
()
||
it
->
first
!=
id
)
it
=
nameIds
.
insert
(
it
,
std
::
make_pair
(
id
,
new
NameId
(
id
)));
return
it
->
second
;
return
nameIds
.
intern
(
NameId
(
id
));
}
const
TemplateNameId
*
findOrInsertTemplateNameId
(
const
Identifier
*
id
,
const
std
::
vector
<
FullySpecifiedType
>
&
templateArguments
)
template
<
typename
_Iterator
>
const
TemplateNameId
*
findOrInsertTemplateNameId
(
const
Identifier
*
id
,
_Iterator
first
,
_Iterator
last
)
{
if
(
!
id
)
return
0
;
const
TemplateNameIdKey
key
(
id
,
templateArguments
);
std
::
map
<
TemplateNameIdKey
,
const
TemplateNameId
*>::
iterator
it
=
templateNameIds
.
lower_bound
(
key
);
if
(
it
==
templateNameIds
.
end
()
||
it
->
first
!=
key
)
{
const
FullySpecifiedType
*
args
=
0
;
if
(
templateArguments
.
size
())
args
=
&
templateArguments
[
0
];
const
TemplateNameId
*
templ
=
new
TemplateNameId
(
id
,
args
,
templateArguments
.
size
());
it
=
templateNameIds
.
insert
(
it
,
std
::
make_pair
(
key
,
templ
));
}
return
it
->
second
;
return
templateNameIds
.
intern
(
TemplateNameId
(
id
,
first
,
last
));
}
const
DestructorNameId
*
findOrInsertDestructorNameId
(
const
Identifier
*
id
)
{
if
(
!
id
)
return
0
;
std
::
map
<
const
Identifier
*
,
const
DestructorNameId
*>::
iterator
it
=
destructorNameIds
.
lower_bound
(
id
);
if
(
it
==
destructorNameIds
.
end
()
||
it
->
first
!=
id
)
it
=
destructorNameIds
.
insert
(
it
,
std
::
make_pair
(
id
,
new
DestructorNameId
(
id
)));
return
it
->
second
;
return
destructorNameIds
.
intern
(
DestructorNameId
(
id
));
}
const
OperatorNameId
*
findOrInsertOperatorNameId
(
int
kind
)
{
const
int
key
(
kind
);
std
::
map
<
int
,
const
OperatorNameId
*>::
iterator
it
=
operatorNameIds
.
lower_bound
(
key
);
if
(
it
==
operatorNameIds
.
end
()
||
it
->
first
!=
key
)
it
=
operatorNameIds
.
insert
(
it
,
std
::
make_pair
(
key
,
new
OperatorNameId
(
kind
)));
return
it
->
second
;
return
operatorNameIds
.
intern
(
OperatorNameId
(
kind
));
}
const
ConversionNameId
*
findOrInsertConversionNameId
(
const
FullySpecifiedType
&
type
)
{
std
::
map
<
FullySpecifiedType
,
const
ConversionNameId
*>::
iterator
it
=
conversionNameIds
.
lower_bound
(
type
);
if
(
it
==
conversionNameIds
.
end
()
||
it
->
first
!=
type
)
it
=
conversionNameIds
.
insert
(
it
,
std
::
make_pair
(
type
,
new
ConversionNameId
(
type
)));
return
it
->
second
;
return
conversionNameIds
.
intern
(
ConversionNameId
(
type
));
}
const
QualifiedNameId
*
findOrInsertQualifiedNameId
(
const
std
::
vector
<
const
Name
*>
&
names
,
bool
isGlobal
)
template
<
typename
_Iterator
>
const
QualifiedNameId
*
findOrInsertQualifiedNameId
(
_Iterator
first
,
_Iterator
last
,
bool
isGlobal
)
{
const
QualifiedNameIdKey
key
(
names
,
isGlobal
);
std
::
map
<
QualifiedNameIdKey
,
const
QualifiedNameId
*>::
iterator
it
=
qualifiedNameIds
.
lower_bound
(
key
);
if
(
it
==
qualifiedNameIds
.
end
()
||
it
->
first
!=
key
)
{
const
QualifiedNameId
*
name
=
new
QualifiedNameId
(
&
names
[
0
],
names
.
size
(),
isGlobal
);
it
=
qualifiedNameIds
.
insert
(
it
,
std
::
make_pair
(
key
,
name
));
}
return
it
->
second
;
return
qualifiedNameIds
.
intern
(
QualifiedNameId
(
first
,
last
,
isGlobal
));
}
const
SelectorNameId
*
findOrInsertSelectorNameId
(
const
std
::
vector
<
const
Name
*>
&
names
,
bool
hasArguments
)
template
<
typename
_Iterator
>
const
SelectorNameId
*
findOrInsertSelectorNameId
(
_Iterator
first
,
_Iterator
last
,
bool
hasArguments
)
{
const
SelectorNameIdKey
key
(
names
,
hasArguments
);
std
::
map
<
SelectorNameIdKey
,
const
SelectorNameId
*>::
iterator
it
=
selectorNameIds
.
lower_bound
(
key
);
if
(
it
==
selectorNameIds
.
end
()
||
it
->
first
!=
key
)
it
=
selectorNameIds
.
insert
(
it
,
std
::
make_pair
(
key
,
new
SelectorNameId
(
&
names
[
0
],
names
.
size
(),
hasArguments
)));
return
it
->
second
;
return
selectorNameIds
.
intern
(
SelectorNameId
(
first
,
last
,
hasArguments
));
}
IntegerType
*
findOrInsertIntegerType
(
int
kind
)
...
...
@@ -439,75 +454,6 @@ public:
return
u
;
}
struct
TemplateNameIdKey
{
const
Identifier
*
id
;
std
::
vector
<
FullySpecifiedType
>
templateArguments
;
TemplateNameIdKey
(
const
Identifier
*
id
,
const
std
::
vector
<
FullySpecifiedType
>
&
templateArguments
)
:
id
(
id
),
templateArguments
(
templateArguments
)
{
}
bool
operator
==
(
const
TemplateNameIdKey
&
other
)
const
{
return
id
==
other
.
id
&&
templateArguments
==
other
.
templateArguments
;
}
bool
operator
!=
(
const
TemplateNameIdKey
&
other
)
const
{
return
!
operator
==
(
other
);
}
bool
operator
<
(
const
TemplateNameIdKey
&
other
)
const
{
if
(
id
==
other
.
id
)
return
std
::
lexicographical_compare
(
templateArguments
.
begin
(),
templateArguments
.
end
(),
other
.
templateArguments
.
begin
(),
other
.
templateArguments
.
end
());
return
id
<
other
.
id
;
}
};
struct
QualifiedNameIdKey
{
std
::
vector
<
const
Name
*>
names
;
bool
isGlobal
;
QualifiedNameIdKey
(
const
std
::
vector
<
const
Name
*>
&
names
,
bool
isGlobal
)
:
names
(
names
),
isGlobal
(
isGlobal
)
{
}
bool
operator
==
(
const
QualifiedNameIdKey
&
other
)
const
{
return
isGlobal
==
other
.
isGlobal
&&
names
==
other
.
names
;
}
bool
operator
!=
(
const
QualifiedNameIdKey
&
other
)
const
{
return
!
operator
==
(
other
);
}
bool
operator
<
(
const
QualifiedNameIdKey
&
other
)
const
{
if
(
isGlobal
==
other
.
isGlobal
)
return
std
::
lexicographical_compare
(
names
.
begin
(),
names
.
end
(),
other
.
names
.
begin
(),
other
.
names
.
end
());
return
isGlobal
<
other
.
isGlobal
;
}
};
struct
SelectorNameIdKey
{
std
::
vector
<
const
Name
*>
_names
;
bool
_hasArguments
;
SelectorNameIdKey
(
const
std
::
vector
<
const
Name
*>
&
names
,
bool
hasArguments
)
:
_names
(
names
),
_hasArguments
(
hasArguments
)
{}
bool
operator
==
(
const
SelectorNameIdKey
&
other
)
const
{
return
_names
==
other
.
_names
&&
_hasArguments
==
other
.
_hasArguments
;
}
bool
operator
!=
(
const
SelectorNameIdKey
&
other
)
const
{
return
!
operator
==
(
other
);
}
bool
operator
<
(
const
SelectorNameIdKey
&
other
)
const
{
if
(
_hasArguments
==
other
.
_hasArguments
)
return
std
::
lexicographical_compare
(
_names
.
begin
(),
_names
.
end
(),
other
.
_names
.
begin
(),
other
.
_names
.
end
());
else
return
_hasArguments
<
other
.
_hasArguments
;
}
};
Control
*
control
;
TranslationUnit
*
translationUnit
;
DiagnosticClient
*
diagnosticClient
;
...
...
@@ -521,13 +467,13 @@ public:
// ### replace std::map with lookup tables. ASAP!
// names
std
::
map
<
const
Identifier
*
,
const
NameId
*
>
nameIds
;
std
::
map
<
const
Identifier
*
,
const
DestructorNameId
*
>
destructorNameIds
;
std
::
map
<
int
,
const
OperatorNameId
*
>
operatorNameIds
;
std
::
map
<
FullySpecifiedType
,
const
ConversionNameId
*
>
conversionNameIds
;
std
::
map
<
TemplateNameIdKey
,
const
TemplateNameId
*
>
templateNameIds
;
std
::
map
<
QualifiedNameIdKey
,
const
QualifiedNameId
*
>
qualifiedNameIds
;
std
::
map
<
SelectorNameIdKey
,
const
SelectorNameId
*
>
selectorNameIds
;
Table
<
NameId
>
nameIds
;
Table
<
DestructorNameId
>
destructorNameIds
;
Table
<
OperatorNameId
>
operatorNameIds
;
Table
<
ConversionNameId
>
conversionNameIds
;
Table
<
TemplateNameId
>
templateNameIds
;
Table
<
QualifiedNameId
>
qualifiedNameIds
;
Table
<
SelectorNameId
>
selectorNameIds
;
// types
VoidType
voidType
;
...
...
@@ -641,8 +587,7 @@ const TemplateNameId *Control::templateNameId(const Identifier *id,
const
FullySpecifiedType
*
const
args
,
unsigned
argv
)
{
std
::
vector
<
FullySpecifiedType
>
templateArguments
(
args
,
args
+
argv
);
return
d
->
findOrInsertTemplateNameId
(
id
,
templateArguments
);
return
d
->
findOrInsertTemplateNameId
(
id
,
args
,
args
+
argv
);
}
const
DestructorNameId
*
Control
::
destructorNameId
(
const
Identifier
*
id
)
...
...
@@ -658,16 +603,14 @@ const QualifiedNameId *Control::qualifiedNameId(const Name *const *names,
unsigned
nameCount
,
bool
isGlobal
)
{
std
::
vector
<
const
Name
*>
classOrNamespaceNames
(
names
,
names
+
nameCount
);
return
d
->
findOrInsertQualifiedNameId
(
classOrNamespaceNames
,
isGlobal
);
return
d
->
findOrInsertQualifiedNameId
(
names
,
names
+
nameCount
,
isGlobal
);
}
const
SelectorNameId
*
Control
::
selectorNameId
(
const
Name
*
const
*
names
,
unsigned
nameCount
,
bool
hasArguments
)
{
std
::
vector
<
const
Name
*>
selectorNames
(
names
,
names
+
nameCount
);
return
d
->
findOrInsertSelectorNameId
(
selectorNames
,
hasArguments
);
return
d
->
findOrInsertSelectorNameId
(
names
,
names
+
nameCount
,
hasArguments
);
}
...
...
src/shared/cplusplus/Names.cpp
View file @
c4737c1f
...
...
@@ -50,17 +50,11 @@
#include "NameVisitor.h"
#include "Literals.h"
#include <cstring>
#include <cassert>
#include <algorithm>
using
namespace
CPlusPlus
;
QualifiedNameId
::
QualifiedNameId
(
const
Name
*
const
*
names
,
unsigned
nameCount
,
bool
isGlobal
)
:
_names
(
names
,
names
+
nameCount
),
_isGlobal
(
isGlobal
)
{
}
QualifiedNameId
::~
QualifiedNameId
()
{
}
...
...
@@ -159,13 +153,6 @@ bool DestructorNameId::isEqualTo(const Name *other) const
return
l
->
isEqualTo
(
r
);
}
TemplateNameId
::
TemplateNameId
(
const
Identifier
*
identifier
,
const
FullySpecifiedType
templateArguments
[],
unsigned
templateArgumentCount
)
:
_identifier
(
identifier
),
_templateArguments
(
templateArguments
,
templateArguments
+
templateArgumentCount
)
{
}
TemplateNameId
::~
TemplateNameId
()
{
}
...
...
@@ -249,13 +236,6 @@ bool ConversionNameId::isEqualTo(const Name *other) const
return
_type
.
isEqualTo
(
c
->
type
());
}
SelectorNameId
::
SelectorNameId
(
const
Name
*
const
*
names
,
unsigned
nameCount
,
bool
hasArguments
)
:
_names
(
names
,
names
+
nameCount
),
_hasArguments
(
hasArguments
)
{
}
SelectorNameId
::~
SelectorNameId
()
{
}
...
...
src/shared/cplusplus/Names.h
View file @
c4737c1f
...
...
@@ -59,7 +59,10 @@ namespace CPlusPlus {
class
CPLUSPLUS_EXPORT
QualifiedNameId
:
public
Name
{
public:
QualifiedNameId
(
const
Name
*
const
*
names
,
unsigned
nameCount
,
bool
isGlobal
=
false
);
template
<
typename
_Iterator
>
QualifiedNameId
(
_Iterator
first
,
_Iterator
last
,
bool
isGlobal
=
false
)
:
_names
(
first
,
last
),
_isGlobal
(
isGlobal
)
{}
virtual
~
QualifiedNameId
();
virtual
const
Identifier
*
identifier
()
const
;
...
...
@@ -75,6 +78,11 @@ public:
virtual
const
QualifiedNameId
*
asQualifiedNameId
()
const
{
return
this
;
}
typedef
std
::
vector
<
const
Name
*>::
const_iterator
NameIterator
;
NameIterator
firstName
()
const
{
return
_names
.
begin
();
}
NameIterator
lastName
()
const
{
return
_names
.
end
();
}
protected:
virtual
void
accept0
(
NameVisitor
*
visitor
)
const
;
...
...
@@ -126,9 +134,10 @@ private:
class
CPLUSPLUS_EXPORT
TemplateNameId
:
public
Name
{
public:
TemplateNameId
(
const
Identifier
*
identifier
,
const
FullySpecifiedType
templateArguments
[],
unsigned
templateArgumentCount
);
template
<
typename
_Iterator
>
TemplateNameId
(
const
Identifier
*
identifier
,
_Iterator
first
,
_Iterator
last
)
:
_identifier
(
identifier
),
_templateArguments
(
first
,
last
)
{}
virtual
~
TemplateNameId
();
virtual
const
Identifier
*
identifier
()
const
;
...
...
@@ -142,6 +151,11 @@ public:
virtual
const
TemplateNameId
*
asTemplateNameId
()
const
{
return
this
;
}
typedef
std
::
vector
<
FullySpecifiedType
>::
const_iterator
TemplateArgumentIterator
;
TemplateArgumentIterator
firstTemplateArgument
()
const
{
return
_templateArguments
.
begin
();
}
TemplateArgumentIterator
lastTemplateArgument
()
const
{
return
_templateArguments
.
end
();
}
protected:
virtual
void
accept0
(
NameVisitor
*
visitor
)
const
;
...
...
@@ -250,7 +264,10 @@ private:
class
CPLUSPLUS_EXPORT
SelectorNameId
:
public
Name
{
public:
SelectorNameId
(
const
Name
*
const
*
names
,
unsigned
nameCount
,
bool
hasArguments
);
template
<
typename
_Iterator
>
SelectorNameId
(
_Iterator
first
,
_Iterator
last
,
bool
hasArguments
)
:
_names
(
first
,
last
),
_hasArguments
(
hasArguments
)
{}
virtual
~
SelectorNameId
();
virtual
const
Identifier
*
identifier
()
const
;
...
...
@@ -264,6 +281,11 @@ public:
virtual
const
SelectorNameId
*
asSelectorNameId
()
const
{
return
this
;
}
typedef
std
::
vector
<
const
Name
*>::
const_iterator
NameIterator
;
NameIterator
firstName
()
const
{
return
_names
.
begin
();
}
NameIterator
lastName
()
const
{
return
_names
.
end
();
}
protected:
virtual
void
accept0
(
NameVisitor
*
visitor
)
const
;
...
...
@@ -274,5 +296,4 @@ private:
}
// end of namespace CPlusPlus
#endif // CPLUSPLUS_NAMES_H
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment