mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-22 23:22:51 +00:00
This adds tracking of call information plus basic type checking. It adds a builtin for the empty tuple, mainly so that I have the basis for a default function return type. As an aside, it also unifies printing within SemanticsIR, fixing a missing comma after callables. Co-authored-by: Richard Smith <richard@metafoo.co.uk>
75 lines
2.9 KiB
Modula-2
75 lines
2.9 KiB
Modula-2
// 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
|
|
//
|
|
// Note that this is an X-macro header.
|
|
//
|
|
// It does not use `#include` guards, and instead is designed to be `#include`ed
|
|
// after the x-macro is defined in order for its inclusion to expand to the
|
|
// desired output.
|
|
//
|
|
// x-macros come in two forms:
|
|
// CARBON_SEMANTICS_BUILTIN_KIND_NAME(Name)
|
|
// Used as a fallback if other macros are missing.
|
|
// CARBON_SEMANTICS_BUILTIN_KIND(Name, Type)
|
|
// Defines a builtin kind with the associated type, which must also be
|
|
// builtin.
|
|
//
|
|
// Note that Invalid is provided with CARBON_SEMANTICS_BUILTIN_KIND_NAME but not
|
|
// CARBON_SEMANTICS_BUILTIN_KIND.
|
|
|
|
#if !(defined(CARBON_SEMANTICS_BUILTIN_KIND_NAME) || \
|
|
defined(CARBON_SEMANTICS_BUILTIN_KIND))
|
|
#error \
|
|
"Must define CARBON_SEMANTICS_BUILTIN_KIND family x-macros to use this file."
|
|
#endif
|
|
|
|
// If CARBON_SEMANTICS_BUILTIN_KIND_NAME is undefined, ignore calls.
|
|
#ifndef CARBON_SEMANTICS_BUILTIN_KIND_NAME
|
|
#define CARBON_SEMANTICS_BUILTIN_KIND_NAME(Name)
|
|
#endif
|
|
|
|
// If CARBON_SEMANTICS_BUILTIN_KIND is undefined, delegate calls to
|
|
// CARBON_SEMANTICS_BUILTIN_KIND_NAME.
|
|
#ifndef CARBON_SEMANTICS_BUILTIN_KIND
|
|
#define CARBON_SEMANTICS_BUILTIN_KIND(Name, ...) \
|
|
CARBON_SEMANTICS_BUILTIN_KIND_NAME(Name)
|
|
#endif
|
|
|
|
// Tracks expressions which are valid as types.
|
|
// This has a deliberately self-referential type.
|
|
CARBON_SEMANTICS_BUILTIN_KIND(TypeType, TypeType)
|
|
|
|
// Used when a SemanticNode has an invalid type, which should then be ignored
|
|
// for future type checking.
|
|
// This has a deliberately self-referential type.
|
|
CARBON_SEMANTICS_BUILTIN_KIND(InvalidType, InvalidType)
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// TODO: Below types are all placeholders. While the above may last, the below
|
|
// are expected to need to change in order to better reflect Carbon's design.
|
|
// Keeping distinct placeholders can help find usages for later fixes.
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// The type of integer values and integer literals, currently always i32.
|
|
CARBON_SEMANTICS_BUILTIN_KIND(IntegerType, TypeType)
|
|
|
|
// The type of floating point values and real literals, currently always f64.
|
|
CARBON_SEMANTICS_BUILTIN_KIND(FloatingPointType, TypeType)
|
|
|
|
// The type of string values and String literals.
|
|
CARBON_SEMANTICS_BUILTIN_KIND(StringType, TypeType)
|
|
|
|
// The canonical empty tuple type, or `() as type`.
|
|
CARBON_SEMANTICS_BUILTIN_KIND(EmptyTupleType, TypeType)
|
|
|
|
// The canonical empty tuple, or `()`.
|
|
CARBON_SEMANTICS_BUILTIN_KIND(EmptyTuple, EmptyTupleType)
|
|
|
|
// Keep invalid last, so that we can use values as array indices without needing
|
|
// an invalid entry.
|
|
CARBON_SEMANTICS_BUILTIN_KIND_NAME(Invalid)
|
|
|
|
#undef CARBON_SEMANTICS_BUILTIN_KIND_NAME
|
|
#undef CARBON_SEMANTICS_BUILTIN_KIND
|