Files
carbon-lang/toolchain/parse/node_category.h
T
Richard Smith bf5d2a2ace Add support for -> auto deduced return types. (#7931)
The return type is deduced from the function's `return` statements
(currently required to all have the same type), or from its first
`returned var`. Calls to generic functions with deduced return types are
not yet supported.

When a function has a deduced return type, we defer the return type
portion of the callee pattern match until deduction, and during
deduction we extend the decl block and the pattern block with the
return-related instructions.

Conversions for `return expr;` statements are deferred until the return
type has been deduced. The design requires that we take the common type
of the returned types as the deduced return type, so we can't in general
perform any conversions for returned expressions until we reach the end
of the function. This is accomplished by inserting a `splice_block`
where the conversions will go, and later updating that instruction to
contain the conversion.

Assisted-by: Claude Opus 5.5 via Antigravity
2026-10-15 00:30:09 +00:00

63 lines
2.6 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 CARBON_TOOLCHAIN_PARSE_NODE_CATEGORY_H_
#define CARBON_TOOLCHAIN_PARSE_NODE_CATEGORY_H_
#include "common/enum_mask_base.h"
#include "common/ostream.h"
namespace Carbon::Parse {
// An X-macro for node categories. Uses should look like:
//
// #define CARBON_NODE_CATEGORY_FOR_XYZ(Name) ...
// CARBON_NODE_CATEGORY(CARBON_NODE_CATEGORY_FOR_XYZ)
// #undef CARBON_NODE_CATEGORY_FOR_XYZ
#define CARBON_NODE_CATEGORY(X) \
X(Decl) \
X(Expr) \
/* `impl <type> as` or just `impl as` */ \
X(ImplAs) \
X(IntConst) \
X(MemberExpr) \
X(MemberName) \
X(Modifier) \
X(NonExprName) \
/* `observe <type> == <type>` or `observe <type> impls` */ \
X(ObserveOperator) \
X(PackageName) \
X(Pattern) \
/* `require <type> impls` or just `require impls` */ \
X(RequireImpls) \
X(Requirement) \
X(ReturnSpecifier) \
X(Statement)
// We expect this to grow, so are using a bigger size than needed.
CARBON_DEFINE_RAW_ENUM_MASK(NodeCategory, uint32_t) {
CARBON_NODE_CATEGORY(CARBON_RAW_ENUM_MASK_ENUMERATOR)
};
// Represents a set of keyword modifiers, using a separate bit per modifier.
class NodeCategory : public CARBON_ENUM_MASK_BASE(NodeCategory) {
public:
CARBON_NODE_CATEGORY(CARBON_ENUM_MASK_CONSTANT_DECL)
using EnumMaskBase::EnumMaskBase;
// Provide implicit conversion because the raw enum is used in templates.
explicit(false) constexpr NodeCategory(RawEnumType value) {
*this = EnumBase::Make(value);
}
};
#define CARBON_NODE_CATEGORY_WITH_TYPE(X) \
CARBON_ENUM_MASK_CONSTANT_DEFINITION(NodeCategory, X)
CARBON_NODE_CATEGORY(CARBON_NODE_CATEGORY_WITH_TYPE)
#undef CARBON_NODE_CATEGORY_WITH_TYPE
} // namespace Carbon::Parse
#endif // CARBON_TOOLCHAIN_PARSE_NODE_CATEGORY_H_