2008-12-02 12:01:29 +01:00
|
|
|
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
|
|
|
|
|
//
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
|
//
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
//
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
#include "ASTVisitor.h"
|
|
|
|
|
#include "AST.h"
|
|
|
|
|
#include "TranslationUnit.h"
|
|
|
|
|
#include "Control.h"
|
|
|
|
|
|
2009-10-20 11:21:25 +02:00
|
|
|
using namespace CPlusPlus;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-11-17 13:28:20 +01:00
|
|
|
ASTVisitor::ASTVisitor(TranslationUnit *translationUnit)
|
|
|
|
|
: _translationUnit(translationUnit)
|
2008-12-02 12:01:29 +01:00
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
ASTVisitor::~ASTVisitor()
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
void ASTVisitor::accept(AST *ast)
|
|
|
|
|
{ AST::accept(ast, this); }
|
|
|
|
|
|
|
|
|
|
Control *ASTVisitor::control() const
|
2009-11-17 13:28:20 +01:00
|
|
|
{
|
|
|
|
|
if (_translationUnit)
|
|
|
|
|
return _translationUnit->control();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
TranslationUnit *ASTVisitor::translationUnit() const
|
2009-11-17 13:28:20 +01:00
|
|
|
{ return _translationUnit; }
|
|
|
|
|
|
|
|
|
|
void ASTVisitor::setTranslationUnit(TranslationUnit *translationUnit)
|
|
|
|
|
{ _translationUnit = translationUnit; }
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-05-11 17:00:29 +02:00
|
|
|
unsigned ASTVisitor::tokenCount() const
|
|
|
|
|
{ return translationUnit()->tokenCount(); }
|
|
|
|
|
|
2009-03-06 10:20:15 +01:00
|
|
|
const Token &ASTVisitor::tokenAt(unsigned index) const
|
|
|
|
|
{ return translationUnit()->tokenAt(index); }
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
int ASTVisitor::tokenKind(unsigned index) const
|
|
|
|
|
{ return translationUnit()->tokenKind(index); }
|
|
|
|
|
|
|
|
|
|
const char *ASTVisitor::spell(unsigned index) const
|
2009-02-19 13:01:01 +01:00
|
|
|
{ return translationUnit()->spell(index); }
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-12-01 11:33:13 +01:00
|
|
|
const Identifier *ASTVisitor::identifier(unsigned index) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{ return translationUnit()->identifier(index); }
|
|
|
|
|
|
2009-12-01 11:33:13 +01:00
|
|
|
const Literal *ASTVisitor::literal(unsigned index) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{ return translationUnit()->literal(index); }
|
|
|
|
|
|
2009-12-01 11:33:13 +01:00
|
|
|
const NumericLiteral *ASTVisitor::numericLiteral(unsigned index) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{ return translationUnit()->numericLiteral(index); }
|
|
|
|
|
|
2009-12-01 11:33:13 +01:00
|
|
|
const StringLiteral *ASTVisitor::stringLiteral(unsigned index) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{ return translationUnit()->stringLiteral(index); }
|
|
|
|
|
|
2009-03-06 10:20:15 +01:00
|
|
|
void ASTVisitor::getPosition(unsigned offset,
|
|
|
|
|
unsigned *line,
|
|
|
|
|
unsigned *column,
|
2009-12-01 11:33:13 +01:00
|
|
|
const StringLiteral **fileName) const
|
2009-03-06 10:20:15 +01:00
|
|
|
{ translationUnit()->getPosition(offset, line, column, fileName); }
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void ASTVisitor::getTokenPosition(unsigned index,
|
|
|
|
|
unsigned *line,
|
|
|
|
|
unsigned *column,
|
2009-12-01 11:33:13 +01:00
|
|
|
const StringLiteral **fileName) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{ translationUnit()->getTokenPosition(index, line, column, fileName); }
|
|
|
|
|
|
2009-03-06 10:20:15 +01:00
|
|
|
void ASTVisitor::getTokenStartPosition(unsigned index, unsigned *line, unsigned *column) const
|
2014-05-06 14:48:24 -04:00
|
|
|
{ getPosition(tokenAt(index).utf16charsBegin(), line, column); }
|
2009-03-06 10:20:15 +01:00
|
|
|
|
|
|
|
|
void ASTVisitor::getTokenEndPosition(unsigned index, unsigned *line, unsigned *column) const
|
2014-05-06 14:48:24 -04:00
|
|
|
{ getPosition(tokenAt(index).utf16charsEnd(), line, column); }
|