Files
swift-mirror/include/swift/IDE/SourceEntityWalker.h
Jordan Rose 417b5d3982 Merge TranslationUnit into Module, and eliminate the term "translation unit".
This completes the FileUnit refactoring. A module consists of multiple
FileUnits, which provide decls from various file-like sources. I say
"file-like" because the Builtin module is implemented with a single
BuiltinUnit, and imported Clang modules are just a single FileUnit source
within a module.

Most modules, therefore, contain a single file unit; only the main module
will contain multiple source files (and eventually partial AST files).

The term "translation unit" has been scrubbed from the project. To refer
to the context of declarations outside of any other declarations, use
"top-level" or "module scope". To refer to a .swift file or its DeclContext,
use "source file". To refer to a single unit of compilation, use "module",
since the model is that an entire module will be compiled with a single
driver call. (It will still be possible to compile a single source file
through the direct-to-frontend interface, but only in the context of the
whole module.)

Swift SVN r10837
2013-12-05 01:51:15 +00:00

96 lines
3.6 KiB
C++

//===- SourceEntityWalker.h - Routines for semantic source info -----------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_IDE_SEMANTIC_SOURCE_ENTITY_WALKER_H
#define SWIFT_IDE_SEMANTIC_SOURCE_ENTITY_WALKER_H
#include "swift/Basic/LLVM.h"
#include "swift/Basic/SourceLoc.h"
namespace swift {
class DeclContext;
class SourceFile;
class Module;
class Decl;
class ValueDecl;
class TypeDecl;
class Stmt;
class Expr;
namespace ide {
/// An abstract class used to traverse the AST and provide source information.
/// Visitation happens in source-order and compiler-generated semantic info,
/// like implicit declarations, is ignored.
class SourceEntityWalker {
public:
/// Walks the provided source file.
/// \returns true if traversal was aborted, false otherwise.
bool walk(SourceFile &SrcFile);
/// Walks the provided module.
/// \returns true if traversal was aborted, false otherwise.
bool walk(Module &Mod);
/// Walks the provided Decl.
/// \returns true if traversal was aborted, false otherwise.
bool walk(Decl *D);
/// Walks the provided DeclContext.
/// \returns true if traversal was aborted, false otherwise.
bool walk(DeclContext *DC);
/// This method is called when first visiting a decl, before walking into its
/// children. If it returns false, the subtree is skipped.
virtual bool walkToDeclPre(Decl *D, CharSourceRange Range) { return true; }
/// This method is called after visiting the children of a decl. If it returns
/// false, the remaining traversal is terminated and returns failure.
virtual bool walkToDeclPost(Decl *D) { return true; }
/// This method is called when first visiting a statement, before walking into
/// its children. If it returns false, the subtree is skipped.
virtual bool walkToStmtPre(Stmt *S) { return true; }
/// This method is called after visiting the children of a statement. If it
/// returns false, the remaining traversal is terminated and returns failure.
virtual bool walkToStmtPost(Stmt *S) { return true; }
/// This method is called when first visiting an expression, before walking
/// into its children. If it returns false, the subtree is skipped.
virtual bool walkToExprPre(Expr *E) { return true; }
/// This method is called after visiting the children of an expression. If it
/// returns false, the remaining traversal is terminated and returns failure.
virtual bool walkToExprPost(Expr *E) { return true; }
/// This method is called when a ValueDecl is referenced in source. If it
/// returns false, the remaining traversal is terminated and returns failure.
///
/// \param D the referenced decl.
/// \param Range the source range of the source reference.
/// \param CtorTyRef this is set when the entity is a reference to a
/// \c ConstructorDecl, to point to the type declaration that the source
/// refers to.
virtual bool visitDeclReference(ValueDecl *D, CharSourceRange Range,
TypeDecl *CtorTyRef) { return true; }
protected:
SourceEntityWalker() = default;
SourceEntityWalker(const SourceEntityWalker &) = default;
virtual ~SourceEntityWalker() {}
virtual void anchor();
};
} // namespace ide
} // namespace swift
#endif