mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 13:11:05 +01:00
Generic classes (#1124)
* 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>
This commit is contained in:
committed by
GitHub
co-authored by
Jon Meow
Geoff Romer
parent
37a0e35b31
commit
210856dd57
@@ -38,15 +38,22 @@ static constexpr bool ImplementsValueNode = false;
|
||||
with a value, such as declarations and bindings. The interface consists of
|
||||
the following methods:
|
||||
|
||||
// Returns the constant associated with the node.
|
||||
// This is called by the interpreter, not the type checker.
|
||||
auto constant_value() const -> std::optional<Nonnull<const Value*>>;
|
||||
|
||||
// Returns the symbolic compile-time identity of the node.
|
||||
// This is called by the type checker, not the interpreter.
|
||||
auto symbolic_identity() const -> std::optional<Nonnull<const Value*>>;
|
||||
|
||||
// Returns the static type of an IdentifierExpression that names *this.
|
||||
auto static_type() const -> const Value&;
|
||||
|
||||
// Returns the value category of an IdentifierExpression that names *this.
|
||||
auto value_category() const -> ValueCategory;
|
||||
|
||||
// Print the node for diagnostic or tracing purposes.
|
||||
void Print(llvm::raw_ostream& out) const;
|
||||
|
||||
// Print the node's identity (e.g. its name).
|
||||
void PrintID(llvm::raw_ostream& out) const;
|
||||
|
||||
*/
|
||||
// TODO: consider turning the above documentation into real code, as sketched
|
||||
@@ -70,9 +77,13 @@ class ValueNodeView {
|
||||
[](const AstNode& base) -> std::optional<Nonnull<const Value*>> {
|
||||
return llvm::cast<NodeType>(base).constant_value();
|
||||
}),
|
||||
symbolic_identity_(
|
||||
[](const AstNode& base) -> std::optional<Nonnull<const Value*>> {
|
||||
return llvm::cast<NodeType>(base).symbolic_identity();
|
||||
}),
|
||||
print_([](const AstNode& base, llvm::raw_ostream& out) -> void {
|
||||
// TODO: change this to print a summary of the node
|
||||
return llvm::cast<NodeType>(base).Print(out);
|
||||
return llvm::cast<NodeType>(base).PrintID(out);
|
||||
}),
|
||||
static_type_([](const AstNode& base) -> const Value& {
|
||||
return llvm::cast<NodeType>(base).static_type();
|
||||
@@ -94,6 +105,11 @@ class ValueNodeView {
|
||||
return constant_value_(*base_);
|
||||
}
|
||||
|
||||
// Returns node->symbolic_identity()
|
||||
auto symbolic_identity() const -> std::optional<Nonnull<const Value*>> {
|
||||
return symbolic_identity_(*base_);
|
||||
}
|
||||
|
||||
void Print(llvm::raw_ostream& out) const { print_(*base_, out); }
|
||||
|
||||
// Returns node->static_type()
|
||||
@@ -123,6 +139,8 @@ class ValueNodeView {
|
||||
Nonnull<const AstNode*> base_;
|
||||
std::function<std::optional<Nonnull<const Value*>>(const AstNode&)>
|
||||
constant_value_;
|
||||
std::function<std::optional<Nonnull<const Value*>>(const AstNode&)>
|
||||
symbolic_identity_;
|
||||
std::function<void(const AstNode&, llvm::raw_ostream&)> print_;
|
||||
std::function<const Value&(const AstNode&)> static_type_;
|
||||
std::function<ValueCategory(const AstNode&)> value_category_;
|
||||
|
||||
Reference in New Issue
Block a user