Files
swift-mirror/include/swift/AST/ASTNode.h
Anna Zaks 54524e622a Replace ExprStmtOrDecl with ASTNode and make it a struct.
Previously, the Parser and BranchStmt typedef-ed ExprStmtOrDecl as a pointer union. Using typedef made the objects compatible, but did not allow us to extend the type with helper methods, such as getSourceRange(), which is something you can get on all of the AST objects. This patch introduces ASTNode that subclasses from PointerUnion and is used by both parser and BranchStmt.

Swift SVN r9971
2013-11-05 21:46:59 +00:00

44 lines
1.3 KiB
C++

//===--- ASTNode.h - Swift Language ASTs ------------------------*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// This file defines the ASTNode, which is a union of Stmt, Expr, and Decl.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_AST_AST_NODE_H
#define SWIFT_AST_AST_NODE_H
#include "llvm/ADT/PointerUnion.h"
namespace swift {
class Expr;
class Stmt;
class Decl;
class SourceLoc;
class SourceRange;
struct ASTNode : public llvm::PointerUnion3<Expr*, Stmt*, Decl*> {
// Inherit the constructors from PointerUnion.
using PointerUnion3::PointerUnion3;
SourceRange getSourceRange() const;
/// \brief Return the location of the start of the statement.
SourceLoc getStartLoc() const;
/// \brief Return the location of the end of the statement.
SourceLoc getEndLoc() const;
};
} // namespace swift
#endif // LLVM_SWIFT_AST_AST_NODE_H