mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Add semantics for struct type and value literals. (#2709)
This handles the basics of type and value for structs. Structurally, these look like parameters and arguments (respectively) because expressions/generics may result in multiple IR nodes being generated.
Because `{}` needs to be cast to a type for storage, I'm also adding some validation that's not specific to `{}`, e.g. that `1` shouldn't be valid as a type for storage (previously, nothing errored for that).
This adds more stringification of types, particularly literals, because they come up in value errors now.
ImplicitAs is the result of me mulling whether I'm taking the right approach on type conversions. I think it needs to return a value so that if the implicit cast rewrites the value, the result is accessible to the caller. I may reorient the current TryTypeConversion logic to be more based on the ImplicitAs logic.
This commit is contained in:
@@ -45,10 +45,8 @@ class SemanticsNodeStack {
|
||||
PushEntry({.parse_node = parse_node, .node_id = node_id}, DebugLog::NodeId);
|
||||
}
|
||||
|
||||
// Pushes a PatternBinding parse tree node onto the stack with its name.
|
||||
// Pushes a parse tree node onto the stack with its name.
|
||||
auto Push(ParseTree::Node parse_node, SemanticsStringId name_id) -> void {
|
||||
CARBON_CHECK(parse_tree_->node_kind(parse_node) ==
|
||||
ParseNodeKind::PatternBinding);
|
||||
PushEntry({.parse_node = parse_node, .name_id = name_id}, DebugLog::NameId);
|
||||
}
|
||||
|
||||
@@ -85,16 +83,14 @@ class SemanticsNodeStack {
|
||||
auto PopForNodeId() -> SemanticsNodeId;
|
||||
|
||||
// Pops the top of the stack and returns the parse_node and name_id.
|
||||
// Verifies that the parse_node is a PatternBinding.
|
||||
auto PopForParseNodeAndNameId()
|
||||
auto PopForParseNodeAndNameId(ParseNodeKind pop_parse_kind)
|
||||
-> std::pair<ParseTree::Node, SemanticsStringId>;
|
||||
|
||||
// Peeks at the parse_node of the top of the stack.
|
||||
auto PeekParseNode() -> ParseTree::Node { return stack_.back().parse_node; }
|
||||
|
||||
// Peeks at the name_id of the top of the stack.
|
||||
// Verifies that the parse_node is a PatternBinding.
|
||||
auto PeekForNameId() -> SemanticsStringId;
|
||||
auto PeekForNameId(ParseNodeKind parse_kind) -> SemanticsStringId;
|
||||
|
||||
// Prints the stack for a stack dump.
|
||||
auto PrintForStackDump(llvm::raw_ostream& output) const -> void;
|
||||
@@ -115,8 +111,6 @@ class SemanticsNodeStack {
|
||||
// is used based on the ParseNodeKind.
|
||||
union {
|
||||
SemanticsNodeId node_id;
|
||||
|
||||
// Right now name_id is exclusively for PatternBinding, which is enforced.
|
||||
SemanticsStringId name_id;
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user