From 15641165f95f9f83cb2702fe52ec4dcb419a2f54 Mon Sep 17 00:00:00 2001
From: Roberto Raggi <roberto.raggi@nokia.com>
Date: Mon, 10 May 2010 13:45:27 +0200
Subject: [PATCH] Removed deprecated (and unsafe) methods.

---
 src/shared/cplusplus/CheckDeclaration.cpp |  4 +-
 src/shared/cplusplus/Symbol.cpp           | 69 +++++------------------
 src/shared/cplusplus/Symbol.h             | 20 ++-----
 3 files changed, 21 insertions(+), 72 deletions(-)

diff --git a/src/shared/cplusplus/CheckDeclaration.cpp b/src/shared/cplusplus/CheckDeclaration.cpp
index d0472334ddd..ec8ddfcc4ca 100644
--- a/src/shared/cplusplus/CheckDeclaration.cpp
+++ b/src/shared/cplusplus/CheckDeclaration.cpp
@@ -206,7 +206,7 @@ bool CheckDeclaration::visit(SimpleDeclarationAST *ast)
 
         Function *fun = 0;
         if (declTy && 0 != (fun = declTy->asFunctionType())) {
-            fun->setSourceLocation(location);
+            fun->setSourceLocation(location, translationUnit());
             fun->setScope(_scope);
             fun->setName(name);
             fun->setMethodKey(semantic()->currentMethodKey());
@@ -341,7 +341,7 @@ bool CheckDeclaration::visit(FunctionDefinitionAST *ast)
     fun->setStartOffset(tokenAt(ast->firstToken()).offset);
     fun->setEndOffset(tokenAt(ast->lastToken()).offset);
     if (ast->declarator)
-        fun->setSourceLocation(ast->declarator->firstToken());
+        fun->setSourceLocation(ast->declarator->firstToken(), translationUnit());
     fun->setName(name);
     fun->setTemplateParameters(_templateParameters);
     fun->setVisibility(semantic()->currentVisibility());
diff --git a/src/shared/cplusplus/Symbol.cpp b/src/shared/cplusplus/Symbol.cpp
index 8572f191dcb..fa2d00f3162 100644
--- a/src/shared/cplusplus/Symbol.cpp
+++ b/src/shared/cplusplus/Symbol.cpp
@@ -161,10 +161,7 @@ private:
 };
 
 Symbol::Symbol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
-    : _control(0),
-      _sourceLocation(sourceLocation),
-      _sourceOffset(0),
-      _startOffset(0),
+    : _startOffset(0),
       _endOffset(0),
       _name(0),
       _hashCode(0),
@@ -175,23 +172,13 @@ Symbol::Symbol(TranslationUnit *translationUnit, unsigned sourceLocation, const
       _next(0),
       _isGenerated(false)
 {
-    if (translationUnit) {
-        _control = translationUnit->control();
-        setSourceLocation(sourceLocation);
-    }
-
+    setSourceLocation(sourceLocation, translationUnit);
     setName(name);
 }
 
 Symbol::~Symbol()
 { }
 
-Control *Symbol::control() const
-{ return _control; }
-
-TranslationUnit *Symbol::translationUnit() const
-{ return _control->translationUnit(); }
-
 void Symbol::visitSymbol(SymbolVisitor *visitor)
 {
     if (visitor->preVisit(this))
@@ -210,9 +197,6 @@ void Symbol::visitSymbol(Symbol *symbol, SymbolVisitor *visitor)
 unsigned Symbol::sourceLocation() const
 { return _sourceLocation; }
 
-unsigned Symbol::sourceOffset() const
-{ return _sourceOffset; }
-
 bool Symbol::isGenerated() const
 { return _isGenerated; }
 
@@ -222,62 +206,38 @@ bool Symbol::isDeprecated() const
 void Symbol::setDeprecated(bool isDeprecated)
 { _isDeprecated = isDeprecated; }
 
-void Symbol::setSourceLocation(unsigned sourceLocation)
+void Symbol::setSourceLocation(unsigned sourceLocation, TranslationUnit *translationUnit)
 {
     _sourceLocation = sourceLocation;
+    unsigned offset = 0;
 
     if (! _sourceLocation) {
         _isGenerated = false;
-        _sourceOffset = 0;
-    } else {
-        TranslationUnit *unit = translationUnit();
-
-        const Token &tk = unit->tokenAt(sourceLocation);
 
+    } else {
+        const Token &tk = translationUnit->tokenAt(sourceLocation);
         _isGenerated = tk.f.generated;
-        _sourceOffset = tk.offset;
+        offset = tk.offset;
     }
+
+    translationUnit->getPosition(offset, &_line, &_column, &_fileId);
 }
 
 unsigned Symbol::line() const
 {
-    assert(_sourceOffset != 0);
-
-    unsigned line = 0, column = 0;
-    const StringLiteral *fileId = 0;
-    translationUnit()->getPosition(_sourceOffset, &line, &column, &fileId);
-    return line;
+    return _line;
 }
 
 unsigned Symbol::column() const
 {
-    assert(_sourceOffset != 0);
-
-    unsigned line = 0, column = 0;
-    const StringLiteral *fileId = 0;
-    translationUnit()->getPosition(_sourceOffset, &line, &column, &fileId);
-    return column;
+    return _column;
 }
 
 const StringLiteral *Symbol::fileId() const
 {
-    assert(_sourceOffset != 0);
-
-    unsigned line = 0, column = 0;
-    const StringLiteral *fileId = 0;
-    translationUnit()->getPosition(_sourceOffset, &line, &column, &fileId);
-    return fileId;
+    return _fileId;
 }
 
-void Symbol::getPosition(unsigned *line, unsigned *column, const StringLiteral **fileId) const
-{ translationUnit()->getPosition(_sourceOffset, line, column, fileId); }
-
-void Symbol::getStartPosition(unsigned *line, unsigned *column, const StringLiteral **fileId) const
-{ translationUnit()->getPosition(_startOffset, line, column, fileId); }
-
-void Symbol::getEndPosition(unsigned *line, unsigned *column, const StringLiteral **fileId) const
-{ translationUnit()->getPosition(_endOffset, line, column, fileId); }
-
 const char *Symbol::fileName() const
 { return fileId()->chars(); }
 
@@ -511,9 +471,7 @@ bool Symbol::isObjCPropertyDeclaration() const
 
 void Symbol::copy(Symbol *other)
 {
-    _control = other->_control;
     _sourceLocation = other->_sourceLocation;
-    _sourceOffset = other->_sourceOffset;
     _startOffset = other->_startOffset;
     _endOffset = other->_endOffset;
     _name = other->_name;
@@ -523,6 +481,9 @@ void Symbol::copy(Symbol *other)
     _scope = other->_scope;
     _index = other->_index;
     _next = other->_next;
+    _fileId = other->_fileId;
+    _line = other->_line;
+    _column = other->_column;
 
     _isGenerated = other->_isGenerated;
     _isDeprecated = other->_isDeprecated;
diff --git a/src/shared/cplusplus/Symbol.h b/src/shared/cplusplus/Symbol.h
index ab762f63811..e0fe2b01be9 100644
--- a/src/shared/cplusplus/Symbol.h
+++ b/src/shared/cplusplus/Symbol.h
@@ -90,9 +90,6 @@ public:
     /// Returns this Symbol's source location.
     unsigned sourceLocation() const;
 
-    /// Returns this Symbol's source offset.
-    unsigned sourceOffset() const;
-
     /// Returns this Symbol's line number.
     unsigned line() const;
 
@@ -114,10 +111,6 @@ public:
     unsigned endOffset() const;
     void setEndOffset(unsigned offset);
 
-    void getPosition(unsigned *line, unsigned *column = 0, const StringLiteral **fileId = 0) const;
-    void getStartPosition(unsigned *line, unsigned *column = 0, const StringLiteral **fileId = 0) const;
-    void getEndPosition(unsigned *line, unsigned *column = 0, const StringLiteral **fileId = 0) const;
-
     /// Returns this Symbol's name.
     const Name *name() const;
 
@@ -312,7 +305,7 @@ public:
     Scope *enclosingBlockScope() const;
 
     void setScope(Scope *scope); // ### make me private
-    void setSourceLocation(unsigned sourceLocation); // ### make me private
+    void setSourceLocation(unsigned sourceLocation, TranslationUnit *translationUnit); // ### make me private
 
     void visitSymbol(SymbolVisitor *visitor);
     static void visitSymbol(Symbol *symbol, SymbolVisitor *visitor);
@@ -322,16 +315,8 @@ public:
 protected:
     virtual void visitSymbol0(SymbolVisitor *visitor) = 0;
 
-    /// Returns this Symbol's Control object.
-    Control *control() const;
-
-    /// Returns this Symbol's TranslationUnit.
-    TranslationUnit *translationUnit() const;
-
 private:
-    Control *_control;
     unsigned _sourceLocation;
-    unsigned _sourceOffset;
     unsigned _startOffset;
     unsigned _endOffset;
     const Name *_name;
@@ -341,6 +326,9 @@ private:
     Scope *_scope;
     unsigned _index;
     Symbol *_next;
+    const StringLiteral *_fileId;
+    unsigned _line;
+    unsigned _column;
 
     bool _isGenerated: 1;
     bool _isDeprecated: 1;
-- 
GitLab