From 5964940d419af307e6ac6d03a6baa96d80fa516d Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Sat, 7 Feb 2015 00:42:18 -0800 Subject: [PATCH] Fix autocomplete on foreach expressions --- src/conversion/first.d | 13 +++++++++---- src/conversion/third.d | 4 +++- tests/tc007/expected1.txt | 12 ++++++++++++ tests/tc007/expected2.txt | 8 ++++++++ tests/tc007/file.d | 17 +++++++++++++++++ tests/tc007/run.sh | 8 ++++++++ 6 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 tests/tc007/expected1.txt create mode 100644 tests/tc007/expected2.txt create mode 100644 tests/tc007/file.d create mode 100755 tests/tc007/run.sh diff --git a/src/conversion/first.d b/src/conversion/first.d index f1447ed..55f4b7c 100644 --- a/src/conversion/first.d +++ b/src/conversion/first.d @@ -453,11 +453,7 @@ final class FirstPass : ASTVisitor feType.identifier.text, CompletionKind.variableName, symbolFile, feType.identifier.index, feType.type); if (symbol.type is null && feExpression !is null) - { -// Log.trace("Populating initializer"); populateInitializer(symbol, feExpression, true); -// Log.trace(symbol.initializer[]); - } symbol.parent = currentSymbol; currentSymbol.addChild(symbol); } @@ -888,6 +884,15 @@ class InitializerVisitor : ASTVisitor on = false; } + override void visit(const ExpressionNode expression) + { + on = true; + expression.accept(this); + if (appendForeach) + semanticSymbol.initializer.insert(internString("foreach")); + on = false; + } + SemanticSymbol* semanticSymbol; bool on = false; const bool appendForeach; diff --git a/src/conversion/third.d b/src/conversion/third.d index b16f3b9..2f0200e 100644 --- a/src/conversion/third.d +++ b/src/conversion/third.d @@ -26,6 +26,7 @@ import actypes; import messages; import std.allocator; import string_interning; +import stupidlog; /** * Third pass handles the following: @@ -95,7 +96,6 @@ private: void thirdPass(SemanticSymbol* currentSymbol) { -// Log.trace("third pass on ", currentSymbol.acSymbol.name); with (CompletionKind) final switch (currentSymbol.acSymbol.kind) { case className: @@ -242,6 +242,7 @@ private: s = s.type; if (slice.front == "foreach") { +// Log.trace("foreach"); if (s.qualifier == SymbolQualifier.array) s = s.type; else @@ -252,6 +253,7 @@ private: else s = null; } + slice.popFront(); } else if (slice.front == "[]") s = s.type; diff --git a/tests/tc007/expected1.txt b/tests/tc007/expected1.txt new file mode 100644 index 0000000..c7f4f34 --- /dev/null +++ b/tests/tc007/expected1.txt @@ -0,0 +1,12 @@ +identifiers +alignof k +dup k +idup k +init k +length k +mangleof k +ptr k +reverse k +sizeof k +sort k +stringof k diff --git a/tests/tc007/expected2.txt b/tests/tc007/expected2.txt new file mode 100644 index 0000000..9a132a4 --- /dev/null +++ b/tests/tc007/expected2.txt @@ -0,0 +1,8 @@ +identifiers +alignof k +init k +mangleof k +max k +min k +sizeof k +stringof k diff --git a/tests/tc007/file.d b/tests/tc007/file.d new file mode 100644 index 0000000..4f69ecc --- /dev/null +++ b/tests/tc007/file.d @@ -0,0 +1,17 @@ +struct R { int front() { return 1; } } + +void main(string[] args) +{ + foreach (arg; args) + { + arg. + } + R r; + foreach (i; r) + { + i. + } +} + + + diff --git a/tests/tc007/run.sh b/tests/tc007/run.sh new file mode 100755 index 0000000..b8d358e --- /dev/null +++ b/tests/tc007/run.sh @@ -0,0 +1,8 @@ +set -e +set -u + +dcd-client file.d -c97 > actual1.txt +diff actual1.txt expected1.txt + +dcd-client file.d -c130 > actual2.txt +diff actual2.txt expected2.txt