Remove the type field from semantics nodes that don't produce values of that type. (#3049)

For `Assign` and `ReturnExpression`, this field wasn't used for
anything. For `StructTypeField`, we stored the type of the field here,
and now store it as an argument of the node instead.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
Richard Smith
2023-08-02 17:30:27 +00:00
committed by GitHub
co-authored by Jon Ross-Perkins
parent ab709b4117
commit 0c33dead70
71 changed files with 170 additions and 162 deletions
+12 -8
View File
@@ -286,7 +286,8 @@ class SemanticsNode {
using FactoryBase<Kind, ArgTypes...>::Get;
};
// Provides Get along with a Make that assumes a non-changing type.
// Provides Get along with a Make that assumes the node doesn't produce a
// typed value.
template <KindTemplateEnum Kind, typename... ArgTypes>
class FactoryNoType : public FactoryBase<Kind, ArgTypes...> {
public:
@@ -306,9 +307,9 @@ class SemanticsNode {
}
};
using Assign = SemanticsNode::Factory<SemanticsNodeKind::Assign,
SemanticsNodeId /*lhs_id*/,
SemanticsNodeId /*rhs_id*/>;
using Assign = SemanticsNode::FactoryNoType<SemanticsNodeKind::Assign,
SemanticsNodeId /*lhs_id*/,
SemanticsNodeId /*rhs_id*/>;
using BinaryOperatorAdd =
SemanticsNode::Factory<SemanticsNodeKind::BinaryOperatorAdd,
@@ -387,8 +388,8 @@ class SemanticsNode {
using Return = FactoryNoType<SemanticsNodeKind::Return>;
using ReturnExpression =
Factory<SemanticsNodeKind::ReturnExpression, SemanticsNodeId /*expr_id*/>;
using ReturnExpression = FactoryNoType<SemanticsNodeKind::ReturnExpression,
SemanticsNodeId /*expr_id*/>;
using StringLiteral = Factory<SemanticsNodeKind::StringLiteral,
SemanticsStringId /*string_id*/>;
@@ -400,8 +401,9 @@ class SemanticsNode {
using StructType =
Factory<SemanticsNodeKind::StructType, SemanticsNodeBlockId /*refs_id*/>;
using StructTypeField = Factory<SemanticsNodeKind::StructTypeField,
SemanticsStringId /*name_id*/>;
using StructTypeField =
FactoryNoType<SemanticsNodeKind::StructTypeField,
SemanticsStringId /*name_id*/, SemanticsTypeId /*type_id*/>;
using StructValue =
Factory<SemanticsNodeKind::StructValue, SemanticsNodeBlockId /*refs_id*/>;
@@ -431,6 +433,8 @@ class SemanticsNode {
auto parse_node() const -> ParseTree::Node { return parse_node_; }
auto kind() const -> SemanticsNodeKind { return kind_; }
// Gets the type of the value produced by evaluating this node.
auto type_id() const -> SemanticsTypeId { return type_id_; }
auto Print(llvm::raw_ostream& out) const -> void;