source: src/AST/porting.md@ be567e9

ADT arm-eh ast-experimental cleanup-dtors enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum stuck-waitfor-destruct
Last change on this file since be567e9 was be567e9, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

  • Property mode set to 100644
File size: 6.0 KB
Line 
1# Porting notes for new AST #
2
3## Pointer Types ##
4* raw pointer `T*` is used for construction, but not storage
5* `ast::ptr_base<T,R>` is a pointer to AST node `T` with reference type `R`
6 * specialization: strong pointer `ast::ptr<T>` is used for an ownership relationship
7 * specialization: weak pointer `ast::readonly<T>` is used for an observation relationship
8 * added `ast::ptr_base<T,R>::as<S>()` with same semantics as `dynamic_cast<S*>(p)`
9
10## Visitors ##
11* `Visitor` and `Mutator` are combined into a single `ast::Visitor` class
12 * Base nodes now override `const Node * accept( Visitor & v ) const = 0` with, e.g. `const Stmt * accept( Visitor & v ) const override = 0`
13* `PassVisitor` is replaced with `ast::Pass`
14
15## Structural Changes ##
16`CodeLocation` has been devolved from `BaseSyntaxNode` to `ast::ParseNode`
17* excludes `ast::Type` from carrying location information
18* `CodeLocation` is a mandatory constructor field for `ast::ParseNode`
19 * all subclass constructors must fill it; by convention, from their first argument
20
21`N->print(std::ostream&)` is a visitor now, port these methods to `ast::Print` class
22* **TODO** write this visitor
23* **TODO** write `std::ostream& operator<< ( std::ostream& out, const Node* node )` in `Node.hpp` in terms of `ast::Print`
24* `Declaration::printShort` should also be integrated
25
26`clone` is private to `Node` now
27* still needs to be overriden to return appropriate type
28 * e.g. `private: virtual Stmt * clone() const override = 0;`
29 * because friendship is not inherited, all implementations of clone need
30 /// Must be copied in ALL derived classes
31 template<typename node_t>
32 friend auto mutate(const node_t * node);
33
34All leaves of the `Node` inheritance tree are now declared `final`
35* e.g. `class CompoundStmt final : public Stmt`
36* allows compiler to optimize virtual calls to static calls if given static type
37
38Pulled `FuncSpecifiers` and `StorageClasses` out of `Type` into their own headers
39* Made `BFCommon` a `MakeBitfield` macro in its own header
40 * added default and field-init constructors to macro
41
42Prefer move semantics for containers passed to node constructors
43
44## Code Style ##
45
46### Files ###
47* Headers have a `.hpp` suffix
48* Source code has a `.cpp` suffix
49* All source has the project-standard leading and trailing comments
50* prefer `#pragma once` over `#ifdef` guards
51* namespaces that cover entire files don't get indented
52
53### Documentation ###
54* class, method, and field comments should use doxygen-style `///` prefix
55 * should be included on all classes
56 * should be included on any method declaration that doesn't have an obvious behaviour from either naming convention (e.g. constructor, print operator, implement visitor pattern) or an inline implementation
57* use explanatory comments with `//` wherever appropriate
58 * older comments should be maintained in porting process wherever possible
59
60### Naming ###
61* Preserve names from previous AST whenever reasonable, and get team consensus on any changes.
62* Strong justification required for private fields
63 * No `get_` prefix on getters (including for generated fields)
64 * exception is `DeclWithType::get_type()`
65* Notable changes:
66 * for concision and consistency with subclasses:
67 * `Declaration` => `ast::Decl`
68 * `DeclarationWithType` => `ast::DeclWithType`
69 * `Expression` => `ast::Expr`
70 * `Initializer` => `ast::Init`
71 * `Statement` => `ast::Stmt`
72 * because they don't really belong to `Type` (and for consistency with `Linkage::Spec`):
73 * `Type::StorageClasses` => `ast::Storage::Classes`
74 * `Type::Extern` etc. => `ast::Storage::Extern` etc.
75 * `LinkageSpec::Spec` => `ast::Linkage::Spec`
76 * `LinkageSpec::Mangle` etc. => `ast::Linkage::Mangle` etc.
77 * `LinkageSpec::linkageUpdate` => `ast::Linkage::update`
78 * `LinkageSpec::linkageName` => `ast::Linkage::name`
79 * `LinkageSpec::isMangled(Spec)` etc. => `Spec.is_mangled` etc.
80 * `LinkageSpec::Intrinsic` etc. => `ast::Linkage::Intrinsic` etc.
81
82## Specific Nodes ##
83`Decl`
84* `storageClasses` => `storage`
85* `declFromId()` => `fromId()`
86 * not 100% sure about the return type here...
87
88`DeclWithType`
89* When `SymTab::Validate::Pass2` is rewritten, update comment on `mangleName` with new name of pass
90* `get_scopedMangleName()` => `scopedMangleName()`
91* `get_type()` now returns `const Type*` so can't be inadvertently mutated
92 * still with `get_` name so it doesn't conflict with subclass field names
93
94`ObjectDecl`
95* changed constructor parameter order for better defaults
96 * allows `newObject` as just default settings
97
98`TypeDecl`
99* stripped `isComplete()` accessor in favour of direct access to `sized`
100
101`EnumDecl`
102* **TODO** rebuild `eval` for new AST (re: `valueOf` implementation)
103
104`Expr`
105* Merged `inferParams`/`resnSlots` into union, as suggested by comment in old version
106 * does imply get_/set_ API, and some care about moving backward
107
108`Label`
109* `get_statement()` exclusively used for code location, replaced with `CodeLocation` field
110
111`CompoundStmt`
112* **TODO** port copy operator
113 * Needs to be an almost-shallow clone, where the declarations are cloned only if needed
114 * **TODO** port DeclReplacer
115* Still a `std::list` for children, rather than `std::vector`
116 * allows more-efficient splicing for purposes of later code generation
117
118`Type`
119* `forall` field split off into `ParameterizedType` subclass
120 * any type that needs it can inherit from `ParameterizedType`
121* `get_qualifiers()` replaced with accessor `qualifiers()` and mutator `set_qualifiers()`
122 * `get_CV()` replaced with `is_CV()` variants
123* A number of features only supported on aggregates pushed down to `ReferenceToType`:
124 * `attributes`: per docs [1] GCC only supports type attributes on aggregates and typedefs
125 * suggest adding a `TypeWithAttributes` wrapper type if this proves insufficient
126 * `getAggr()`
127 * `genericSubstitution()`
128
129`BasicType`
130* does not inherit from `Type` to allow pointer inlining
131* moved `Kind` before qualifiers in constructor to allow for default
132* **TODO** move `kind`, `typeNames` into code generator
133
134[1] https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Type-Attributes.html#Type-Attributes
135
Note: See TracBrowser for help on using the repository browser.