Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
kdevelop
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Rolf Eike Beer
kdevelop
Commits
a048f702
Commit
a048f702
authored
Nov 15, 2013
by
Andrea Scarpino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement identifiers types, functions types, functions arguments types
parent
44481027
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
53 additions
and
15 deletions
+53
-15
duchain/contextbuilder.cpp
duchain/contextbuilder.cpp
+8
-1
duchain/contextbuilder.h
duchain/contextbuilder.h
+2
-0
duchain/declarationbuilder.cpp
duchain/declarationbuilder.cpp
+10
-0
duchain/declarationbuilder.h
duchain/declarationbuilder.h
+3
-0
duchain/expressionvisitor.cpp
duchain/expressionvisitor.cpp
+12
-4
duchain/expressionvisitor.h
duchain/expressionvisitor.h
+10
-7
tests/files/helloworld.js
tests/files/helloworld.js
+8
-3
No files found.
duchain/contextbuilder.cpp
View file @
a048f702
...
...
@@ -18,7 +18,7 @@
*************************************************************************************/
#include "contextbuilder.h"
#include "expressionvisitor.h"
#include "parsesession.h"
using
namespace
KDevelop
;
...
...
@@ -41,6 +41,13 @@ QualifiedIdentifier ContextBuilder::identifierForNode(QmlJS::AST::IdentifierProp
return
QualifiedIdentifier
(
node
->
id
.
toString
());
}
AbstractType
::
Ptr
ContextBuilder
::
findType
(
QmlJS
::
AST
::
Node
*
node
)
{
ExpressionVisitor
visitor
(
currentContext
());
QmlJS
::
AST
::
Node
::
accept
(
node
,
&
visitor
);
return
visitor
.
lastType
();
}
void
ContextBuilder
::
setContextOnNode
(
QmlJS
::
AST
::
Node
*
node
,
DUContext
*
context
)
{
m_session
->
setContextOnNode
(
node
,
context
);
...
...
duchain/contextbuilder.h
View file @
a048f702
...
...
@@ -21,6 +21,7 @@
#define CONTEXTBUILDER_H
#include <language/duchain/builders/abstractcontextbuilder.h>
#include <language/duchain/types/abstracttype.h>
#include <qmljs/parser/qmljsast_p.h>
#include <qmljs/qmljsdocument.h>
...
...
@@ -62,6 +63,7 @@ public:
virtual
KDevelop
::
TopDUContext
*
newTopContext
(
const
KDevelop
::
RangeInRevision
&
range
,
KDevelop
::
ParsingEnvironmentFile
*
file
=
0
);
KDevelop
::
AbstractType
::
Ptr
findType
(
QmlJS
::
AST
::
Node
*
node
);
void
setParseSession
(
ParseSession
*
session
);
using
Visitor
::
visit
;
...
...
duchain/declarationbuilder.cpp
View file @
a048f702
...
...
@@ -116,11 +116,21 @@ bool DeclarationBuilder::visit(QmlJS::AST::FormalParameterList* node)
IntegralType
*
type
=
new
IntegralType
(
IntegralType
::
TypeMixed
);
dec
->
setType
(
IntegralType
::
Ptr
(
type
));
closeDeclaration
();
FunctionType
::
Ptr
funType
=
currentType
<
FunctionType
>
();
funType
->
addArgument
(
findType
(
plist
));
}
return
DeclarationBuilderBase
::
visit
(
node
);
}
void
DeclarationBuilder
::
endVisit
(
QmlJS
::
AST
::
ReturnStatement
*
node
)
{
DeclarationBuilderBase
::
endVisit
(
node
);
FunctionType
::
Ptr
type
=
currentType
<
FunctionType
>
();
type
->
setReturnType
(
findType
(
node
->
expression
));
}
bool
DeclarationBuilder
::
visit
(
QmlJS
::
AST
::
VariableDeclaration
*
node
)
{
setComment
(
m_session
->
commentForLocation
(
node
->
firstSourceLocation
()).
toUtf8
());
...
...
duchain/declarationbuilder.h
View file @
a048f702
...
...
@@ -47,8 +47,11 @@ protected:
virtual
bool
visit
(
QmlJS
::
AST
::
FormalParameterList
*
node
);
virtual
bool
visit
(
QmlJS
::
AST
::
VariableDeclaration
*
node
);
virtual
void
endVisit
(
QmlJS
::
AST
::
ReturnStatement
*
node
);
virtual
bool
visit
(
QmlJS
::
AST
::
UiObjectDefinition
*
node
);
virtual
void
endVisit
(
QmlJS
::
AST
::
UiObjectDefinition
*
node
);
virtual
bool
visit
(
QmlJS
::
AST
::
UiObjectInitializer
*
node
);
virtual
bool
visit
(
QmlJS
::
AST
::
UiScriptBinding
*
node
);
...
...
duchain/expressionvisitor.cpp
View file @
a048f702
...
...
@@ -18,13 +18,15 @@
#include "expressionvisitor.h"
#include <language/duchain/declaration.h>
#include "helper.h"
using
namespace
KDevelop
;
AbstractType
::
Ptr
findType
(
QmlJS
::
AST
::
Node
*
node
)
ExpressionVisitor
::
ExpressionVisitor
(
DUContext
*
context
)
:
m_context
(
context
)
{
ExpressionVisitor
visitor
;
QmlJS
::
AST
::
Node
::
accept
(
node
,
&
visitor
);
return
visitor
.
lastType
();
}
void
ExpressionVisitor
::
endVisit
(
QmlJS
::
AST
::
ArrayLiteral
*
node
)
...
...
@@ -39,6 +41,12 @@ void ExpressionVisitor::endVisit(QmlJS::AST::FalseLiteral* node)
m_lastType
.
push
(
AbstractType
::
Ptr
(
new
IntegralType
(
IntegralType
::
TypeBoolean
)));
}
void
ExpressionVisitor
::
endVisit
(
QmlJS
::
AST
::
IdentifierExpression
*
node
)
{
const
QualifiedIdentifier
name
(
node
->
name
.
toString
());
m_lastType
.
push
(
QmlJS
::
getDeclaration
(
name
,
DUContextPointer
(
m_context
))
->
abstractType
());
}
void
ExpressionVisitor
::
endVisit
(
QmlJS
::
AST
::
NumericLiteral
*
node
)
{
if
(
QString
::
number
(
node
->
value
).
contains
(
'.'
))
{
...
...
duchain/expressionvisitor.h
View file @
a048f702
...
...
@@ -22,30 +22,33 @@
#include <QStack>
#include <language/duchain/types/integraltype.h>
#include <language/duchain/ducontext.h>
#include <qmljs/parser/qmljsast_p.h>
#include "duchainexport.h"
KDevelop
::
AbstractType
::
Ptr
findType
(
QmlJS
::
AST
::
Node
*
node
);
class
KDEVQMLJSDUCHAIN_EXPORT
ExpressionVisitor
:
public
QmlJS
::
AST
::
Visitor
{
public:
explicit
ExpressionVisitor
(
KDevelop
::
DUContext
*
context
);
using
Visitor
::
visit
;
using
Visitor
::
endVisit
;
KDevelop
::
AbstractType
::
Ptr
lastType
();
protected:
virtual
void
endVisit
(
QmlJS
::
AST
::
ArrayLiteral
*
);
virtual
void
endVisit
(
QmlJS
::
AST
::
FalseLiteral
*
);
virtual
void
endVisit
(
QmlJS
::
AST
::
NumericLiteral
*
);
virtual
void
endVisit
(
QmlJS
::
AST
::
StringLiteral
*
);
virtual
void
endVisit
(
QmlJS
::
AST
::
TrueLiteral
*
);
virtual
void
endVisit
(
QmlJS
::
AST
::
ArrayLiteral
*
node
);
virtual
void
endVisit
(
QmlJS
::
AST
::
FalseLiteral
*
node
);
virtual
void
endVisit
(
QmlJS
::
AST
::
IdentifierExpression
*
node
);
virtual
void
endVisit
(
QmlJS
::
AST
::
NumericLiteral
*
node
);
virtual
void
endVisit
(
QmlJS
::
AST
::
StringLiteral
*
node
);
virtual
void
endVisit
(
QmlJS
::
AST
::
TrueLiteral
*
node
);
private:
QStack
<
KDevelop
::
AbstractType
::
Ptr
>
m_lastType
;
KDevelop
::
DUContext
*
m_context
;
};
...
...
tests/files/helloworld.js
View file @
a048f702
...
...
@@ -12,6 +12,11 @@ function helloWorld()
*/
var
a
=
5
;
/**
* "type" : { "toString" : "int" }
*/
var
b
=
a
;
/**
* "type" : { "toString" : "double" }
*/
...
...
@@ -23,7 +28,7 @@ var d = 1.2;
var
array
=
[
1
,
2
,
3
];
/**
* "
EXPECT_FAIL" : { "returnType" : "return type is not properly deduced
" },
* "
type" : { "toString" : "function string ()
" },
* "returnType" : { "toString" : "string" }
*/
function
testVariables
()
...
...
@@ -36,8 +41,8 @@ function testVariables()
}
/**
* "
EXPECT_FAIL" : { "type" : "neither arg type nor ret type is properly deduced
" },
* "
type": { "toString" : "function mixed (mixed)
" }
* "
type": { "toString" : "function mixed (mixed)
" },
* "
returnType" : { "toString" : "mixed
" }
*/
function
testReturnMixedArg
(
arg
)
{
...
...
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