mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-25 18:20:09 +01:00
* start of generic classes * fix regressions * class functions in interfaces * access to class function on interface from class parameter * more stuff working for generic classes * fixing bugs * update TypeEqual for generic classes * fixing bugs and finding new ones * disable unqualified access to members from other members for now * minor edits * bug fixes * introduce compile_time_value to use in type checker instead of constant_value * cleanup * put a CHECK back in * failure test cases for the new FATAL_COMPILATION_ERROR * change a runtime FATAL into a FATAL_COMPILATION_ERROR * Update executable_semantics/ast/declaration.h Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/action_stack.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/interpreter.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/value.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/value.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/interpreter.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/value.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/value.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/resolve_names.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/type_checker.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/type_checker.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/type_checker.cpp Co-authored-by: Jon Meow <jperkins@google.com> * responses to reviews * Update executable_semantics/interpreter/type_checker.cpp Co-authored-by: Jon Meow <jperkins@google.com> * rename compile_time_value to symbolic_identity * Update executable_semantics/interpreter/type_checker.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/type_checker.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/type_checker.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/type_checker.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/type_checker.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/type_checker.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/value.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/value.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/value.cpp Co-authored-by: Jon Meow <jperkins@google.com> * more edits from review * Apply suggestions from code review Co-authored-by: Geoff Romer <gromer@google.com> * review responses * Update executable_semantics/interpreter/interpreter.cpp Co-authored-by: Geoff Romer <gromer@google.com> * const impl_scope for TypeCheckChoiceDeclaration * add some const Co-authored-by: Jon Meow <jperkins@google.com> Co-authored-by: Geoff Romer <gromer@google.com>
80 lines
2.9 KiB
C++
80 lines
2.9 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#ifndef EXECUTABLE_SEMANTICS_AST_AST_NODE_H_
|
|
#define EXECUTABLE_SEMANTICS_AST_AST_NODE_H_
|
|
|
|
#include "executable_semantics/ast/ast_rtti.h"
|
|
#include "executable_semantics/ast/source_location.h"
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
namespace Carbon {
|
|
|
|
// Base class for all nodes in the AST.
|
|
//
|
|
// Every class derived from this class must be listed in ast_rtti.txt. See
|
|
// the documentation of gen_rtti.py for details about the format. As a result,
|
|
// every abstract class `Foo` will have a `FooKind` enumerated type, whose
|
|
// enumerators correspond to the subclasses of `Foo`.
|
|
//
|
|
// AstNode and its derived classes support LLVM-style RTTI, including
|
|
// llvm::isa, llvm::cast, and llvm::dyn_cast. To support this, every
|
|
// class derived from Declaration must provide a `classof` operation, with
|
|
// the following form, where `Foo` is the name of the derived class:
|
|
//
|
|
// static auto classof(const AstNode* node) -> bool {
|
|
// return InheritsFromFoo(node->kind());
|
|
// }
|
|
//
|
|
// Furthermore, if the class is abstract, it must provide a `kind()` operation,
|
|
// with the following form:
|
|
//
|
|
// auto kind() const -> FooKind { return static_cast<FooKind>(root_kind()); }
|
|
//
|
|
// The definitions of `InheritsFromFoo` and `FooKind` are generated from
|
|
// ast_rtti.txt, and are implicitly provided by this header.
|
|
//
|
|
// TODO: To support generic traversal, add children() method, and ensure that
|
|
// all AstNodes are reachable from a root AstNode.
|
|
class AstNode {
|
|
public:
|
|
AstNode(AstNode&&) = delete;
|
|
auto operator=(AstNode&&) -> AstNode& = delete;
|
|
virtual ~AstNode() = 0;
|
|
|
|
// Print the AST rooted at the node.
|
|
virtual void Print(llvm::raw_ostream& out) const = 0;
|
|
// Print identifying information about the node, such as it's name.
|
|
virtual void PrintID(llvm::raw_ostream& out) const = 0;
|
|
LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
|
|
|
|
// Returns an enumerator specifying the concrete type of this node.
|
|
//
|
|
// Abstract subclasses of AstNode will provide their own `kind()` method
|
|
// which hides this one, and provides a narrower return type.
|
|
auto kind() const -> AstNodeKind { return kind_; }
|
|
|
|
// The location of the code described by this node.
|
|
auto source_loc() const -> SourceLocation { return source_loc_; }
|
|
|
|
protected:
|
|
// Constructs an AstNode representing code at the given location. `kind`
|
|
// must be the enumerator that exactly matches the concrete type being
|
|
// constructed.
|
|
explicit AstNode(AstNodeKind kind, SourceLocation source_loc)
|
|
: kind_(kind), source_loc_(source_loc) {}
|
|
|
|
// Equivalent to kind(), but will not be hidden by `kind()` methods of
|
|
// derived classes.
|
|
auto root_kind() const -> AstNodeKind { return kind_; }
|
|
|
|
private:
|
|
AstNodeKind kind_;
|
|
SourceLocation source_loc_;
|
|
};
|
|
|
|
} // namespace Carbon
|
|
|
|
#endif // EXECUTABLE_SEMANTICS_AST_AST_NODE_H_
|