]> granicus.if.org Git - clang/commitdiff
Add a new -rewrite-test option, which is basically a
authorChris Lattner <sabre@nondot.org>
Sun, 12 Oct 2008 05:29:20 +0000 (05:29 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 12 Oct 2008 05:29:20 +0000 (05:29 +0000)
playground to experiment with some new rewriter approaches. For now
it is probably the most complex version of 'cat' ever invented.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57406 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/RewriteTest.cpp [new file with mode: 0644]
Driver/clang.cpp
Driver/clang.h
clang.xcodeproj/project.pbxproj

diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp
new file mode 100644 (file)
index 0000000..446ae1a
--- /dev/null
@@ -0,0 +1,41 @@
+//===--- RewriteTest.cpp - Rewriter playground ----------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This is a testbed.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Rewrite/TokenRewriter.h"
+#include "clang.h"
+#include "clang/Lex/Preprocessor.h"
+#include <iostream>
+
+void clang::DoRewriteTest(Preprocessor &PP, const std::string &InFileName,
+                          const std::string &OutFileName) {
+  SourceManager &SM = PP.getSourceManager();
+  const LangOptions &LangOpts = PP.getLangOptions();
+
+  std::pair<const char*,const char*> File =SM.getBufferData(SM.getMainFileID());
+  
+  // Create a lexer to lex all the tokens of the main file in raw mode.  Even
+  // though it is in raw mode, it will not return comments.
+  Lexer RawLex(SourceLocation::getFileLoc(SM.getMainFileID(), 0),
+               LangOpts, File.first, File.second);
+  
+  RawLex.SetKeepWhitespaceMode(true);
+  
+  Token RawTok;
+  RawLex.LexFromRawLexer(RawTok);
+  while (RawTok.isNot(tok::eof)) {
+    std::cout << PP.getSpelling(RawTok);
+    RawLex.LexFromRawLexer(RawTok);
+  }
+  
+  
+}
\ No newline at end of file
index 91d521246ab3e464f5a8078f2239420f6dce2bfa..ae7ec879ddab0b840aebd9a9978ad1e36a660780 100644 (file)
@@ -66,6 +66,7 @@ enum ProgActions {
   RewriteObjC,                  // ObjC->C Rewriter.
   RewriteBlocks,                // ObjC->C Rewriter for Blocks.
   RewriteMacros,                // Expand macros but not #includes.
+  RewriteTest,                  // Rewriter playground
   HTMLTest,                     // HTML displayer testing stuff.
   EmitLLVM,                     // Emit a .ll file.
   EmitBC,                       // Emit a .bc file.
@@ -119,6 +120,8 @@ ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
                         "Build ASTs then convert to LLVM, emit .bc file"),
              clEnumValN(SerializeAST, "serialize",
                         "Build ASTs and emit .ast file"),
+             clEnumValN(RewriteTest, "rewrite-test",
+                        "Rewriter playground"),
              clEnumValN(RewriteObjC, "rewrite-objc",
                         "Rewrite ObjC into C (code rewriter example)"),
              clEnumValN(RewriteMacros, "rewrite-macros",
@@ -1173,6 +1176,11 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
     RewriteMacrosInInput(PP, InFile, OutputFile);
     ClearSourceMgr = true;
     break;
+      
+  case RewriteTest:
+    DoRewriteTest(PP, InFile, OutputFile);
+    ClearSourceMgr = true;
+    break;
   }
   
   if (Consumer) {
index ddb5dcb11d8f5af289ed362e0996e62e27108057..829467546d0e0bdd596d9d35f816755cb2153870 100644 (file)
@@ -32,6 +32,10 @@ void DoPrintPreprocessedInput(Preprocessor &PP, const std::string& OutFile);
 /// RewriteMacrosInInput - Implement -rewrite-macros mode.
 void RewriteMacrosInInput(Preprocessor &PP, const std::string &InFileName,
                           const std::string& OutFile);
+
+void DoRewriteTest(Preprocessor &PP, const std::string &InFileName,
+                   const std::string &OutFileName);
+    
   
 /// CreatePrintParserActionsAction - Return the actions implementation that
 /// implements the -parse-print-callbacks option.
index 1d3aa080a96c3b93a953fc81327f7e584e9edb87..c6e50213b969da9c0a95ebd1267933a60d7a089c 100644 (file)
                DE4772FA0C10EAE5002239E8 /* CGStmt.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE4772F90C10EAE5002239E8 /* CGStmt.cpp */; };
                DE4772FC0C10EAEC002239E8 /* CGExpr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE4772FB0C10EAEC002239E8 /* CGExpr.cpp */; };
                DE47999C0D2EBE1A00706D2D /* SemaExprObjC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE47999B0D2EBE1A00706D2D /* SemaExprObjC.cpp */; };
+               DE4DC79E0EA1C09E00069E5A /* RewriteTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE4DC79D0EA1C09E00069E5A /* RewriteTest.cpp */; };
                DE5932D10AD60FF400BC794C /* clang.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE5932CD0AD60FF400BC794C /* clang.cpp */; };
                DE5932D20AD60FF400BC794C /* clang.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE5932CE0AD60FF400BC794C /* clang.h */; };
                DE5932D30AD60FF400BC794C /* PrintParserCallbacks.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE5932CF0AD60FF400BC794C /* PrintParserCallbacks.cpp */; };
                DE4772F90C10EAE5002239E8 /* CGStmt.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = CGStmt.cpp; path = lib/CodeGen/CGStmt.cpp; sourceTree = "<group>"; tabWidth = 2; };
                DE4772FB0C10EAEC002239E8 /* CGExpr.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = CGExpr.cpp; path = lib/CodeGen/CGExpr.cpp; sourceTree = "<group>"; tabWidth = 2; };
                DE47999B0D2EBE1A00706D2D /* SemaExprObjC.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = SemaExprObjC.cpp; path = lib/Sema/SemaExprObjC.cpp; sourceTree = "<group>"; tabWidth = 2; };
+               DE4DC7980EA1BE4400069E5A /* TokenRewriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TokenRewriter.h; path = clang/Rewrite/TokenRewriter.h; sourceTree = "<group>"; };
+               DE4DC79D0EA1C09E00069E5A /* RewriteTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RewriteTest.cpp; path = Driver/RewriteTest.cpp; sourceTree = "<group>"; };
                DE53370B0CE2D96F00D9A028 /* RewriteRope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RewriteRope.h; path = clang/Rewrite/RewriteRope.h; sourceTree = "<group>"; };
                DE5932CD0AD60FF400BC794C /* clang.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = clang.cpp; path = Driver/clang.cpp; sourceTree = "<group>"; };
                DE5932CE0AD60FF400BC794C /* clang.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = clang.h; path = Driver/clang.h; sourceTree = "<group>"; };
                                9030C1090E807A9300941490 /* RewriteBlocks.cpp */,
                                DEA0EBD90DD2D3C8007A02A9 /* RewriteMacros.cpp */,
                                035611E10DB40C8100D2EF2A /* RewriteObjC.cpp */,
+                               DE4DC79D0EA1C09E00069E5A /* RewriteTest.cpp */,
                                352981080CC58344008B5E84 /* SerializationTest.cpp */,
                        );
                        name = Driver;
                                35F2BE7B0DAC2963006E7668 /* HTMLRewrite.h */,
                                DEF7D9F60C9C8B1A0001F598 /* Rewriter.h */,
                                DE53370B0CE2D96F00D9A028 /* RewriteRope.h */,
+                               DE4DC7980EA1BE4400069E5A /* TokenRewriter.h */,
                        );
                        name = Rewrite;
                        sourceTree = "<group>";
                                355106860E9A8507006A4E44 /* MemRegion.cpp in Sources */,
                                3551068C0E9A8546006A4E44 /* ParsePragma.cpp in Sources */,
                                3551068D0E9A8546006A4E44 /* ParseTentative.cpp in Sources */,
+                               DE4DC79E0EA1C09E00069E5A /* RewriteTest.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };