Changes in src/AST/porting.md [54e41b3:1e97287]
- File:
-
- 1 edited
-
src/AST/porting.md (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/porting.md
r54e41b3 r1e97287 6 6 * specialization: strong pointer `ast::ptr<T>` is used for an ownership relationship 7 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 * added `N * ast::ptr_base<N,R>::set_and_mutate( const N * n )` 10 * takes ownership of `n`, then returns a mutable version owned by this pointer 11 * Some debate on whether this is a good approach: 12 * makes an easy path to cloning, which we were trying to eliminate 13 * counter-point: these are all mutating clones rather than lifetime-preserving clones, and thus "necessary" (for some definition) 14 * existing uses: 15 * `VariableExpr::VariableExpr`, `UntypedExpr::createDeref` 16 * both involve grabbing a type from elsewhere and making an `lvalue` copy of it 17 * could potentially be replaced by a view class something like this: 18 ``` 19 template<unsigned Quals> 20 class AddQualifiersType final : public Type { 21 readonly<Type> base; 22 // ... 23 }; 24 ``` 25 * requires all `qualifiers` use (and related helpers) to be virtual, non-zero overhead 26 * also subtle semantic change, where mutations to the source decl now change the viewing expression 8 * added `ast::ptr_base<T,R>::as<S>()` with same semantics as `dynamic_cast<S*>(p)` 27 9 28 10 ## Visitors ## … … 54 36 * allows compiler to optimize virtual calls to static calls if given static type 55 37 56 Pulled `FuncSpecifiers` , `StorageClasses`, `CVQualifiers` out of `Type` into their own headers38 Pulled `FuncSpecifiers` and `StorageClasses` out of `Type` into their own headers 57 39 * Made `BFCommon` a `MakeBitfield` macro in its own header 58 40 * added default and field-init constructors to macro … … 88 70 * `Initializer` => `ast::Init` 89 71 * `Statement` => `ast::Stmt` 90 * any field names should follow a similar renaming91 72 * because they don't really belong to `Type` (and for consistency with `Linkage::Spec`): 92 73 * `Type::StorageClasses` => `ast::Storage::Classes` 93 74 * `Type::Extern` etc. => `ast::Storage::Extern` etc. 94 * `Type::FuncSpecifiers` => `ast::Function::Specs`95 * `Type::Inline` etc. => `ast::Function::Inline` etc.96 * `Type::Qualifiers` => `ast::CV::Qualifiers`97 * `Type::Const` etc. => `ast::CV::Const`98 * couldn't break name-dependency loop without pulling `Qualifiers` out of `Type`99 75 * `LinkageSpec::Spec` => `ast::Linkage::Spec` 100 76 * `LinkageSpec::Mangle` etc. => `ast::Linkage::Mangle` etc. … … 103 79 * `LinkageSpec::isMangled(Spec)` etc. => `Spec.is_mangled` etc. 104 80 * `LinkageSpec::Intrinsic` etc. => `ast::Linkage::Intrinsic` etc. 105 * Boolean constructor parameters get replaced with a dedicated flag enum:106 * e.g. `bool isVarLen;` => `enum LengthFlag { FixedLen, VariableLen };` `LengthFlag isVarLen;`107 * field can be *read* in the existing boolean contexts, but requires documentation to write108 * suggest naming all flag enums `FooFlag` to hint at boolean nature109 81 110 82 ## Specific Nodes ## … … 124 96 * allows `newObject` as just default settings 125 97 126 `NamedTypeDecl`127 * `parameters` => `params`128 129 98 `TypeDecl` 130 * moved `TypeDecl::Kind` to `ast::TypeVar::Kind` 131 132 `AggregateDecl` 133 * `parameters` => `params` 99 * stripped `isComplete()` accessor in favour of direct access to `sized` 134 100 135 101 `EnumDecl` … … 139 105 * Merged `inferParams`/`resnSlots` into union, as suggested by comment in old version 140 106 * does imply get_/set_ API, and some care about moving backward 141 * added constructor that sets result, for benefit of types that set it directly142 143 `ApplicationExpr`144 * `function` => `func`145 146 `UntypedExpr`147 * `function` => `func`148 * removed `begin_args()` in favour of `args.begin()`149 150 `MemberExpr`151 * **TODO** port setup of `result` in constructor152 153 `ConstantExpr`154 * inlined features of `Constant`, never used elsewhere, so removed `Constant`155 * `Constant Constant::from_int(int)` etc. => `ConstantExpr * ConstantExpr::from_int(CodeLocation, int)`156 * allocates new `ConstantExpr`, consistent with all existing uses157 158 `SizeofExpr`, `AlignofExpr`159 * `isType` deprecated in favour of boolean check on `type`160 * all existing uses assume `type` set if true and don't use `expr`161 162 `AttrExpr`163 * did not port due to feature deprecation (e.g. `expr@attribute`)164 165 `LogicalExpr`166 * un-defaulted constructor parameter determining `&&` or `||`167 168 `Init`169 * `bool maybeConstruct` => `enum ConstructFlag { DoConstruct, MaybeConstruct }`170 107 171 108 `Label` … … 192 129 * **TODO** port copy operator 193 130 * Needs to be an almost-shallow clone, where the declarations are cloned only if needed 194 * **TODO** port `DeclReplacer`131 * **TODO** port DeclReplacer 195 132 * Still a `std::list` for children, rather than `std::vector` 196 133 * allows more-efficient splicing for purposes of later code generation 197 134 198 135 `Type` 199 * `CV::Qualifiers` moved to end of constructor parameter list, defaulted to `{}`200 * removed getter, setter in favour of public `qualifiers` field201 * `ReferenceToType` puts a defaulted list of attributes after qualifiers202 136 * `forall` field split off into `ParameterizedType` subclass 203 137 * any type that needs it can inherit from `ParameterizedType` 204 * currently `FunctionType`, `ReferenceToType`205 138 * `get_qualifiers()` replaced with accessor `qualifiers()` and mutator `set_qualifiers()` 206 * `get_const()` etc. replaced with `is_const()` etc. variants 207 * `referenceDepth()` now returns `unsigned` rather than `int` 139 * `get_CV()` replaced with `is_CV()` variants 208 140 * A number of features only supported on aggregates pushed down to `ReferenceToType`: 209 141 * `attributes`: per docs [1] GCC only supports type attributes on aggregates and typedefs 210 142 * suggest adding a `TypeWithAttributes` wrapper type if this proves insufficient 211 * `getAggr()` => `aggr()` 212 * also now returns `const AggregateDecl *` 213 * `genericSubstitution()` moved to own visitor in `AST/GenericSubstitution.hpp` **TODO** write 143 * `getAggr()` 144 * `genericSubstitution()` 214 145 215 146 `BasicType` 147 * does not inherit from `Type` to allow pointer inlining 148 * moved `Kind` before qualifiers in constructor to allow for default 216 149 * **TODO** move `kind`, `typeNames` into code generator 217 218 `ReferenceToType`219 * deleted `get_baseParameters()` from children220 * replace with `aggr() ? aggr()->params : nullptr`221 * `parameters` => `params`222 * hoisted `lookup` implementation into parent, made non-virtual223 * also changed to return vector rather than filling; change back if any great win for reuse224 * `baseStruct` etc. renamed to `base`225 226 `PointerType`/`ArrayType`227 * `is_array()` => `isArray()`228 * `bool isVarLen;` => `enum LengthFlag { FixedLen, VariableLen }; LengthFlag isVarLen;`229 * `bool isStatic;` => `enum DimensionFlag { DynamicDim, StaticDim }; DimensionFlag isStatic;`230 231 `FunctionType`232 * `returnVals` => `returns`233 * `parameters` => `params`234 * `bool isVarArgs;` => `enum ArgumentFlag { FixedArgs, VariableArgs }; ArgumentFlag isVarArgs;`235 236 `TypeInstType`237 * `bool isFtype` => `TypeVar::Kind kind`238 239 `TypeofType`240 * `bool is_basetypeof` => `enum Kind { Typeof, Basetypeof } kind;`241 242 `TupleType`243 * removed `value_type` typedef due to likely error244 * if readded, should be `const Type *`245 246 `AttrType`247 * did not port due to deprecation of feature248 * feature is `type@thing` e.g. `int@MAX`249 150 250 151 [1] https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Type-Attributes.html#Type-Attributes
Note:
See TracChangeset
for help on using the changeset viewer.