Commit Graph

16 Commits

Author SHA1 Message Date
Eli Friedman e6eb2edb50 Fix for PR2386: distinguish between insertion and replacements in the
delta tree.

The issue is roughly a conflict in ReplaceText between two kinds of 
uses. One, it should be possible to replace a replacement: for example, the
ObjC rewriter calls ReplaceStmt for an expression, then replaces the resulting
expression with another expression.  Two, it should be possible to 
replace text that already has text inserted before it: for example, the 
HTML rewriter inserts a bunch of tags at the beginning of the line, then 
tries to escape the first character on the line.  This patch 
distinguishes the two cases by storing the deltas separately; 
essentially, replacements and insertions no longer interfere with 
each other.

Another possibility would be to add some sort of flag to ReplaceText, but
this seems a bit more intuitive and flexible.

There are a few downsides to the current solution: one is that there isn't
any way to remove/replace an insertion without touching additional
surrounding text; if such an operation turns out to be useful, an
additional method or flag can be added.  Another is that an insertion 
and replacing a string of length zero are distinct operations; I'm not 
sure how to resolve this, or whether it will be confusing in practice.

This is relatively sensitive code, so please test and tell me if 
anything breaks.

llvm-svn: 72000
2009-05-18 13:56:52 +00:00
Chris Lattner 184e65d363 Change Lexer::MeasureTokenLength to take a LangOptions reference.
This allows it to accurately measure tokens, so that we get:

t.cpp:8:13: error: unknown type name 'X'
static foo::X  P;
       ~~~~~^

instead of the woefully inferior:

t.cpp:8:13: error: unknown type name 'X'
static foo::X  P;
       ~~~~ ^

Most of this is just plumbing to push the reference around.

llvm-svn: 69099
2009-04-14 23:22:57 +00:00
Chris Lattner 4fa23625ab Check in the long promised SourceLocation rewrite. This lays the
ground work for implementing #line, and fixes the "out of macro ID's" 
problem.

There is nothing particularly tricky about the code, other than the
very performance sensitive SourceManager::getFileID() method.

llvm-svn: 62978
2009-01-26 00:43:02 +00:00
Chris Lattner d32480d3db this massive patch introduces a simple new abstraction: it makes
"FileID" a concept that is now enforced by the compiler's type checker
instead of yet-another-random-unsigned floating around.

This is an important distinction from the "FileID" currently tracked by
SourceLocation.  *That* FileID may refer to the start of a file or to a
chunk within it.  The new FileID *only* refers to the file (and its 
#include stack and eventually #line data), it cannot refer to a chunk.

FileID is a completely opaque datatype to all clients, only SourceManager
is allowed to poke and prod it.

llvm-svn: 62407
2009-01-17 06:22:33 +00:00
Ted Kremenek 5ee6292e32 Add #include (introduced by dependence on DeclGroup)
llvm-svn: 57274
2008-10-07 23:08:39 +00:00
Chris Lattner 7c306a70b9 add a new Rewriter::getRewritenText method that returns the text for a range
that includes any edits in the range.

llvm-svn: 57037
2008-10-03 23:31:16 +00:00
Ted Kremenek 2d470fc0ba Patch by Csaba Hruska!
"Here is a patch what replaces std::ostream with llvm::raw_ostream. This patch
covers the AST library, but ignores Analysis lib."

llvm-svn: 56185
2008-09-13 05:16:45 +00:00
Chris Lattner c5c27f7bfe add an assertion
llvm-svn: 51645
2008-05-28 16:35:02 +00:00
Chris Lattner 17c2476d0b fix an inconsistency computing offsets that caused a crash on rewrite-nest.m
llvm-svn: 51514
2008-05-23 23:06:56 +00:00
Chris Lattner 04df1bb8b5 remove ifdefs
llvm-svn: 49651
2008-04-14 17:12:49 +00:00
Chris Lattner 3374b039d9 Change the RewriteRope::Chunks data structure from an std::list into
a nice shiny B+ Tree variant.  This fixes the last of the known algorithmic
issues with the rewriter, allowing a significant speedup.  For example,
-emit-html on Ted's 500K .i file speeds up from 26.8s -> 0.64s in a 
debug build (41x!) and 5.475s -> 0.132s (41x!) in an optimized build.

This code is functional but needs to be cleaned up, ifdefs removed, better
commented, and moved to a .cpp file.  I plan to do this tomorrow.

llvm-svn: 49635
2008-04-14 07:17:29 +00:00
Chris Lattner 0c8d17fc43 remove ifdefs
llvm-svn: 49587
2008-04-12 20:34:05 +00:00
Chris Lattner d154731131 Do an initial hack at replacing one of the incredibly inefficient
(but simple!) datastructures in the rewriter with a more complex but
more efficient one.

This replaces the Deltas vector with a specialized BTree that makes
delta lookups much more efficient.  This speeds up -emit-html on a 500K
.i file from 157.154 to 27.127 seconds on my machine (5.8x).

While this code is functional, it isn't very pretty, I have much 
refactoring planned for it, and will remove the USE_VECTOR ifdef.
Stay tuned.

llvm-svn: 49586
2008-04-12 20:28:24 +00:00
Ted Kremenek 45467ef372 Added variant of "InsertText" in the Rewriter to support inserting text both
*before* and after a specific location.

llvm-svn: 48504
2008-03-18 21:17:59 +00:00
Ted Kremenek af5b820af3 Bug fix in RewriteBuffer::getMappedOffset: potentially multiple deltas
need to be skipped over when AfterInserts == true, as multiple deltas
may share the same FileLoc.

llvm-svn: 48503
2008-03-18 21:00:57 +00:00
Chris Lattner 7a51313d8a Make a major restructuring of the clang tree: introduce a top-level
lib dir and move all the libraries into it.  This follows the main
llvm tree, and allows the libraries to be built in parallel.  The
top level now enforces that all the libs are built before Driver,
but we don't care what order the libs are built in.  This speeds
up parallel builds, particularly incremental ones.

llvm-svn: 48402
2008-03-15 23:59:48 +00:00