Boaz Brickner aa23e9e2d8 Update LLVM (#4807) 1 năm trước cách đây
..
BUILD a3b1c433be Remove legacy repo_name settings (#3772) 2 năm trước cách đây
README.md b6396e97f8 Build a website. (#4189) 1 năm trước cách đây
address.h 53af8f04b2 Provide a Printable CRTP parent to replace HasPrintable templates. (#3166) 2 năm trước cách đây
ast.h 357baaeef8 Rename //explorer/common to base (#3103) 2 năm trước cách đây
ast_kinds.h 1505a634a4 Implement syntax changes from #2760 in Explorer (#2906) 2 năm trước cách đây
ast_node.cpp 309ec35f95 Rename executable_semantics to explorer (#1188) 4 năm trước cách đây
ast_node.h 53af8f04b2 Provide a Printable CRTP parent to replace HasPrintable templates. (#3166) 2 năm trước cách đây
ast_rtti.cpp 29b6399e4f Modify EnumBase to better support the namespacing of toolchain (#3156) 2 năm trước cách đây
ast_rtti.h 5020fdb3be Use abbreviation "decl" instead of "declaration" (#3382) 2 năm trước cách đây
ast_test_matchers.h 59ae6e31b6 Rename PrimitiveOperatorExpression to OperatorExpression. (#1530) 3 năm trước cách đây
ast_test_matchers_internal.cpp c172487395 Support for declaring functions within a namespace (#2569) 3 năm trước cách đây
ast_test_matchers_internal.h 59ae6e31b6 Rename PrimitiveOperatorExpression to OperatorExpression. (#1530) 3 năm trước cách đây
ast_test_matchers_test.cpp 2de79a6db0 Fix test to use a single test suite with multiple tests. (#3458) 2 năm trước cách đây
bindings.cpp 4845f40dff Switch `CARBON_CHECK` to a format string API (#4285) 1 năm trước cách đây
bindings.h 53af8f04b2 Provide a Printable CRTP parent to replace HasPrintable templates. (#3166) 2 năm trước cách đây
clone_context.cpp 4845f40dff Switch `CARBON_CHECK` to a format string API (#4285) 1 năm trước cách đây
clone_context.h 4845f40dff Switch `CARBON_CHECK` to a format string API (#4285) 1 năm trước cách đây
declaration.cpp 4845f40dff Switch `CARBON_CHECK` to a format string API (#4285) 1 năm trước cách đây
declaration.h 4845f40dff Switch `CARBON_CHECK` to a format string API (#4285) 1 năm trước cách đây
element.cpp aa23e9e2d8 Update LLVM (#4807) 1 năm trước cách đây
element.h 53af8f04b2 Provide a Printable CRTP parent to replace HasPrintable templates. (#3166) 2 năm trước cách đây
element_path.h 4845f40dff Switch `CARBON_CHECK` to a format string API (#4285) 1 năm trước cách đây
element_test.cpp e3d3122f1d Move tests to the namespace of the code under test (#3244) 2 năm trước cách đây
expression.cpp 4845f40dff Switch `CARBON_CHECK` to a format string API (#4285) 1 năm trước cách đây
expression.h 4845f40dff Switch `CARBON_CHECK` to a format string API (#4285) 1 năm trước cách đây
expression_category.h 7bcfe7df59 LLVM should be included using quotes. (#2952) 2 năm trước cách đây
expression_test.cpp e3d3122f1d Move tests to the namespace of the code under test (#3244) 2 năm trước cách đây
impl_binding.cpp 782bd87316 AST cloning mechanism (#2699) 3 năm trước cách đây
impl_binding.h 4845f40dff Switch `CARBON_CHECK` to a format string API (#4285) 1 năm trước cách đây
library_name.h 20728dbd3a CARBON_ header guards (#1261) 4 năm trước cách đây
paren_contents.h 357baaeef8 Rename //explorer/common to base (#3103) 2 năm trước cách đây
pattern.cpp 357baaeef8 Rename //explorer/common to base (#3103) 2 năm trước cách đây
pattern.h 4845f40dff Switch `CARBON_CHECK` to a format string API (#4285) 1 năm trước cách đây
pattern_test.cpp e3d3122f1d Move tests to the namespace of the code under test (#3244) 2 năm trước cách đây
return_term.h 53af8f04b2 Provide a Printable CRTP parent to replace HasPrintable templates. (#3166) 2 năm trước cách đây
statement.cpp 289d05813e Explorer: Remove `PrintDepth` and implement `PrintIndent`. (#3113) 2 năm trước cách đây
statement.h 4845f40dff Switch `CARBON_CHECK` to a format string API (#4285) 1 năm trước cách đây
static_scope.cpp 4845f40dff Switch `CARBON_CHECK` to a format string API (#4285) 1 năm trước cách đây
static_scope.h 44fdcc3db8 Refactor Duplicate Code Patterns in StaticScope Class (#3550) 2 năm trước cách đây
value.cpp 4845f40dff Switch `CARBON_CHECK` to a format string API (#4285) 1 năm trước cách đây
value.h 4845f40dff Switch `CARBON_CHECK` to a format string API (#4285) 1 năm trước cách đây
value_kinds.def d02366f881 Explorer: Prevent copies when initializing a let binding from reference expression (#2946) 2 năm trước cách đây
value_node.h 53af8f04b2 Provide a Printable CRTP parent to replace HasPrintable templates. (#3166) 2 năm trước cách đây
value_transform.h c93a0e5e42 Implement canonicalization of Value and Element (#3024) 2 năm trước cách đây

README.md

Explorer AST

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.