diff options
| author | Chris Lattner <sabre@nondot.org> | 2007-10-16 22:36:42 +0000 | 
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2007-10-16 22:36:42 +0000 | 
| commit | a7c19feca2823d2c8431c7c35d83298dad070285 (patch) | |
| tree | 9b86d55476cd24ad4b8c98b08650ff6f238065c5 /clang/Driver | |
| parent | ebac2cb23561a933f9572a06b0a901c9221f086e (diff) | |
| download | bcm5719-llvm-a7c19feca2823d2c8431c7c35d83298dad070285.tar.gz bcm5719-llvm-a7c19feca2823d2c8431c7c35d83298dad070285.zip  | |
Add a new Rewriter::getRangeSize method.
Rename SourceRange::Begin()/End() to getBegin()/getEnd() for
consistency with other code.
Start building the rewriter towards handling @encode.
llvm-svn: 43047
Diffstat (limited to 'clang/Driver')
| -rw-r--r-- | clang/Driver/RewriteTest.cpp | 29 | ||||
| -rw-r--r-- | clang/Driver/TextDiagnosticPrinter.cpp | 10 | 
2 files changed, 34 insertions, 5 deletions
diff --git a/clang/Driver/RewriteTest.cpp b/clang/Driver/RewriteTest.cpp index 5b27f55190f..731d6fe7774 100644 --- a/clang/Driver/RewriteTest.cpp +++ b/clang/Driver/RewriteTest.cpp @@ -36,6 +36,9 @@ namespace {      void HandleDeclInMainFile(Decl *D);      void RewriteInclude(SourceLocation Loc); +     +    void RewriteFunctionBody(Stmt *S); +    void RewriteAtEncode(ObjCEncodeExpr *Exp);      ~RewriteTest();    }; @@ -86,10 +89,36 @@ void RewriteTest::RewriteInclude(SourceLocation Loc) {  /// HandleDeclInMainFile - This is called for each top-level decl defined in the  /// main file of the input.  void RewriteTest::HandleDeclInMainFile(Decl *D) { +  if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) +    if (Stmt *Body = FD->getBody()) +      RewriteFunctionBody(Body);    // Nothing yet.  } +void RewriteTest::RewriteFunctionBody(Stmt *S) { +  // Handle specific things. +  if (ObjCEncodeExpr *AtEncode = dyn_cast<ObjCEncodeExpr>(S)) +    return RewriteAtEncode(AtEncode); +   +  // Otherwise, just rewrite all children. +  for (Stmt::child_iterator CI = S->child_begin(), E = S->child_end(); +       CI != E; ++CI) +    RewriteFunctionBody(*CI); +} + +void RewriteTest::RewriteAtEncode(ObjCEncodeExpr *Exp) { +#if 0 +  int Size = Rewrite.getRangeSize(Exp->getSourceRange()); +  if (Size == -1) { +    printf("BLAH!"); +  } +   +  Rewrite.RemoveText(Exp->getEncLoc(), Size); +#endif +} + +  RewriteTest::~RewriteTest() {    // Get the top-level buffer that this corresponds to.    std::pair<const char*, const char*> MainBuf = SM->getBufferData(MainFileID); diff --git a/clang/Driver/TextDiagnosticPrinter.cpp b/clang/Driver/TextDiagnosticPrinter.cpp index 3a90a4f5485..2a3bd0d9546 100644 --- a/clang/Driver/TextDiagnosticPrinter.cpp +++ b/clang/Driver/TextDiagnosticPrinter.cpp @@ -54,16 +54,16 @@ void TextDiagnosticPrinter::HighlightRange(const SourceRange &R,           "Expect a correspondence between source and carat line!");    if (!R.isValid()) return; -  unsigned StartLineNo = SourceMgr.getLogicalLineNumber(R.Begin()); +  unsigned StartLineNo = SourceMgr.getLogicalLineNumber(R.getBegin());    if (StartLineNo > LineNo) return;  // No intersection. -  unsigned EndLineNo = SourceMgr.getLogicalLineNumber(R.End()); +  unsigned EndLineNo = SourceMgr.getLogicalLineNumber(R.getEnd());    if (EndLineNo < LineNo) return;  // No intersection.    // Compute the column number of the start.    unsigned StartColNo = 0;    if (StartLineNo == LineNo) { -    StartColNo = SourceMgr.getLogicalColumnNumber(R.Begin()); +    StartColNo = SourceMgr.getLogicalColumnNumber(R.getBegin());      if (StartColNo) --StartColNo;  // Zero base the col #.    } @@ -75,12 +75,12 @@ void TextDiagnosticPrinter::HighlightRange(const SourceRange &R,    // Compute the column number of the end.    unsigned EndColNo = CaratLine.size();    if (EndLineNo == LineNo) { -    EndColNo = SourceMgr.getLogicalColumnNumber(R.End()); +    EndColNo = SourceMgr.getLogicalColumnNumber(R.getEnd());      if (EndColNo) {        --EndColNo;  // Zero base the col #.        // Add in the length of the token, so that we cover multi-char tokens. -      EndColNo += GetTokenLength(R.End()); +      EndColNo += GetTokenLength(R.getEnd());      } else {        EndColNo = CaratLine.size();      }  | 

