Commit 10757091 authored by Andrea Scarpino's avatar Andrea Scarpino Committed by Milian Wolff

Build contexts for functions bodies and arguments, extend test.

parent 8ed77167
......@@ -68,3 +68,24 @@ void ContextBuilder::setParseSession(ParseSession* session)
{
m_session = session;
}
bool ContextBuilder::visit(QmlJS::AST::FunctionDeclaration* node)
{
const QualifiedIdentifier functionName(node->name.toString());
const RangeInRevision pRange = ParseSession::locationsToRange(node->lparenToken, node->rparenToken);
DUContext* parameters = openContextInternal(pRange, DUContext::Function, functionName);
visit(node->formals);
closeContext();
const RangeInRevision bRange = ParseSession::locationsToRange(node->lbraceToken, node->rbraceToken);
DUContext* body = openContextInternal(bRange, DUContext::Other, functionName);
if (compilingContexts()) {
DUChainWriteLocker lock;
body->addImportedParentContext(parameters);
}
visit(node->body);
closeContext();
return true;
}
......@@ -46,6 +46,9 @@ public:
KDevelop::ParsingEnvironmentFile* file = 0);
void setParseSession(ParseSession* session);
using Visitor::visit;
virtual bool visit(QmlJS::AST::FunctionDeclaration* node);
protected:
ParseSession* m_session;
QHash<QmlJS::AST::Node*, KDevelop::DUContext*> m_astToContext;
......
......@@ -27,7 +27,7 @@ using namespace KDevelop;
RangeInRevision ParseSession::locationToRange(const QmlJS::AST::SourceLocation& location)
{
return RangeInRevision(location.startLine - 1, location.startColumn - 1,
location.startLine - 1, location.startColumn - 1 + location.length);
location.startLine - 1, location.startColumn - 1 + location.length - 1);
}
RangeInRevision ParseSession::locationsToRange(const QmlJS::AST::SourceLocation& locationFrom,
......
......@@ -71,8 +71,10 @@ void TestContexts::testFunctionContext()
QCOMPARE(argCtx->range(), RangeInRevision(0, 12, 0, 13));
DUContext* bodyCtx = top->childContexts().last();
QCOMPARE(argCtx->type(), DUContext::Other);
QCOMPARE(argCtx->range(), RangeInRevision(0, 15, 0, 16));
QCOMPARE(bodyCtx->type(), DUContext::Other);
QCOMPARE(bodyCtx->range(), RangeInRevision(0, 15, 0, 16));
QVERIFY(bodyCtx->imports(argCtx));
}
#include "testcontexts.moc"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment