Skip to content
GitLab
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
867bf3da
Commit
867bf3da
authored
Jul 19, 2010
by
Erik Verbruggen
Browse files
Fixes for scope range calculation.
parent
7de836bf
Changes
9
Hide whitespace changes
Inline
Side-by-side
src/libs/cplusplus/CppDocument.cpp
View file @
867bf3da
...
...
@@ -89,11 +89,11 @@ protected:
}
unsigned
startLine
,
startColumn
;
_unit
->
getPosition
(
s
ymbol
->
startOffset
(),
&
startLine
,
&
startColumn
);
_unit
->
getPosition
(
s
cope
->
startOffset
(),
&
startLine
,
&
startColumn
);
if
(
_line
>
startLine
||
(
_line
==
startLine
&&
_column
>=
startColumn
))
{
unsigned
endLine
,
endColumn
;
_unit
->
getPosition
(
s
ymbol
->
endOffset
(),
&
endLine
,
&
endColumn
);
_unit
->
getPosition
(
s
cope
->
endOffset
(),
&
endLine
,
&
endColumn
);
if
(
_line
<
endLine
||
(
_line
==
endLine
&&
_column
<=
endColumn
))
_scope
=
scope
;
...
...
src/plugins/cppeditor/cppchecksymbols.cpp
View file @
867bf3da
...
...
@@ -87,12 +87,12 @@ public:
static
Scope
*
findScope
(
unsigned
tokenOffset
,
const
QList
<
ScopedSymbol
*>
&
scopes
)
{
for
(
int
i
=
scopes
.
size
()
-
1
;
i
!=
-
1
;
--
i
)
{
Scope
dSymbol
*
symbol
=
scopes
.
at
(
i
);
const
unsigned
start
=
s
ymbol
->
startOffset
();
const
unsigned
end
=
s
ymbol
->
endOffset
();
Scope
*
scope
=
scopes
.
at
(
i
)
->
members
()
;
const
unsigned
start
=
s
cope
->
startOffset
();
const
unsigned
end
=
s
cope
->
endOffset
();
if
(
tokenOffset
>=
start
&&
tokenOffset
<
end
)
return
s
ymbol
->
members
()
;
return
s
cope
;
}
return
0
;
...
...
src/shared/cplusplus/CheckDeclaration.cpp
View file @
867bf3da
...
...
@@ -349,8 +349,8 @@ bool CheckDeclaration::visit(FunctionDefinitionAST *ast)
fun
->
setDeprecated
(
true
);
if
(
ty
.
isUnavailable
())
fun
->
setUnavailable
(
true
);
fun
->
setStartOffset
(
funStartOffset
);
fun
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
fun
->
members
()
->
setStartOffset
(
funStartOffset
);
fun
->
members
()
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
if
(
ast
->
declarator
)
fun
->
setSourceLocation
(
ast
->
declarator
->
firstToken
(),
translationUnit
());
fun
->
setName
(
name
);
...
...
@@ -410,13 +410,15 @@ bool CheckDeclaration::visit(NamespaceAST *ast)
namespaceName
=
control
()
->
nameId
(
id
);
unsigned
sourceLocation
=
ast
->
firstToken
();
if
(
ast
->
identifier_token
)
sourceLocation
=
ast
->
identifier_token
;
unsigned
scopeStart
=
tokenAt
(
ast
->
firstToken
()).
offset
;
if
(
ast
->
linkage_body
&&
ast
->
linkage_body
->
firstToken
())
scopeStart
=
tokenAt
(
ast
->
linkage_body
->
firstToken
()).
offset
;
Namespace
*
ns
=
control
()
->
newNamespace
(
sourceLocation
,
namespaceName
);
ns
->
setStartOffset
(
tokenAt
(
ast
->
firstToken
()).
offse
t
);
ns
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
ns
->
members
()
->
setStartOffset
(
scopeStar
t
);
ns
->
members
()
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
ast
->
symbol
=
ns
;
_scope
->
enterSymbol
(
ns
);
semantic
()
->
check
(
ast
->
linkage_body
,
ns
->
members
());
// ### we'll do the merge later.
...
...
@@ -583,6 +585,18 @@ bool CheckDeclaration::visit(ObjCProtocolForwardDeclarationAST *ast)
return
false
;
}
unsigned
CheckDeclaration
::
calculateScopeStart
(
ObjCProtocolDeclarationAST
*
ast
)
const
{
if
(
ast
->
protocol_refs
)
if
(
unsigned
pos
=
ast
->
protocol_refs
->
lastToken
())
return
tokenAt
(
pos
-
1
).
end
();
if
(
ast
->
name
)
if
(
unsigned
pos
=
ast
->
name
->
lastToken
())
return
tokenAt
(
pos
-
1
).
end
();
return
tokenAt
(
ast
->
firstToken
()).
offset
;
}
bool
CheckDeclaration
::
visit
(
ObjCProtocolDeclarationAST
*
ast
)
{
unsigned
sourceLocation
;
...
...
@@ -593,8 +607,8 @@ bool CheckDeclaration::visit(ObjCProtocolDeclarationAST *ast)
const
Name
*
protocolName
=
semantic
()
->
check
(
ast
->
name
,
_scope
);
ObjCProtocol
*
protocol
=
control
()
->
newObjCProtocol
(
sourceLocation
,
protocolName
);
protocol
->
setStartOffset
(
tokenAt
(
ast
->
firstToken
()).
offset
);
protocol
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
protocol
->
members
()
->
setStartOffset
(
calculateScopeStart
(
ast
)
);
protocol
->
members
()
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
if
(
ast
->
protocol_refs
&&
ast
->
protocol_refs
->
identifier_list
)
{
for
(
NameListAST
*
iter
=
ast
->
protocol_refs
->
identifier_list
;
iter
;
iter
=
iter
->
next
)
{
...
...
@@ -642,6 +656,40 @@ bool CheckDeclaration::visit(ObjCClassForwardDeclarationAST *ast)
return
false
;
}
unsigned
CheckDeclaration
::
calculateScopeStart
(
ObjCClassDeclarationAST
*
ast
)
const
{
if
(
ast
->
inst_vars_decl
)
if
(
unsigned
pos
=
ast
->
inst_vars_decl
->
lbrace_token
)
return
tokenAt
(
pos
).
end
();
if
(
ast
->
protocol_refs
)
if
(
unsigned
pos
=
ast
->
protocol_refs
->
lastToken
())
return
tokenAt
(
pos
-
1
).
end
();
if
(
ast
->
superclass
)
if
(
unsigned
pos
=
ast
->
superclass
->
lastToken
())
return
tokenAt
(
pos
-
1
).
end
();
if
(
ast
->
colon_token
)
return
tokenAt
(
ast
->
colon_token
).
end
();
if
(
ast
->
rparen_token
)
return
tokenAt
(
ast
->
rparen_token
).
end
();
if
(
ast
->
category_name
)
if
(
unsigned
pos
=
ast
->
category_name
->
lastToken
())
return
tokenAt
(
pos
-
1
).
end
();
if
(
ast
->
lparen_token
)
return
tokenAt
(
ast
->
lparen_token
).
end
();
if
(
ast
->
class_name
)
if
(
unsigned
pos
=
ast
->
class_name
->
lastToken
())
return
tokenAt
(
pos
-
1
).
end
();
return
tokenAt
(
ast
->
firstToken
()).
offset
;
}
bool
CheckDeclaration
::
visit
(
ObjCClassDeclarationAST
*
ast
)
{
unsigned
sourceLocation
;
...
...
@@ -652,8 +700,8 @@ bool CheckDeclaration::visit(ObjCClassDeclarationAST *ast)
const
Name
*
className
=
semantic
()
->
check
(
ast
->
class_name
,
_scope
);
ObjCClass
*
klass
=
control
()
->
newObjCClass
(
sourceLocation
,
className
);
klass
->
setStartOffset
(
tokenAt
(
ast
->
firstToken
()).
offset
);
klass
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
()
);
klass
->
members
()
->
setStartOffset
(
calculateScopeStart
(
ast
)
);
klass
->
members
()
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
offset
);
ast
->
symbol
=
klass
;
klass
->
setInterface
(
ast
->
interface_token
!=
0
);
...
...
@@ -716,8 +764,8 @@ bool CheckDeclaration::visit(ObjCMethodDeclarationAST *ast)
Symbol
*
symbol
;
if
(
ast
->
function_body
)
{
symbol
=
methodTy
;
methodTy
->
setStartOffset
(
tokenAt
(
ast
->
firstToken
()).
offset
);
methodTy
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
methodTy
->
members
()
->
setStartOffset
(
tokenAt
(
ast
->
function_body
->
firstToken
()).
offset
);
methodTy
->
members
()
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
}
else
{
Declaration
*
decl
=
control
()
->
newDeclaration
(
selector
->
firstToken
(),
methodTy
->
name
());
decl
->
setType
(
methodTy
);
...
...
src/shared/cplusplus/CheckDeclaration.h
View file @
867bf3da
...
...
@@ -111,6 +111,9 @@ private:
void
checkQEnumsQFlagsNames
(
NameListAST
*
nameListAst
,
const
char
*
declName
);
unsigned
calculateScopeStart
(
ObjCClassDeclarationAST
*
ast
)
const
;
unsigned
calculateScopeStart
(
ObjCProtocolDeclarationAST
*
ast
)
const
;
private:
DeclarationAST
*
_declaration
;
Scope
*
_scope
;
...
...
src/shared/cplusplus/CheckSpecifier.cpp
View file @
867bf3da
...
...
@@ -316,8 +316,8 @@ bool CheckSpecifier::visit(ClassSpecifierAST *ast)
const
Name
*
className
=
semantic
()
->
check
(
ast
->
name
,
_scope
);
Class
*
klass
=
control
()
->
newClass
(
sourceLocation
,
className
);
klass
->
setStartOffset
(
classScopeStart
);
klass
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
klass
->
members
()
->
setStartOffset
(
classScopeStart
);
klass
->
members
()
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
ast
->
symbol
=
klass
;
unsigned
classKey
=
tokenKind
(
ast
->
classkey_token
);
if
(
classKey
==
T_CLASS
)
...
...
@@ -407,8 +407,8 @@ bool CheckSpecifier::visit(EnumSpecifierAST *ast)
const
Name
*
name
=
semantic
()
->
check
(
ast
->
name
,
_scope
);
Enum
*
e
=
control
()
->
newEnum
(
sourceLocation
,
name
);
e
->
setStartOffset
(
scopeStart
);
e
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
e
->
members
()
->
setStartOffset
(
scopeStart
);
e
->
members
()
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
e
->
setVisibility
(
semantic
()
->
currentVisibility
());
_scope
->
enterSymbol
(
e
);
_fullySpecifiedType
.
setType
(
e
);
...
...
src/shared/cplusplus/CheckStatement.cpp
View file @
867bf3da
...
...
@@ -111,8 +111,8 @@ bool CheckStatement::visit(CaseStatementAST *ast)
bool
CheckStatement
::
visit
(
CompoundStatementAST
*
ast
)
{
Block
*
block
=
control
()
->
newBlock
(
ast
->
lbrace_token
);
block
->
setStartOffset
(
tokenAt
(
ast
->
firstToken
()).
end
());
block
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
block
->
members
()
->
setStartOffset
(
tokenAt
(
ast
->
firstToken
()).
end
());
block
->
members
()
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
ast
->
symbol
=
block
;
_scope
->
enterSymbol
(
block
);
Scope
*
previousScope
=
switchScope
(
block
->
members
());
...
...
@@ -167,6 +167,7 @@ bool CheckStatement::visit(ExpressionStatementAST *ast)
}
bool
CheckStatement
::
forEachFastEnum
(
unsigned
firstToken
,
unsigned
lparen
,
unsigned
lastToken
,
SpecifierListAST
*
type_specifier_list
,
DeclaratorAST
*
declarator
,
...
...
@@ -175,9 +176,13 @@ bool CheckStatement::forEachFastEnum(unsigned firstToken,
StatementAST
*
statement
,
Block
*&
symbol
)
{
unsigned
scopeStart
=
tokenAt
(
firstToken
).
offset
;
if
(
lparen
)
scopeStart
=
tokenAt
(
lparen
).
end
();
Block
*
block
=
control
()
->
newBlock
(
firstToken
);
block
->
setStartOffset
(
tokenAt
(
firstToken
).
offse
t
);
block
->
setEndOffset
(
tokenAt
(
lastToken
-
1
).
end
());
block
->
members
()
->
setStartOffset
(
scopeStar
t
);
block
->
members
()
->
setEndOffset
(
tokenAt
(
lastToken
-
1
).
end
());
symbol
=
block
;
_scope
->
enterSymbol
(
block
);
Scope
*
previousScope
=
switchScope
(
block
->
members
());
...
...
@@ -205,6 +210,7 @@ bool CheckStatement::forEachFastEnum(unsigned firstToken,
bool
CheckStatement
::
visit
(
ForeachStatementAST
*
ast
)
{
return
forEachFastEnum
(
ast
->
firstToken
(),
ast
->
lparen_token
,
ast
->
lastToken
(),
ast
->
type_specifier_list
,
ast
->
declarator
,
...
...
@@ -217,6 +223,7 @@ bool CheckStatement::visit(ForeachStatementAST *ast)
bool
CheckStatement
::
visit
(
ObjCFastEnumerationAST
*
ast
)
{
return
forEachFastEnum
(
ast
->
firstToken
(),
ast
->
lparen_token
,
ast
->
lastToken
(),
ast
->
type_specifier_list
,
ast
->
declarator
,
...
...
@@ -228,9 +235,13 @@ bool CheckStatement::visit(ObjCFastEnumerationAST *ast)
bool
CheckStatement
::
visit
(
ForStatementAST
*
ast
)
{
unsigned
scopeStart
=
tokenAt
(
ast
->
firstToken
()).
offset
;
if
(
ast
->
lparen_token
)
scopeStart
=
tokenAt
(
ast
->
lparen_token
).
end
();
Block
*
block
=
control
()
->
newBlock
(
ast
->
for_token
);
block
->
setStartOffset
(
tokenAt
(
ast
->
firstToken
()).
offse
t
);
block
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
block
->
members
()
->
setStartOffset
(
scopeStar
t
);
block
->
members
()
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
ast
->
symbol
=
block
;
_scope
->
enterSymbol
(
block
);
Scope
*
previousScope
=
switchScope
(
block
->
members
());
...
...
@@ -245,9 +256,13 @@ bool CheckStatement::visit(ForStatementAST *ast)
bool
CheckStatement
::
visit
(
IfStatementAST
*
ast
)
{
unsigned
scopeStart
=
tokenAt
(
ast
->
firstToken
()).
offset
;
if
(
ast
->
lparen_token
)
scopeStart
=
tokenAt
(
ast
->
lparen_token
).
end
();
Block
*
block
=
control
()
->
newBlock
(
ast
->
if_token
);
block
->
setStartOffset
(
tokenAt
(
ast
->
firstToken
()).
offse
t
);
block
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
block
->
members
()
->
setStartOffset
(
scopeStar
t
);
block
->
members
()
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
ast
->
symbol
=
block
;
_scope
->
enterSymbol
(
block
);
Scope
*
previousScope
=
switchScope
(
block
->
members
());
...
...
@@ -292,9 +307,13 @@ bool CheckStatement::visit(ReturnStatementAST *ast)
bool
CheckStatement
::
visit
(
SwitchStatementAST
*
ast
)
{
unsigned
scopeStart
=
tokenAt
(
ast
->
firstToken
()).
offset
;
if
(
ast
->
lparen_token
)
scopeStart
=
tokenAt
(
ast
->
lparen_token
).
offset
;
Block
*
block
=
control
()
->
newBlock
(
ast
->
switch_token
);
block
->
setStartOffset
(
tokenAt
(
ast
->
firstToken
()).
offse
t
);
block
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
block
->
members
()
->
setStartOffset
(
scopeStar
t
);
block
->
members
()
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
ast
->
symbol
=
block
;
_scope
->
enterSymbol
(
block
);
Scope
*
previousScope
=
switchScope
(
block
->
members
());
...
...
@@ -317,9 +336,13 @@ bool CheckStatement::visit(TryBlockStatementAST *ast)
bool
CheckStatement
::
visit
(
CatchClauseAST
*
ast
)
{
unsigned
scopeStart
=
tokenAt
(
ast
->
firstToken
()).
offset
;
if
(
ast
->
lparen_token
)
scopeStart
=
tokenAt
(
ast
->
lparen_token
).
end
();
Block
*
block
=
control
()
->
newBlock
(
ast
->
catch_token
);
block
->
setStartOffset
(
tokenAt
(
ast
->
firstToken
()).
offse
t
);
block
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
block
->
members
()
->
setStartOffset
(
scopeStar
t
);
block
->
members
()
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
ast
->
symbol
=
block
;
_scope
->
enterSymbol
(
block
);
Scope
*
previousScope
=
switchScope
(
block
->
members
());
...
...
@@ -332,9 +355,13 @@ bool CheckStatement::visit(CatchClauseAST *ast)
bool
CheckStatement
::
visit
(
WhileStatementAST
*
ast
)
{
unsigned
scopeStart
=
tokenAt
(
ast
->
firstToken
()).
offset
;
if
(
ast
->
lparen_token
)
scopeStart
=
tokenAt
(
ast
->
lparen_token
).
end
();
Block
*
block
=
control
()
->
newBlock
(
ast
->
while_token
);
block
->
setStartOffset
(
tokenAt
(
ast
->
firstToken
()).
offse
t
);
block
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
block
->
members
()
->
setStartOffset
(
scopeStar
t
);
block
->
members
()
->
setEndOffset
(
tokenAt
(
ast
->
lastToken
()
-
1
).
end
());
ast
->
symbol
=
block
;
_scope
->
enterSymbol
(
block
);
Scope
*
previousScope
=
switchScope
(
block
->
members
());
...
...
src/shared/cplusplus/CheckStatement.h
View file @
867bf3da
...
...
@@ -92,6 +92,7 @@ protected:
virtual
bool
visit
(
QtMemberDeclarationAST
*
ast
);
bool
forEachFastEnum
(
unsigned
firstToken
,
unsigned
lparen
,
unsigned
lastToken
,
SpecifierListAST
*
type_specifier_list
,
DeclaratorAST
*
declarator
,
...
...
src/shared/cplusplus/Symbols.cpp
View file @
867bf3da
...
...
@@ -427,18 +427,6 @@ Scope *ScopedSymbol::members() const
void
ScopedSymbol
::
addMember
(
Symbol
*
member
)
{
_members
->
enterSymbol
(
member
);
}
unsigned
ScopedSymbol
::
startOffset
()
const
{
return
_members
->
startOffset
();
}
void
ScopedSymbol
::
setStartOffset
(
unsigned
offset
)
{
_members
->
setStartOffset
(
offset
);
}
unsigned
ScopedSymbol
::
endOffset
()
const
{
return
_members
->
endOffset
();
}
void
ScopedSymbol
::
setEndOffset
(
unsigned
offset
)
{
_members
->
setEndOffset
(
offset
);
}
Block
::
Block
(
TranslationUnit
*
translationUnit
,
unsigned
sourceLocation
)
:
ScopedSymbol
(
translationUnit
,
sourceLocation
,
/*name = */
0
)
{
}
...
...
src/shared/cplusplus/Symbols.h
View file @
867bf3da
...
...
@@ -234,14 +234,6 @@ public:
virtual
ScopedSymbol
*
asScopedSymbol
()
{
return
this
;
}
/// Set the start offset of the scope for this symbol
unsigned
startOffset
()
const
;
void
setStartOffset
(
unsigned
offset
);
/// Set the end offset of the scope for this symbol
unsigned
endOffset
()
const
;
void
setEndOffset
(
unsigned
offset
);
private:
Scope
*
_members
;
};
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment