Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qt-creator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Hunger
qt-creator
Commits
b7820022
Commit
b7820022
authored
15 years ago
by
Roberto Raggi
Browse files
Options
Downloads
Patches
Plain Diff
Warn for undefined namespaces in using namespace directives.
parent
19dd2b81
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/libs/cplusplus/CppBindings.cpp
+26
-0
26 additions, 0 deletions
src/libs/cplusplus/CppBindings.cpp
src/libs/cplusplus/CppBindings.h
+2
-0
2 additions, 0 deletions
src/libs/cplusplus/CppBindings.h
src/plugins/cpptools/cppmodelmanager.cpp
+32
-7
32 additions, 7 deletions
src/plugins/cpptools/cppmodelmanager.cpp
with
60 additions
and
7 deletions
src/libs/cplusplus/CppBindings.cpp
+
26
−
0
View file @
b7820022
...
...
@@ -567,6 +567,32 @@ bool Binder::visit(Block *)
}
// end of anonymous namespace
static
NamespaceBinding
*
find_helper
(
Namespace
*
symbol
,
NamespaceBinding
*
binding
,
QSet
<
QByteArray
>
*
processed
)
{
const
QByteArray
id
=
binding
->
qualifiedId
();
if
(
!
processed
->
contains
(
id
))
{
processed
->
insert
(
id
);
if
(
binding
->
symbols
.
contains
(
symbol
))
return
binding
;
foreach
(
NamespaceBinding
*
nestedBinding
,
binding
->
children
)
{
if
(
NamespaceBinding
*
ns
=
find_helper
(
symbol
,
nestedBinding
,
processed
))
return
ns
;
}
}
return
0
;
}
NamespaceBinding
*
NamespaceBinding
::
find
(
Namespace
*
symbol
,
NamespaceBinding
*
binding
)
{
QSet
<
QByteArray
>
processed
;
return
find_helper
(
symbol
,
binding
,
&
processed
);
}
NamespaceBindingPtr
CPlusPlus
::
bind
(
Document
::
Ptr
doc
,
Snapshot
snapshot
)
{
NamespaceBindingPtr
global
(
new
NamespaceBinding
());
...
...
This diff is collapsed.
Click to expand it.
src/libs/cplusplus/CppBindings.h
+
2
−
0
View file @
b7820022
...
...
@@ -118,6 +118,8 @@ public:
virtual
NamespaceBinding
*
asNamespaceBinding
()
{
return
this
;
}
static
NamespaceBinding
*
find
(
Namespace
*
symbol
,
NamespaceBinding
*
binding
);
private
:
NamespaceBinding
*
findNamespaceBindingForNameId
(
NameId
*
name
);
...
...
This diff is collapsed.
Click to expand it.
src/plugins/cpptools/cppmodelmanager.cpp
+
32
−
7
View file @
b7820022
...
...
@@ -252,13 +252,16 @@ namespace {
class
Process
;
class
CheckUndefined
BaseClasse
s
:
protected
ASTVisitor
class
CheckUndefined
Symbol
s
:
protected
ASTVisitor
{
public:
CheckUndefined
BaseClasses
(
Control
*
control
)
:
ASTVisitor
(
control
),
_
context
(
0
)
CheckUndefined
Symbols
(
Document
::
Ptr
doc
)
:
ASTVisitor
(
doc
->
control
()
),
_
process
(
0
),
_doc
(
doc
)
{
}
void
setGlobalNamespaceBinding
(
NamespaceBindingPtr
globalNamespaceBinding
)
{
_globalNamespaceBinding
=
globalNamespaceBinding
;
}
void
operator
()(
AST
*
ast
,
Process
*
process
)
{
_process
=
process
;
accept
(
ast
);
}
...
...
@@ -290,6 +293,26 @@ protected:
"expected class-name %s token"
,
token
);
}
}
return
true
;
}
virtual
bool
visit
(
UsingDirectiveAST
*
ast
)
{
if
(
ast
->
name
&&
ast
->
name
->
name
&&
_globalNamespaceBinding
)
{
const
Location
loc
=
Location
(
ast
->
symbol
);
NamespaceBinding
*
binding
=
_globalNamespaceBinding
.
data
();
if
(
Scope
*
enclosingNamespaceScope
=
ast
->
symbol
->
enclosingNamespaceScope
())
binding
=
NamespaceBinding
::
find
(
enclosingNamespaceScope
->
owner
()
->
asNamespace
(),
binding
);
if
(
!
binding
||
!
binding
->
resolveNamespace
(
loc
,
ast
->
name
->
name
))
{
translationUnit
()
->
warning
(
ast
->
name
->
firstToken
(),
"expected a namespace after `=' token"
);
}
}
return
true
;
}
...
...
@@ -297,7 +320,9 @@ protected:
private
:
Process
*
_process
;
Document
::
Ptr
_doc
;
LookupContext
_context
;
NamespaceBindingPtr
_globalNamespaceBinding
;
};
class
Process
:
public
std
::
unary_function
<
Document
::
Ptr
,
void
>
...
...
@@ -334,12 +359,12 @@ public:
if
(
_workingCopy
.
contains
(
doc
->
fileName
()))
{
// run the binding pass
NamespaceBindingPtr
ns
=
bind
(
doc
,
_snapshot
);
Q_UNUSED
(
ns
);
// check for undefined symbols.
CheckUndefinedSymbols
checkUndefinedSymbols
(
doc
);
checkUndefinedSymbols
.
setGlobalNamespaceBinding
(
ns
);
CheckUndefinedBaseClasses
checkUndefinedBaseClasses
(
doc
->
control
());
checkUndefinedBaseClasses
(
doc
->
translationUnit
()
->
ast
(),
this
);
checkUndefinedSymbols
(
doc
->
translationUnit
()
->
ast
(),
this
);
}
doc
->
releaseTranslationUnit
();
...
...
@@ -349,7 +374,7 @@ public:
}
};
LookupContext
CheckUndefined
BaseClasse
s
::
lookupContext
(
unsigned
line
,
unsigned
column
)
const
LookupContext
CheckUndefined
Symbol
s
::
lookupContext
(
unsigned
line
,
unsigned
column
)
const
{
return
_process
->
lookupContext
(
line
,
column
);
}
}
// end of anonymous namespace
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment