2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2009-07-07 12:06:34 +02:00
|
|
|
|
|
|
|
|
#include "ASTParent.h"
|
2013-03-27 18:54:03 +01:00
|
|
|
|
|
|
|
|
#include <cplusplus/AST.h>
|
2009-07-07 12:06:34 +02:00
|
|
|
|
|
|
|
|
using namespace CPlusPlus;
|
|
|
|
|
|
2009-11-17 13:28:20 +01:00
|
|
|
ASTParent::ASTParent(TranslationUnit *translationUnit, AST *rootNode)
|
|
|
|
|
: ASTVisitor(translationUnit)
|
2009-07-07 12:06:34 +02:00
|
|
|
{
|
|
|
|
|
accept(rootNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ASTParent::~ASTParent()
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
AST *ASTParent::operator()(AST *ast) const
|
|
|
|
|
{ return parent(ast); }
|
|
|
|
|
|
|
|
|
|
AST *ASTParent::parent(AST *ast) const
|
|
|
|
|
{ return _parentMap.value(ast); }
|
|
|
|
|
|
|
|
|
|
bool ASTParent::preVisit(AST *ast)
|
|
|
|
|
{
|
|
|
|
|
if (! _parentStack.isEmpty())
|
|
|
|
|
_parentMap.insert(ast, _parentStack.top());
|
|
|
|
|
|
|
|
|
|
_parentStack.push(ast);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<AST *> ASTParent::path(AST *ast) const
|
|
|
|
|
{
|
|
|
|
|
QList<AST *> path;
|
|
|
|
|
path_helper(ast, &path);
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ASTParent::path_helper(AST *ast, QList<AST *> *path) const
|
|
|
|
|
{
|
|
|
|
|
if (! ast)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
path_helper(parent(ast), path);
|
|
|
|
|
path->append(ast);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ASTParent::postVisit(AST *)
|
|
|
|
|
{ _parentStack.pop(); }
|