Manmeet Singh f310316ef4 fix printing for single element tuple values (#2786) %!s(int64=3) %!d(string=hai) anos
..
BUILD d0645c6a85 Explorer: rename value categories to expression categories (#2744) %!s(int64=3) %!d(string=hai) anos
README.md 807ef98758 Replace RTTI generation script with macros. (#2703) %!s(int64=3) %!d(string=hai) anos
address.h df289efac4 Explorer: Add virtual destructor support (#2695) %!s(int64=3) %!d(string=hai) anos
ast.h 9df70fb115 Disable most tracing in the prelude. (#2616) %!s(int64=3) %!d(string=hai) anos
ast_kinds.h 39155d34ae Remove experimental continuation support (#2776) %!s(int64=3) %!d(string=hai) anos
ast_node.cpp 309ec35f95 Rename executable_semantics to explorer (#1188) %!s(int64=4) %!d(string=hai) anos
ast_node.h 782bd87316 AST cloning mechanism (#2699) %!s(int64=3) %!d(string=hai) anos
ast_rtti.cpp 807ef98758 Replace RTTI generation script with macros. (#2703) %!s(int64=3) %!d(string=hai) anos
ast_rtti.h 807ef98758 Replace RTTI generation script with macros. (#2703) %!s(int64=3) %!d(string=hai) anos
ast_test_matchers.h 59ae6e31b6 Rename PrimitiveOperatorExpression to OperatorExpression. (#1530) %!s(int64=3) %!d(string=hai) anos
ast_test_matchers_internal.cpp c172487395 Support for declaring functions within a namespace (#2569) %!s(int64=3) %!d(string=hai) anos
ast_test_matchers_internal.h 59ae6e31b6 Rename PrimitiveOperatorExpression to OperatorExpression. (#1530) %!s(int64=3) %!d(string=hai) anos
ast_test_matchers_test.cpp c172487395 Support for declaring functions within a namespace (#2569) %!s(int64=3) %!d(string=hai) anos
bindings.cpp 782bd87316 AST cloning mechanism (#2699) %!s(int64=3) %!d(string=hai) anos
bindings.h 782bd87316 AST cloning mechanism (#2699) %!s(int64=3) %!d(string=hai) anos
clone_context.cpp 951cac9607 clang-tidy cleanup (#2774) %!s(int64=3) %!d(string=hai) anos
clone_context.h 807ef98758 Replace RTTI generation script with macros. (#2703) %!s(int64=3) %!d(string=hai) anos
declaration.cpp 951cac9607 clang-tidy cleanup (#2774) %!s(int64=3) %!d(string=hai) anos
declaration.h 68e15c37a3 feat: implement namespace alias (#2720) %!s(int64=3) %!d(string=hai) anos
element.cpp 694dd7bf55 Fix poor dyn_cast usage (#2763) %!s(int64=3) %!d(string=hai) anos
element.h 92e6e5f6f5 Fix missing include in element.h (#2506) %!s(int64=3) %!d(string=hai) anos
element_path.h df289efac4 Explorer: Add virtual destructor support (#2695) %!s(int64=3) %!d(string=hai) anos
element_test.cpp d0645c6a85 Explorer: rename value categories to expression categories (#2744) %!s(int64=3) %!d(string=hai) anos
expression.cpp 39155d34ae Remove experimental continuation support (#2776) %!s(int64=3) %!d(string=hai) anos
expression.h 39155d34ae Remove experimental continuation support (#2776) %!s(int64=3) %!d(string=hai) anos
expression_category.h d0645c6a85 Explorer: rename value categories to expression categories (#2744) %!s(int64=3) %!d(string=hai) anos
expression_test.cpp 309ec35f95 Rename executable_semantics to explorer (#1188) %!s(int64=4) %!d(string=hai) anos
impl_binding.cpp 782bd87316 AST cloning mechanism (#2699) %!s(int64=3) %!d(string=hai) anos
impl_binding.h d0645c6a85 Explorer: rename value categories to expression categories (#2744) %!s(int64=3) %!d(string=hai) anos
library_name.h 20728dbd3a CARBON_ header guards (#1261) %!s(int64=4) %!d(string=hai) anos
paren_contents.h 20728dbd3a CARBON_ header guards (#1261) %!s(int64=4) %!d(string=hai) anos
pattern.cpp e0c90767be Support for templated impl declarations (#2700) %!s(int64=3) %!d(string=hai) anos
pattern.h d0645c6a85 Explorer: rename value categories to expression categories (#2744) %!s(int64=3) %!d(string=hai) anos
pattern_test.cpp 309ec35f95 Rename executable_semantics to explorer (#1188) %!s(int64=4) %!d(string=hai) anos
return_term.h 782bd87316 AST cloning mechanism (#2699) %!s(int64=3) %!d(string=hai) anos
statement.cpp 39155d34ae Remove experimental continuation support (#2776) %!s(int64=3) %!d(string=hai) anos
statement.h 39155d34ae Remove experimental continuation support (#2776) %!s(int64=3) %!d(string=hai) anos
static_scope.cpp 1a8a41a5a6 Improve diagnostic for unknown name in name qualifier. (#2579) %!s(int64=3) %!d(string=hai) anos
static_scope.h 1a8a41a5a6 Improve diagnostic for unknown name in name qualifier. (#2579) %!s(int64=3) %!d(string=hai) anos
value.cpp f310316ef4 fix printing for single element tuple values (#2786) %!s(int64=3) %!d(string=hai) anos
value.h 39155d34ae Remove experimental continuation support (#2776) %!s(int64=3) %!d(string=hai) anos
value_kinds.def 39155d34ae Remove experimental continuation support (#2776) %!s(int64=3) %!d(string=hai) anos
value_node.h d0645c6a85 Explorer: rename value categories to expression categories (#2744) %!s(int64=3) %!d(string=hai) anos
value_transform.h 39155d34ae Remove experimental continuation support (#2776) %!s(int64=3) %!d(string=hai) anos

README.md

The code in this directory defines the AST that represents Carbon code in the rest of explorer.

The AST is not quite immutable, because some node properties are set during some phase of static analysis, rather than during parsing. However, AST mutations are monotonic: once set, a node property cannot be changed. Furthermore, if a property is set after parsing, its documentation specifies what phase is responsible for setting it. Certain properties have has_foo() members for querying whether they are set, but those are for internal use within the phase that sets them. As a result, you can think of the AST as if it were immutable, but with certain parts that you can't yet observe, depending on what phase of compilation you're in.

All node types in the AST are derived from AstNode, and use LLVM-style RTTI to support safe down-casting and similar operations. Each abstract class Foo in the hierarchy has a kind method which returns a enum FooKind that identifies the concrete type of the object, and a FooKind value can be safely static_casted to BarKind if that value represents a type that's derived from both Foo and Bar.

These FooKind enums are generated from a description of the class hierarchy that is provided by X macros defined in ast_kinds.h that specify the classes derived from each AST base class. Those macros must be kept up to date as the class hierarchy changes.

The AST class hierarchy is structured in a fairly unsurprising way, with abstract classes such as Statement and Expression, and concrete classes representing individual syntactic constructs, such as If for if-statements.

Sometimes it is useful to work with a subset of node types that "cuts across" the primary class hierarchy. Rather than deal with the pitfalls of multiple inheritance, we handle these cases using a form of type erasure: we specify a notional interface that those types conform to, and then define a "view" class that behaves like a pointer to an instance of that interface. Types declare that they model an interface Foo by defining a public static member named ImplementsCarbonFoo. See ValueNodeView for an example of this pattern.