Richard Smith bfe5c36bfc Move `Value`, `Address`, and `ElementPath` to ast/. (#2659) пре 3 година
..
BUILD bfe5c36bfc Move `Value`, `Address`, and `ElementPath` to ast/. (#2659) пре 3 година
README.md 47a1e99b9e Factor `ValueNodeView` out of `StaticScope`. (#2562) пре 3 година
address.h bfe5c36bfc Move `Value`, `Address`, and `ElementPath` to ast/. (#2659) пре 3 година
ast.h 9df70fb115 Disable most tracing in the prelude. (#2616) пре 3 година
ast_node.cpp 309ec35f95 Rename executable_semantics to explorer (#1188) пре 4 година
ast_node.h 9007b3952d Initial support for `where` expressions. (#1310) пре 3 година
ast_rtti.txt 60af531f5b Support parsing namespace declarations (#2563) пре 3 година
ast_test_matchers.h 59ae6e31b6 Rename PrimitiveOperatorExpression to OperatorExpression. (#1530) пре 3 година
ast_test_matchers_internal.cpp c172487395 Support for declaring functions within a namespace (#2569) пре 3 година
ast_test_matchers_internal.h 59ae6e31b6 Rename PrimitiveOperatorExpression to OperatorExpression. (#1530) пре 3 година
ast_test_matchers_test.cpp c172487395 Support for declaring functions within a namespace (#2569) пре 3 година
bindings.cpp 8e5dcc2588 Enable readability-qualified-auto (#2314) пре 3 година
bindings.h 43283cb516 Add `Value` decomposition and use it to implement `Substitute` (#2389) пре 3 година
declaration.cpp 7fe8bb308b Clean up clang-tidy issues in explorer. (#2621) пре 3 година
declaration.h 09891d4141 Explorer: drop outdated TODO comment. (#2639) пре 3 година
element.cpp 43283cb516 Add `Value` decomposition and use it to implement `Substitute` (#2389) пре 3 година
element.h 92e6e5f6f5 Fix missing include in element.h (#2506) пре 3 година
element_path.h bfe5c36bfc Move `Value`, `Address`, and `ElementPath` to ast/. (#2659) пре 3 година
element_test.cpp bfe5c36bfc Move `Value`, `Address`, and `ElementPath` to ast/. (#2659) пре 3 година
expression.cpp bfe5c36bfc Move `Value`, `Address`, and `ElementPath` to ast/. (#2659) пре 3 година
expression.h 6d4920148b Initial support for name lookup into namespaces. (#2572) пре 3 година
expression_test.cpp 309ec35f95 Rename executable_semantics to explorer (#1188) пре 4 година
impl_binding.h 4d522c8e90 Finish making clang-tidy (mostly) work (again) and run -fix (#2312) пре 3 година
library_name.h 20728dbd3a CARBON_ header guards (#1261) пре 4 година
paren_contents.h 20728dbd3a CARBON_ header guards (#1261) пре 4 година
pattern.cpp e4a2d0f047 Addr Keyword Implementation (#1255) пре 3 година
pattern.h 47a1e99b9e Factor `ValueNodeView` out of `StaticScope`. (#2562) пре 3 година
pattern_test.cpp 309ec35f95 Rename executable_semantics to explorer (#1188) пре 4 година
return_term.h 20728dbd3a CARBON_ header guards (#1261) пре 4 година
statement.cpp 2fd7e2b65d Add support for compound assignment and increment (#2526) пре 3 година
statement.h 4e1b585fcf clang-tidy --fix (#2577) пре 3 година
static_scope.cpp 1a8a41a5a6 Improve diagnostic for unknown name in name qualifier. (#2579) пре 3 година
static_scope.h 1a8a41a5a6 Improve diagnostic for unknown name in name qualifier. (#2579) пре 3 година
value.cpp bfe5c36bfc Move `Value`, `Address`, and `ElementPath` to ast/. (#2659) пре 3 година
value.h bfe5c36bfc Move `Value`, `Address`, and `ElementPath` to ast/. (#2659) пре 3 година
value_category.h f1e36a50ca C/C++ -> C and C++ (#2340) пре 3 година
value_kinds.def bfe5c36bfc Move `Value`, `Address`, and `ElementPath` to ast/. (#2659) пре 3 година
value_node.h 47a1e99b9e Factor `ValueNodeView` out of `StaticScope`. (#2562) пре 3 година
value_transform.h bfe5c36bfc Move `Value`, `Address`, and `ElementPath` to ast/. (#2659) пре 3 година

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.