New tests for the 'case' expression: not_empty, in_language.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51744 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/llvmc2/AutoGenerated.cpp b/tools/llvmc2/AutoGenerated.cpp
index e240fee..2bd624a 100644
--- a/tools/llvmc2/AutoGenerated.cpp
+++ b/tools/llvmc2/AutoGenerated.cpp
@@ -24,5 +24,10 @@
 using namespace llvm;
 using namespace llvmc;
 
+namespace llvmc {
+  extern LanguageMap GlobalLanguageMap;
+  extern const std::string& GetLanguage(const sys::Path& File);
+}
+
 // The auto-generated file
 #include "AutoGenerated.inc"
diff --git a/tools/llvmc2/AutoGenerated.h b/tools/llvmc2/AutoGenerated.h
index 3b65256..106a04e 100644
--- a/tools/llvmc2/AutoGenerated.h
+++ b/tools/llvmc2/AutoGenerated.h
@@ -25,7 +25,7 @@
 
   /// PopulateLanguageMap - The auto-generated function that fills in
   /// the language map (map from file extensions to language names).
-  void PopulateLanguageMap(LanguageMap& language_map);
+  void PopulateLanguageMap();
   /// PopulateCompilationGraph - The auto-generated function that
   /// populates the compilation graph with nodes and edges.
   void PopulateCompilationGraph(CompilationGraph& tools);
diff --git a/tools/llvmc2/Common.td b/tools/llvmc2/Common.td
index 364cac3..a7515b8 100644
--- a/tools/llvmc2/Common.td
+++ b/tools/llvmc2/Common.td
@@ -56,6 +56,8 @@
 def parameter_equals;
 def element_in_list;
 def input_languages_contain;
+def not_empty;
+// TOTHINK: remove?
 def default;
 
 // Boolean operators.
diff --git a/tools/llvmc2/CompilationGraph.cpp b/tools/llvmc2/CompilationGraph.cpp
index 92f3104..cf174dd 100644
--- a/tools/llvmc2/CompilationGraph.cpp
+++ b/tools/llvmc2/CompilationGraph.cpp
@@ -32,6 +32,19 @@
 extern cl::opt<std::string> OutputFilename;
 extern cl::list<std::string> Languages;
 
+namespace llvmc {
+  /// ExtsToLangs - Map from file extensions to language names.
+  LanguageMap GlobalLanguageMap;
+
+  /// GetLanguage -  Find the language name corresponding to the given file.
+  const std::string& GetLanguage(const sys::Path& File) {
+    LanguageMap::const_iterator Lang = GlobalLanguageMap.find(File.getSuffix());
+    if (Lang == GlobalLanguageMap.end())
+      throw std::runtime_error("Unknown suffix: " + File.getSuffix());
+    return Lang->second;
+  }
+}
+
 namespace {
 
   /// ChooseEdge - Return the edge with the maximum weight.
@@ -87,14 +100,6 @@
   return I->second;
 }
 
-// Find the language name corresponding to the given file.
-const std::string& CompilationGraph::getLanguage(const sys::Path& File) const {
-  LanguageMap::const_iterator Lang = ExtsToLangs.find(File.getSuffix());
-  if (Lang == ExtsToLangs.end())
-    throw std::runtime_error("Unknown suffix: " + File.getSuffix());
-  return Lang->second;
-}
-
 // Find the tools list corresponding to the given language name.
 const CompilationGraph::tools_vector_type&
 CompilationGraph::getToolsVector(const std::string& LangName) const
@@ -200,7 +205,7 @@
 
   // Determine the input language.
   const std::string& InLanguage =
-    forceLanguage ? *forceLanguage : getLanguage(In);
+    forceLanguage ? *forceLanguage : GetLanguage(In);
 
   // Add the current input language to the input language set.
   InLangs.insert(InLanguage);
diff --git a/tools/llvmc2/CompilationGraph.h b/tools/llvmc2/CompilationGraph.h
index 41731a3..7dfe78f 100644
--- a/tools/llvmc2/CompilationGraph.h
+++ b/tools/llvmc2/CompilationGraph.h
@@ -111,8 +111,6 @@
     llvm::SmallVector<llvm::IntrusiveRefCntPtr<Edge>, 3> tools_vector_type;
     typedef llvm::StringMap<tools_vector_type> tools_map_type;
 
-    /// ExtsToLangs - Map from file extensions to language names.
-    LanguageMap ExtsToLangs;
     /// ToolsMap - Map from language names to lists of tool names.
     tools_map_type ToolsMap;
     /// NodesMap - Map from tool names to Tool objects.
@@ -134,7 +132,7 @@
     /// options are passed implicitly as global variables.
     int Build(llvm::sys::Path const& tempDir);
 
-    /// getNode -Return a reference to the node correponding to the
+    /// getNode - Return a reference to the node correponding to the
     /// given tool name. Throws std::runtime_error.
     Node& getNode(const std::string& ToolName);
     const Node& getNode(const std::string& ToolName) const;
@@ -152,15 +150,10 @@
     // GraphTraits support.
     friend NodesIterator GraphBegin(CompilationGraph*);
     friend NodesIterator GraphEnd(CompilationGraph*);
-    friend void PopulateCompilationGraph(CompilationGraph&);
 
   private:
     // Helper functions.
 
-    /// getLanguage - Find out which language corresponds to the
-    /// suffix of this file.
-    const std::string& getLanguage(const llvm::sys::Path& File) const;
-
     /// getToolsVector - Return a reference to the list of tool names
     /// corresponding to the given language name. Throws
     /// std::runtime_error.
diff --git a/tools/llvmc2/Tools.td b/tools/llvmc2/Tools.td
index 0e3faa3..28fba8d 100644
--- a/tools/llvmc2/Tools.td
+++ b/tools/llvmc2/Tools.td
@@ -41,6 +41,7 @@
  (output_suffix "bc"),
  (cmd_line (case
             (switch_on "E"),
+              // TOFIX: this does not play well with -o
               "llvm-g++ -E -x c++ $INFILE",
             (default),
               "llvm-g++ -c -x c++ $INFILE -o $OUTFILE -emit-llvm")),
diff --git a/tools/llvmc2/examples/Clang.td b/tools/llvmc2/examples/Clang.td
index bc9342d..f57c726 100644
--- a/tools/llvmc2/examples/Clang.td
+++ b/tools/llvmc2/examples/Clang.td
@@ -8,9 +8,13 @@
 [(in_language ["c", "c++", "objective-c"]),
  (out_language "llvm-bitcode"),
  (output_suffix "bc"),
- // TOFIX: We should be able to test the language of the input file
  (cmd_line (case (switch_on "E"), "clang -E $INFILE",
-                 (default), "clang -emit-llvm-bc $INFILE -o $OUTFILE")),
+                 (in_language "c"),
+                     "clang -emit-llvm-bc -x c $INFILE -o $OUTFILE",
+                 (in_language "c++"),
+                     "clang -emit-llvm-bc -x c++ $INFILE -o $OUTFILE",
+                 (in_language "objective-c"),
+                     "clang -emit-llvm-bc -x objective-c$INFILE -o $OUTFILE")),
  (switch_option "E", (stop_compilation), (output_suffix "i"),
    (help "Stop after the preprocessing stage, do not run the compiler")),
  (sink)