Richard Smith 9ea405788e Combine most ast/ build targets into one. (#1334) 3 years ago
..
BUILD 9ea405788e Combine most ast/ build targets into one. (#1334) 3 years ago
README.md 309ec35f95 Rename executable_semantics to explorer (#1188) 4 years ago
ast.h 20728dbd3a CARBON_ header guards (#1261) 4 years ago
ast_node.cpp 309ec35f95 Rename executable_semantics to explorer (#1188) 4 years ago
ast_node.h 9007b3952d Initial support for `where` expressions. (#1310) 3 years ago
ast_rtti.txt 2fef76e58c Basic support for `.Self` within `:!` bindings and `where` expressions. (#1311) 3 years ago
ast_test_matchers.h 20728dbd3a CARBON_ header guards (#1261) 4 years ago
ast_test_matchers_internal.cpp 309ec35f95 Rename executable_semantics to explorer (#1188) 4 years ago
ast_test_matchers_internal.h 20728dbd3a CARBON_ header guards (#1261) 4 years ago
ast_test_matchers_test.cpp 309ec35f95 Rename executable_semantics to explorer (#1188) 4 years ago
bindings.cpp a1be2a8a38 Track the arguments and witnesses on values indirectly. (#1335) 3 years ago
bindings.h a1be2a8a38 Track the arguments and witnesses on values indirectly. (#1335) 3 years ago
declaration.cpp 17ee3ed9b7 Track a resolved `Member` on each member access expression. (#1333) 3 years ago
declaration.h 17ee3ed9b7 Track a resolved `Member` on each member access expression. (#1333) 3 years ago
expression.cpp 17ee3ed9b7 Track a resolved `Member` on each member access expression. (#1333) 3 years ago
expression.h a1be2a8a38 Track the arguments and witnesses on values indirectly. (#1335) 3 years ago
expression_test.cpp 309ec35f95 Rename executable_semantics to explorer (#1188) 4 years ago
impl_binding.h 392182cee1 Check for a symbolic value only if normal value lookup fails. (#1326) 3 years ago
library_name.h 20728dbd3a CARBON_ header guards (#1261) 4 years ago
member.cpp 17ee3ed9b7 Track a resolved `Member` on each member access expression. (#1333) 3 years ago
member.h 17ee3ed9b7 Track a resolved `Member` on each member access expression. (#1333) 3 years ago
paren_contents.h 20728dbd3a CARBON_ header guards (#1261) 4 years ago
pattern.cpp e4a2d0f047 Addr Keyword Implementation (#1255) 3 years ago
pattern.h 17ee3ed9b7 Track a resolved `Member` on each member access expression. (#1333) 3 years ago
pattern_test.cpp 309ec35f95 Rename executable_semantics to explorer (#1188) 4 years ago
return_term.h 20728dbd3a CARBON_ header guards (#1261) 4 years ago
statement.cpp 309ec35f95 Rename executable_semantics to explorer (#1188) 4 years ago
statement.h 8dd398807d Support user-defined implicit conversions via `ImplicitAs` (#1273) 4 years ago
static_scope.cpp ccc6498993 Add alias name to name resolution after processing the target to avoid self-referencing name crash (#1295) 3 years ago
static_scope.h 2fef76e58c Basic support for `.Self` within `:!` bindings and `where` expressions. (#1311) 3 years ago
value_category.h 20728dbd3a CARBON_ header guards (#1261) 4 years ago

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.

We rely on code generation to help enforce those invariants, so every node type must be described in ast_rtti.txt. See the documentation in (gen_rtti.py)[../gen_rtti.py], the code generation script, for details about the file format and generated code.

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.