[cfe-commits] r41990 - in /cfe/trunk: Driver/Makefile Makefile Rewrite/ Rewrite/Makefile Rewrite/Rewriter.cpp clang.xcodeproj/project.pbxproj include/clang/Rewrite/ include/clang/Rewrite/Rewriter.h

Chris Lattner sabre at nondot.org
Sat Sep 15 15:21:22 PDT 2007


Author: lattner
Date: Sat Sep 15 17:21:22 2007
New Revision: 41990

URL: http://llvm.org/viewvc/llvm-project?rev=41990&view=rev
Log:
Initial checkin of rewriter interface.  It is just stubbed out for now.

Added:
    cfe/trunk/Rewrite/
    cfe/trunk/Rewrite/Makefile
    cfe/trunk/Rewrite/Rewriter.cpp
    cfe/trunk/include/clang/Rewrite/
    cfe/trunk/include/clang/Rewrite/Rewriter.h
Modified:
    cfe/trunk/Driver/Makefile
    cfe/trunk/Makefile
    cfe/trunk/clang.xcodeproj/project.pbxproj

Modified: cfe/trunk/Driver/Makefile
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/Makefile?rev=41990&r1=41989&r2=41990&view=diff

==============================================================================
--- cfe/trunk/Driver/Makefile (original)
+++ cfe/trunk/Driver/Makefile Sat Sep 15 17:21:22 2007
@@ -3,6 +3,8 @@
 CXXFLAGS = -fno-rtti
 
 TOOLNAME = clang
-USEDLIBS = clangCodeGen.a clangAnalysis.a clangSEMA.a clangAST.a clangParse.a clangLex.a clangBasic.a LLVMCore.a LLVMSupport.a LLVMSystem.a
+USEDLIBS = clangCodeGen.a clangAnalysis.a clangRewrite.a clangSEMA.a \
+           clangAST.a clangParse.a clangLex.a clangBasic.a \
+           LLVMCore.a LLVMSupport.a LLVMSystem.a
 
 include $(LEVEL)/Makefile.common

Modified: cfe/trunk/Makefile
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Makefile?rev=41990&r1=41989&r2=41990&view=diff

==============================================================================
--- cfe/trunk/Makefile (original)
+++ cfe/trunk/Makefile Sat Sep 15 17:21:22 2007
@@ -1,5 +1,5 @@
 LEVEL = ../..
-DIRS := Basic Lex Parse AST Sema CodeGen Analysis Driver
+DIRS := Basic Lex Parse AST Sema CodeGen Analysis Rewrite Driver
 
 include $(LEVEL)/Makefile.common
 

Added: cfe/trunk/Rewrite/Makefile
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Rewrite/Makefile?rev=41990&view=auto

==============================================================================
--- cfe/trunk/Rewrite/Makefile (added)
+++ cfe/trunk/Rewrite/Makefile Sat Sep 15 17:21:22 2007
@@ -0,0 +1,22 @@
+##===- clang/Rewrite/Makefile ------------------------------*- Makefile -*-===##
+# 
+#                     The LLVM Compiler Infrastructure
+#
+# This file was developed by Chris Lattner and is distributed under
+# the University of Illinois Open Source License. See LICENSE.TXT for details.
+# 
+##===----------------------------------------------------------------------===##
+#
+# This implements code transformation / rewriting facilities.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../../..
+LIBRARYNAME := clangRewrite
+BUILD_ARCHIVE = 1
+CXXFLAGS = -fno-rtti
+
+CPPFLAGS += -I$(PROJ_SRC_DIR)/../include
+
+include $(LEVEL)/Makefile.common
+

Added: cfe/trunk/Rewrite/Rewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Rewrite/Rewriter.cpp?rev=41990&view=auto

==============================================================================
--- cfe/trunk/Rewrite/Rewriter.cpp (added)
+++ cfe/trunk/Rewrite/Rewriter.cpp Sat Sep 15 17:21:22 2007
@@ -0,0 +1,26 @@
+//===--- Rewriter.cpp - Code rewriting interface --------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Chris Lattner and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file defines the Rewriter class, which is used for code
+//  transformations.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Rewrite/Rewriter.h"
+using namespace clang;
+
+
+void RewriteBuffer::RemoveText(unsigned OrigOffset, unsigned Size) {
+  // FIXME:
+}
+
+void RewriteBuffer::InsertText(unsigned OrigOffset,
+                               const char *StrData, unsigned StrLen) {
+  // FIXME:
+}

Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=41990&r1=41989&r2=41990&view=diff

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Sat Sep 15 17:21:22 2007
@@ -131,6 +131,8 @@
 		DEF2EDA70C6A4252000C4259 /* StmtDumper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DEF2EDA60C6A4252000C4259 /* StmtDumper.cpp */; };
 		DEF2EFF30C6CDD74000C4259 /* CGExprAgg.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DEF2EFF20C6CDD74000C4259 /* CGExprAgg.cpp */; };
 		DEF2F0100C6CFED5000C4259 /* SemaChecking.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DEF2F00F0C6CFED5000C4259 /* SemaChecking.cpp */; };
+		DEF7D9F70C9C8B1A0001F598 /* Rewriter.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DEF7D9F60C9C8B1A0001F598 /* Rewriter.h */; };
+		DEF7D9F90C9C8B1D0001F598 /* Rewriter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DEF7D9F80C9C8B1D0001F598 /* Rewriter.cpp */; };
 		F0226FD20C18084500141F42 /* TextDiagnosticPrinter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F0226FD00C18084500141F42 /* TextDiagnosticPrinter.cpp */; };
 		F0226FD30C18084500141F42 /* TextDiagnosticPrinter.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = F0226FD10C18084500141F42 /* TextDiagnosticPrinter.h */; };
 /* End PBXBuildFile section */
@@ -199,6 +201,7 @@
 				DEF2E9320C5FB9FB000C4259 /* ASTStreamers.h in CopyFiles */,
 				DEF2E95F0C5FBD74000C4259 /* InternalsManual.html in CopyFiles */,
 				DEC63B1C0C7B940600DBF169 /* CFG.h in CopyFiles */,
+				DEF7D9F70C9C8B1A0001F598 /* Rewriter.h in CopyFiles */,
 			);
 			runOnlyForDeploymentPostprocessing = 1;
 		};
@@ -339,6 +342,8 @@
 		DEF2EDA60C6A4252000C4259 /* StmtDumper.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = StmtDumper.cpp; path = AST/StmtDumper.cpp; sourceTree = "<group>"; };
 		DEF2EFF20C6CDD74000C4259 /* CGExprAgg.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = CGExprAgg.cpp; path = CodeGen/CGExprAgg.cpp; sourceTree = "<group>"; };
 		DEF2F00F0C6CFED5000C4259 /* SemaChecking.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = SemaChecking.cpp; path = Sema/SemaChecking.cpp; sourceTree = "<group>"; };
+		DEF7D9F60C9C8B1A0001F598 /* Rewriter.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Rewriter.h; path = clang/Rewrite/Rewriter.h; sourceTree = "<group>"; };
+		DEF7D9F80C9C8B1D0001F598 /* Rewriter.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = Rewriter.cpp; path = Rewrite/Rewriter.cpp; sourceTree = "<group>"; };
 		F0226FD00C18084500141F42 /* TextDiagnosticPrinter.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = TextDiagnosticPrinter.cpp; path = Driver/TextDiagnosticPrinter.cpp; sourceTree = "<group>"; };
 		F0226FD10C18084500141F42 /* TextDiagnosticPrinter.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = TextDiagnosticPrinter.h; path = Driver/TextDiagnosticPrinter.h; sourceTree = "<group>"; };
 /* End PBXFileReference section */
@@ -376,6 +381,7 @@
 				DE67E7070C020EAB00F66BC5 /* Sema */,
 				DE927FCC0C0557CD00231DA4 /* CodeGen */,
 				356EF9B30C8F7DCA006650F5 /* Analysis */,
+				DEF7D9F50C9C8B0C0001F598 /* Rewrite */,
 			);
 			name = Source;
 			sourceTree = "<group>";
@@ -588,6 +594,7 @@
 				DE67E7260C02108300F66BC5 /* Sema */,
 				DE928B140C05659A00231DA4 /* CodeGen */,
 				356EF9AF0C8F7DA4006650F5 /* Analysis */,
+				DEF7D9F40C9C8B020001F598 /* Rewrite */,
 			);
 			path = include;
 			sourceTree = "<group>";
@@ -659,6 +666,22 @@
 			path = Lex;
 			sourceTree = "<group>";
 		};
+		DEF7D9F40C9C8B020001F598 /* Rewrite */ = {
+			isa = PBXGroup;
+			children = (
+				DEF7D9F60C9C8B1A0001F598 /* Rewriter.h */,
+			);
+			name = Rewrite;
+			sourceTree = "<group>";
+		};
+		DEF7D9F50C9C8B0C0001F598 /* Rewrite */ = {
+			isa = PBXGroup;
+			children = (
+				DEF7D9F80C9C8B1D0001F598 /* Rewriter.cpp */,
+			);
+			name = Rewrite;
+			sourceTree = "<group>";
+		};
 /* End PBXGroup section */
 
 /* Begin PBXNativeTarget section */
@@ -770,6 +793,7 @@
 				356EF9B50C8F7DDF006650F5 /* LiveVariables.cpp in Sources */,
 				355CF6840C90A8D400A08AA3 /* DeadStores.cpp in Sources */,
 				35AE0F690C9B4CC200CC1279 /* UnintializedValues.cpp in Sources */,
+				DEF7D9F90C9C8B1D0001F598 /* Rewriter.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Added: cfe/trunk/include/clang/Rewrite/Rewriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Rewrite/Rewriter.h?rev=41990&view=auto

==============================================================================
--- cfe/trunk/include/clang/Rewrite/Rewriter.h (added)
+++ cfe/trunk/include/clang/Rewrite/Rewriter.h Sat Sep 15 17:21:22 2007
@@ -0,0 +1,88 @@
+//===--- Rewriter.h - Code rewriting interface ------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Chris Lattner and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file defines the Rewriter class, which is used for code
+//  transformations.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_REWRITER_H
+#define LLVM_CLANG_REWRITER_H
+
+#include <vector>
+
+namespace clang {
+  class SourceManager;
+  class SourceLocation;
+  
+/// SourceDelta - As code in the original input buffer is added and deleted,
+/// SourceDelta records are used to keep track of how the input SourceLocation
+/// object is mapped into the output buffer.
+struct SourceDelta {
+  unsigned FileLoc;
+  int Delta;
+};
+
+
+/// RewriteBuffer - As code is rewritten, SourceBuffer's from the original
+/// input with modifications get a new RewriteBuffer associated with them.  The
+/// RewriteBuffer captures the modified text itself as well as information used
+/// to map between SourceLocation's in the original input and offsets in the
+/// RewriteBuffer.  For example, if text is inserted into the buffer, any
+/// locations after the insertion point have to be mapped.
+class RewriteBuffer {
+  /// Deltas - Keep track of all the deltas in the source code due to insertions
+  /// and deletions.  These are kept in sorted order based on the FileLoc.
+  std::vector<SourceDelta> Deltas;
+  
+  /// Buffer - This is the actual buffer itself.  Note that using a vector or
+  /// string is a horribly inefficient way to do this, we should use a rope
+  /// instead.
+  std::vector<char> Buffer;
+public:
+  
+  /// RemoveText - Remove the specified text.
+  void RemoveText(unsigned OrigOffset, unsigned Size);
+  
+  
+  /// InsertText - Insert some text at the specified point, where the offset in
+  /// the buffer is specified relative to the original SourceBuffer.
+  ///
+  /// TODO: Consider a bool to indicate whether the text is inserted 'before' or
+  /// after the atomic point: i.e. whether the atomic point is moved to after
+  /// the inserted text or not.
+  void InsertText(unsigned OrigOffset, const char *StrData, unsigned StrLen);
+  
+};
+  
+class Rewriter {
+  SourceManager &SourceMgr;
+  
+  // FIXME: list of buffers.
+public:
+  explicit Rewriter(SourceManager &SM) : SourceMgr(SM) {}
+  
+  /// InsertText - Insert the specified string at the specified location in the
+  /// original buffer.
+  bool InsertText(SourceLocation Loc, const char *StrData, unsigned StrLen);
+  
+  /// RemoveText - Remove the specified text region.
+  bool RemoveText(SourceLocation Start, SourceLocation End);
+  
+  
+  // TODO: Replace Stmt/Expr with another.
+  
+  
+  // Write out output buffer.
+  
+};
+  
+} // end namespace clang
+
+#endif





More information about the cfe-commits mailing list