]> granicus.if.org Git - clang/commitdiff
Add support for code completion on stdin.
authorDan Gohman <gohman@apple.com>
Tue, 26 Oct 2010 23:21:25 +0000 (23:21 +0000)
committerDan Gohman <gohman@apple.com>
Tue, 26 Oct 2010 23:21:25 +0000 (23:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117414 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/CommandLineSourceLoc.h
lib/Frontend/CompilerInstance.cpp
test/CodeCompletion/stdin.c [new file with mode: 0644]

index bea468b01791dc53c62a93f09a147e3647a37ab7..8911cfadd5303fec22dd447af994cab5e1c82ffa 100644 (file)
@@ -37,9 +37,15 @@ public:
 
     // If both tail splits were valid integers, return success.
     if (!ColSplit.second.getAsInteger(10, PSL.Column) &&
-        !LineSplit.second.getAsInteger(10, PSL.Line))
+        !LineSplit.second.getAsInteger(10, PSL.Line)) {
       PSL.FileName = LineSplit.first;
 
+      // On the command-line, stdin may be specified via "-". Inside the
+      // compiler, stdin is called "<stdin>".
+      if (PSL.FileName == "-")
+        PSL.FileName = "<stdin>";
+    }
+
     return PSL;
   }
 };
index a187140ca04153a3d80503f6282de3156206db96..95d417f63347dda8d0195cf0e3ba6842ae08afe4 100644 (file)
@@ -479,7 +479,10 @@ bool CompilerInstance::InitializeSourceManager(llvm::StringRef InputFile,
       Diags.Report(diag::err_fe_error_reading_stdin);
       return false;
     }
-    SourceMgr.createMainFileIDForMemBuffer(SB);
+    const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(),
+                                                   SB->getBufferSize(), 0);
+    SourceMgr.createMainFileID(File);
+    SourceMgr.overrideFileContents(File, SB);
   }
 
   assert(!SourceMgr.getMainFileID().isInvalid() &&
diff --git a/test/CodeCompletion/stdin.c b/test/CodeCompletion/stdin.c
new file mode 100644 (file)
index 0000000..46495b2
--- /dev/null
@@ -0,0 +1,7 @@
+enum X { x };
+enum Y { y };
+
+enum 
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=-:4:6 < %s -o - | FileCheck -check-prefix=CC1 %s
+  // CHECK-CC1: X
+  // CHECK-CC1: Y