Changes in src/AST/porting.md [1e97287:54e41b3]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/porting.md
r1e97287 r54e41b3 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)` 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 9 27 10 28 ## Visitors ## … … 36 54 * allows compiler to optimize virtual calls to static calls if given static type 37 55 38 Pulled `FuncSpecifiers` and `StorageClasses` out of `Type` into their own headers56 Pulled `FuncSpecifiers`, `StorageClasses`, `CVQualifiers` out of `Type` into their own headers 39 57 * Made `BFCommon` a `MakeBitfield` macro in its own header 40 58 * added default and field-init constructors to macro … … 70 88 * `Initializer` => `ast::Init` 71 89 * `Statement` => `ast::Stmt` 90 * any field names should follow a similar renaming 72 91 * because they don't really belong to `Type` (and for consistency with `Linkage::Spec`): 73 92 * `Type::StorageClasses` => `ast::Storage::Classes` 74 93 * `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` 75 99 * `LinkageSpec::Spec` => `ast::Linkage::Spec` 76 100 * `LinkageSpec::Mangle` etc. => `ast::Linkage::Mangle` etc. … … 79 103 * `LinkageSpec::isMangled(Spec)` etc. => `Spec.is_mangled` etc. 80 104 * `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 write 108 * suggest naming all flag enums `FooFlag` to hint at boolean nature 81 109 82 110 ## Specific Nodes ## … … 96 124 * allows `newObject` as just default settings 97 125 126 `NamedTypeDecl` 127 * `parameters` => `params` 128 98 129 `TypeDecl` 99 * stripped `isComplete()` accessor in favour of direct access to `sized` 130 * moved `TypeDecl::Kind` to `ast::TypeVar::Kind` 131 132 `AggregateDecl` 133 * `parameters` => `params` 100 134 101 135 `EnumDecl` … … 105 139 * Merged `inferParams`/`resnSlots` into union, as suggested by comment in old version 106 140 * does imply get_/set_ API, and some care about moving backward 141 * added constructor that sets result, for benefit of types that set it directly 142 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 constructor 152 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 uses 157 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 }` 107 170 108 171 `Label` … … 129 192 * **TODO** port copy operator 130 193 * Needs to be an almost-shallow clone, where the declarations are cloned only if needed 131 * **TODO** port DeclReplacer194 * **TODO** port `DeclReplacer` 132 195 * Still a `std::list` for children, rather than `std::vector` 133 196 * allows more-efficient splicing for purposes of later code generation 134 197 135 198 `Type` 199 * `CV::Qualifiers` moved to end of constructor parameter list, defaulted to `{}` 200 * removed getter, setter in favour of public `qualifiers` field 201 * `ReferenceToType` puts a defaulted list of attributes after qualifiers 136 202 * `forall` field split off into `ParameterizedType` subclass 137 203 * any type that needs it can inherit from `ParameterizedType` 204 * currently `FunctionType`, `ReferenceToType` 138 205 * `get_qualifiers()` replaced with accessor `qualifiers()` and mutator `set_qualifiers()` 139 * `get_CV()` replaced with `is_CV()` variants 206 * `get_const()` etc. replaced with `is_const()` etc. variants 207 * `referenceDepth()` now returns `unsigned` rather than `int` 140 208 * A number of features only supported on aggregates pushed down to `ReferenceToType`: 141 209 * `attributes`: per docs [1] GCC only supports type attributes on aggregates and typedefs 142 210 * suggest adding a `TypeWithAttributes` wrapper type if this proves insufficient 143 * `getAggr()` 144 * `genericSubstitution()` 211 * `getAggr()` => `aggr()` 212 * also now returns `const AggregateDecl *` 213 * `genericSubstitution()` moved to own visitor in `AST/GenericSubstitution.hpp` **TODO** write 145 214 146 215 `BasicType` 147 * does not inherit from `Type` to allow pointer inlining148 * moved `Kind` before qualifiers in constructor to allow for default149 216 * **TODO** move `kind`, `typeNames` into code generator 150 217 218 `ReferenceToType` 219 * deleted `get_baseParameters()` from children 220 * replace with `aggr() ? aggr()->params : nullptr` 221 * `parameters` => `params` 222 * hoisted `lookup` implementation into parent, made non-virtual 223 * also changed to return vector rather than filling; change back if any great win for reuse 224 * `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 error 244 * if readded, should be `const Type *` 245 246 `AttrType` 247 * did not port due to deprecation of feature 248 * feature is `type@thing` e.g. `int@MAX` 249 151 250 [1] https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Type-Attributes.html#Type-Attributes 152 251
Note: See TracChangeset
for help on using the changeset viewer.