summaryrefslogtreecommitdiff
path: root/test/Parser
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2017-04-19 08:58:56 +0000
committerAlex Lorenz <arphaman@gmail.com>2017-04-19 08:58:56 +0000
commitaac41bcdb19f21fb20a2efdc19494b622ba29171 (patch)
tree345ec850b0f432a0708b5559ca86da3e1c25cdbc /test/Parser
parentad25f8b712f1ef99020fcb7b5e31dd95b39c6112 (diff)
Add support for editor placeholders to Clang
This commit teaches Clang to recognize editor placeholders that are produced when an IDE like Xcode inserts a code-completion result that includes a placeholder. Now when the lexer sees a placeholder token, it emits an 'editor placeholder in source file' error and creates an identifier token that represents the placeholder. The parser/sema can now recognize the placeholders and can suppress the diagnostics related to the placeholders. This ensures that live issues in an IDE like Xcode won't get spurious diagnostics related to placeholders. This commit also adds a new compiler option named '-fallow-editor-placeholders' that silences the 'editor placeholder in source file' error. This is useful for an IDE like Xcode as we don't want to display those errors in live issues. rdar://31581400 Differential Revision: https://reviews.llvm.org/D32081 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300667 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Parser')
-rw-r--r--test/Parser/editor-placeholder-recovery.cpp71
-rw-r--r--test/Parser/placeholder-recovery.m13
2 files changed, 79 insertions, 5 deletions
diff --git a/test/Parser/editor-placeholder-recovery.cpp b/test/Parser/editor-placeholder-recovery.cpp
new file mode 100644
index 0000000000..48c290ee9a
--- /dev/null
+++ b/test/Parser/editor-placeholder-recovery.cpp
@@ -0,0 +1,71 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -fallow-editor-placeholders -DSUPPRESS -verify %s
+
+struct Struct {
+public:
+ void method(Struct &x);
+};
+
+struct <#struct name#> {
+ int <#field-name#>;
+#ifndef SUPPRESS
+ // expected-error@-3 {{editor placeholder in source file}}
+ // expected-error@-3 {{editor placeholder in source file}}
+#endif
+};
+
+typename <#typename#>::<#name#>;
+decltype(<#expression#>) foobar;
+typedef <#type#> <#name#>;
+#ifndef SUPPRESS
+ // expected-error@-4 2 {{editor placeholder in source file}}
+ // expected-error@-4 {{editor placeholder in source file}}
+ // expected-error@-4 2 {{editor placeholder in source file}}
+#endif
+
+namespace <#identifier#> {
+ <#declarations#>
+#ifndef SUPPRESS
+ // expected-error@-3 {{editor placeholder in source file}}
+ // expected-error@-3 {{editor placeholder in source file}}
+#endif
+
+}
+
+using <#qualifier#>::<#name#>;
+#ifndef SUPPRESS
+ // expected-error@-2 2 {{editor placeholder in source file}}
+#endif
+
+void avoidPlaceholderErrors(Struct &obj) {
+ static_cast< <#type#> >(<#expression#>);
+ while (<#condition#>) {
+ <#statements#>
+ }
+ obj.method(<#Struct &x#>);
+#ifndef SUPPRESS
+ // expected-error@-6 2 {{editor placeholder in source file}}
+ // expected-error@-6 {{editor placeholder in source file}}
+ // expected-error@-6 {{editor placeholder in source file}}
+ // expected-error@-5 {{editor placeholder in source file}}
+#endif
+ switch (<#expression#>) {
+ case <#constant#>:
+ <#statements#>
+#ifndef SUPPRESS
+ // expected-error@-4 {{editor placeholder in source file}}
+ // expected-error@-4 {{editor placeholder in source file}}
+ // expected-error@-4 {{editor placeholder in source file}}
+#endif
+ break;
+
+ default:
+ break;
+ }
+}
+
+void Struct::method(<#Struct &x#>, noSupressionHere) { // expected-error {{unknown type name 'noSupressionHere'}} expected-error {{C++ requires a type specifier for all declarations}}
+#ifndef SUPPRESS
+ // expected-error@-2 {{editor placeholder in source file}}
+#endif
+}
diff --git a/test/Parser/placeholder-recovery.m b/test/Parser/placeholder-recovery.m
index b43b0e4a57..4f22ea770d 100644
--- a/test/Parser/placeholder-recovery.m
+++ b/test/Parser/placeholder-recovery.m
@@ -1,11 +1,14 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
+@protocol NSObject
+@end
+
+@protocol <#protocol name#> <NSObject> // expected-error {{editor placeholder in source file}}
+// expected-note@-1 {{protocol started here}}
+
// FIXME: We could do much better with this, if we recognized
// placeholders somehow. However, we're content with not generating
// bogus 'archaic' warnings with bad location info.
-@protocol <#protocol name#> <NSObject> // expected-error {{expected identifier or '('}} \
-// expected-error 2{{expected identifier}} \
-// expected-warning{{protocol has no object type specified; defaults to qualified 'id'}}
-<#methods#>
+<#methods#> // expected-error {{editor placeholder in source file}}
-@end
+@end // expected-error {{prefix attribute must be followed by an interface or protocol}} expected-error {{missing '@end'}}