Adrien Leravat 0cb2c92c6c Explorer: support index-based fields for `FieldPath` and `Members` (#2417) il y a 3 ans
..
BUILD 9feff92f22 Track witnesses wherever possible (#2263) il y a 3 ans
README.md 856a5c4536 Fix broken link in doc (#1716) il y a 3 ans
ast.h 20728dbd3a CARBON_ header guards (#1261) il y a 4 ans
ast_node.cpp 309ec35f95 Rename executable_semantics to explorer (#1188) il y a 4 ans
ast_node.h 9007b3952d Initial support for `where` expressions. (#1310) il y a 3 ans
ast_rtti.txt 9e8cacae00 Implement support for named constraints (#2359) il y a 3 ans
ast_test_matchers.h 59ae6e31b6 Rename PrimitiveOperatorExpression to OperatorExpression. (#1530) il y a 3 ans
ast_test_matchers_internal.cpp 59ae6e31b6 Rename PrimitiveOperatorExpression to OperatorExpression. (#1530) il y a 3 ans
ast_test_matchers_internal.h 59ae6e31b6 Rename PrimitiveOperatorExpression to OperatorExpression. (#1530) il y a 3 ans
ast_test_matchers_test.cpp 59ae6e31b6 Rename PrimitiveOperatorExpression to OperatorExpression. (#1530) il y a 3 ans
bindings.cpp 8e5dcc2588 Enable readability-qualified-auto (#2314) il y a 3 ans
bindings.h 4d522c8e90 Finish making clang-tidy (mostly) work (again) and run -fix (#2312) il y a 3 ans
declaration.cpp 9e8cacae00 Implement support for named constraints (#2359) il y a 3 ans
declaration.h 46f4887cf7 Explorer: support `.base` to initialize parent class from struct (#2361) il y a 3 ans
expression.cpp 0219218b01 Make type contexts expect a value of type `Type`. (#2357) il y a 3 ans
expression.h e557d4af3b Make `addr me: Self*` work for interface methods. (#2374) il y a 3 ans
expression_test.cpp 309ec35f95 Rename executable_semantics to explorer (#1188) il y a 4 ans
impl_binding.h 4d522c8e90 Finish making clang-tidy (mostly) work (again) and run -fix (#2312) il y a 3 ans
library_name.h 20728dbd3a CARBON_ header guards (#1261) il y a 4 ans
member.cpp 0cb2c92c6c Explorer: support index-based fields for `FieldPath` and `Members` (#2417) il y a 3 ans
member.h 0cb2c92c6c Explorer: support index-based fields for `FieldPath` and `Members` (#2417) il y a 3 ans
paren_contents.h 20728dbd3a CARBON_ header guards (#1261) il y a 4 ans
pattern.cpp e4a2d0f047 Addr Keyword Implementation (#1255) il y a 3 ans
pattern.h dfbe35bae5 Remove pattern evaluation from the interpreter. (#2400) il y a 3 ans
pattern_test.cpp 309ec35f95 Rename executable_semantics to explorer (#1188) il y a 4 ans
return_term.h 20728dbd3a CARBON_ header guards (#1261) il y a 4 ans
statement.cpp 8e5dcc2588 Enable readability-qualified-auto (#2314) il y a 3 ans
statement.h cfa295c0af Feature destructor (#2116) il y a 3 ans
static_scope.cpp 1c5770452e Fix comment styles to use // consistently. (#2307) il y a 3 ans
static_scope.h 1c5770452e Fix comment styles to use // consistently. (#2307) il y a 3 ans
value_category.h f1e36a50ca C/C++ -> C and C++ (#2340) il y a 3 ans

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, 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.