]> granicus.if.org Git - clang/commitdiff
Initial checkin of rewriter interface. It is just stubbed out for now.
authorChris Lattner <sabre@nondot.org>
Sat, 15 Sep 2007 22:21:22 +0000 (22:21 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 15 Sep 2007 22:21:22 +0000 (22:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41990 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/Makefile
Makefile
Rewrite/Makefile [new file with mode: 0644]
Rewrite/Rewriter.cpp [new file with mode: 0644]
clang.xcodeproj/project.pbxproj
include/clang/Rewrite/Rewriter.h [new file with mode: 0644]

index 3577a2bca14d0765e9e4afdc68e680b513abcef7..86c6143412eda373f5f1e8772f93455c10b9ef98 100644 (file)
@@ -3,6 +3,8 @@ CPPFLAGS += -I$(PROJ_SRC_DIR)/../include
 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
index db13637f64320fcb96f7a59ef102a02523a99a42..e7b647fe43af96b1351b4e8c0dcec3ce871e747d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -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
 
diff --git a/Rewrite/Makefile b/Rewrite/Makefile
new file mode 100644 (file)
index 0000000..106b618
--- /dev/null
@@ -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
+
diff --git a/Rewrite/Rewriter.cpp b/Rewrite/Rewriter.cpp
new file mode 100644 (file)
index 0000000..c4856ad
--- /dev/null
@@ -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:
+}
index 52139a3bdafc86dc1900fcbc10091a9fc2d0498b..578a156700ed1489889d20145e390f4d1a7f49b6 100644 (file)
                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 */
                                DEF2E9320C5FB9FB000C4259 /* ASTStreamers.h in CopyFiles */,
                                DEF2E95F0C5FBD74000C4259 /* InternalsManual.html in CopyFiles */,
                                DEC63B1C0C7B940600DBF169 /* CFG.h in CopyFiles */,
+                               DEF7D9F70C9C8B1A0001F598 /* Rewriter.h in CopyFiles */,
                        );
                        runOnlyForDeploymentPostprocessing = 1;
                };
                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 */
                                DE67E7070C020EAB00F66BC5 /* Sema */,
                                DE927FCC0C0557CD00231DA4 /* CodeGen */,
                                356EF9B30C8F7DCA006650F5 /* Analysis */,
+                               DEF7D9F50C9C8B0C0001F598 /* Rewrite */,
                        );
                        name = Source;
                        sourceTree = "<group>";
                                DE67E7260C02108300F66BC5 /* Sema */,
                                DE928B140C05659A00231DA4 /* CodeGen */,
                                356EF9AF0C8F7DA4006650F5 /* Analysis */,
+                               DEF7D9F40C9C8B020001F598 /* Rewrite */,
                        );
                        path = include;
                        sourceTree = "<group>";
                        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 */
                                356EF9B50C8F7DDF006650F5 /* LiveVariables.cpp in Sources */,
                                355CF6840C90A8D400A08AA3 /* DeadStores.cpp in Sources */,
                                35AE0F690C9B4CC200CC1279 /* UnintializedValues.cpp in Sources */,
+                               DEF7D9F90C9C8B1D0001F598 /* Rewriter.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
diff --git a/include/clang/Rewrite/Rewriter.h b/include/clang/Rewrite/Rewriter.h
new file mode 100644 (file)
index 0000000..09a9980
--- /dev/null
@@ -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