Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
b7820022
Commit
b7820022
authored
Jun 03, 2009
by
Roberto Raggi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Warn for undefined namespaces in using namespace directives.
parent
19dd2b81
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
7 deletions
+60
-7
src/libs/cplusplus/CppBindings.cpp
src/libs/cplusplus/CppBindings.cpp
+26
-0
src/libs/cplusplus/CppBindings.h
src/libs/cplusplus/CppBindings.h
+2
-0
src/plugins/cpptools/cppmodelmanager.cpp
src/plugins/cpptools/cppmodelmanager.cpp
+32
-7
No files found.
src/libs/cplusplus/CppBindings.cpp
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
());
...
...
src/libs/cplusplus/CppBindings.h
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
);
...
...
src/plugins/cpptools/cppmodelmanager.cpp
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
...
...
Write
Preview
Markdown
is supported
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