tlang/source/tlang/testing/meta/sizeof.t

8 lines
156 B
Perl
Raw Normal View History

🧠 Feature: Meta-programming engine (#10) * Parser - Added new interface `Cloneable` * Symbols - Added new `Statement`-based type: `Macro` to support `Macro`(s) * MetaProcessor - Added the `MetaProcessor` TypeChecker - Added the `MetaProcessor` instance to the `TypeChecker`, it will be instantiated upon the `TypeChecker`'s construction and later have its `.process()` method called as the first call in `beginCheck()` * TypedEntity - Added a `setType(string)` method to update the internal `type` field * MetaProcessor - Added a type-re-writing facility via `typeRewrite(TypedEntity)` which will re-write the types such as `size_t`, `ssize_t` and so forth Test cases - Added a test case `meta/types.t` which tests this * MetaProcessor - Updated the constructor to only take in an instance of the `TypeChecker` - Updated the `process()` method to take in a `Container` such that it can be used recursively - Commented code - Added a recursive call to `process(Container)` when `curStmt` is a kind-of `Container` (this ensures that we reach the `VariableParameter`s of `Function` (die to them making up the `Statement[]` of `Function` type) - Removed unused `cmp` import `std.string` - Added type-rewrite for `ssize_t` -> `long` TypeChecker - Updated the constructor call to `MetaProcessor` to use its new API - Updated call to `process()` to now be `process(modulle)` Test cases - Updated `types.t` to test re-writing of the `Function`'s parameters * MetaProcessor - Added another FIXME * Mcro - Added interface `MTypeRewritable` to represent any AST node which has a `setType(string)` and `string getType()` method for rewriting- Added `Sizeof` which is a kind-of `IntegerLiteral` Data - Made `TypedEntity` implement the `MTypeRewritable` interface Expressions - Made `IntegerLiteral` non-final such that we can inherit from it - Added a final `setNumber(string)` method to `NumberLiteral` to update the literal MetaProcessor - The type rewriting mechanism now operates on `MTypeRewritable` AST nodes - Work has begun on `sizeOf_Literalize(Sizeof)` which is to determine the `Type` of the `Sizeof` statement and then calculate the memory width and update its literal (as it is a kind-of `NunberLiteral`) to said size Test cases - Added `meta/sizeof.t` to test `sizeof` functionality * Mcro - Added interface type `MStatementSearchable` * Mcro - Redefined `MStatementSearchable` - Added `MStatementReplaceable` - Added `Repr` (a kind-of `Expression`) which will be used as an example to test out the aforementioned two interfaces * MStatementSearchable - Added method `search(TypeInfo_Class clazzType)` which uses a `TypeInfo_Class` to search for all types matching that (and which are sub-types of `Statement` and then adds these to a list and returns it in the form of `Statement[]` * MStatementReplaceable - Implemented `replace(Statement thiz, Statement that)` which replaces the `Statement` in the first argument with that of the `Statement` in the second argument * MStatementSearchable - Added documentation for `search(TypeInfo_Class)` method * Mcro - Made `Repr` implement `MStatementSearchable` - Added new interface `MCloneable` to represent PNode's which are deeply-cloneable * Data - Made `DiscardStatement` searchabe via implementing `MStatementSearchable` - Added a stub override for implementing `MStatementReplaceable` in `DiscardStatement` * Mcro - Updated `MStatementReplaceable` to have its `replace(Statement, Statement)` method return a boolean `true` if the replacement was successful, else `false` * Parsing - Added the ability to parse a `Repr` statement Check - Added `GENERIC_TYPE_DECLARE` and `REPR` as new `SymbolType`(s) Data - `DiscardStatement` now implements the `bool replace(Statement, Statement)` method MetaProcessor - Added the ability to replace statements that occur within any _other_ statements which implement `MStatementSearchable` and `MStatementReplaceable` Test cases - Added `meta/simple_meta_replace.t` to test all of this Diagrams - Added diagram on how the meta system works * MetaProcessor - Removed unused `replace` method * MetaProcessor - Accept a new argument to the `MetaProcessor(TypeChecker)` constructor indicating whether or not the `MetaProcessor` is enabled or not TypeChecker - Enable the `MetaProcessor` * Mcro - Removed `Sizeof`, we will let it be parsed as a normal `FunctionCall` and then inspect in `MetaProcessor` * MetaProcessor - Disabled `sizeOf_Literalize` for now - Search for all `FunctionCall` statements in `process(Container)` * MetaProcessor - Removed old code for testing `MStatementSearchable` and `MStatementReplaceable` - Added note that we will have to investigate a recursive `MTypeRewritable` to be able to support things like `sizeof(size_t)` - Implemented module-level `sizeof(<ident_type>)` support - Added `Number`-kind of types support to `sizeOf_Literalize`(string)` Containers (`Module`) - Added `MStatementSearchable` and `MStatementReplaceable` support to `Module` container type Data - Added `MStatementSearchable` and `MStatementReplaceable` support to `Variable` - Added `MStatementSearchable` and `MStatementReplaceable` support to `VariableAssignment` - Work-in-progress for adding `MStatementSearchable` and `MStatementReplaceable` support to `FunctionCall` - Added a note to return `false` in `DiscardStatement` if the statement to be replaced is us (the `DiscardSTatement`) ourselves Test cases - Updated the `meta/sizeof.t` test case * Containers - Inherit from `MStatementSearchable` and `MStatementReplaceable` - Removed direct interface inheritance of `MStatementSearchable, MStatementReplaceable` and `MStatementReplaceable`, rely on `Container` now * Struct - Implemented the `search` method for `MStatementSearchable` - Implemented the `replace` method for `MStatementReplaceable` Clazz - Implemented the `search` method for `MStatementSearchable` - Implemented the `replace` method for `MStatementReplaceable` BinaryOperatorExpression - Implemented the `search` method for `MStatementSearchable` - Implemented the `replace` method for `MStatementReplaceable` Function - Implemented the `search` method for `MStatementSearchable` - Implemented the `replace` method for `MStatementReplaceable` Variable - Fixed the `replace` method implementation which had a bug that would never replace the node `VariableAssignment` inside of it VariableAssignmentStdAlone - Implemented the `search` method for `MStatementSearchable` - Implemented the `replace` method for `MStatementReplaceable` IfStatement - Implemented the `search` method for `MStatementSearchable` - Implemented the `replace` method for `MStatementReplaceable` WhileLoop - Implemented the `search` method for `MStatementSearchable` - Implemented the `replace` method for `MStatementReplaceable` ForLoop - Implemented the `search` method for `MStatementSearchable` - Implemented the `replace` method for `MStatementReplaceable` Branch - Implemented the `search` method for `MStatementSearchable` - Implemented the `replace` method for `MStatementReplaceable` * MetaProcessor - Added a future TODO for occurence of certain types that are alises (i.e. `size_t` appearing in a expression context like `sizeof(size_t)` - Now that all `Container`-based types are `MStatementReplaceable` we no longer need this check * MetaProcessor - Removed `break` which caused only one `sizeof()` function call to be replaced, we should have been looping over each `FunctionCall` found with `search` and then replacing ech that had a name of `sizeof` with a `NumberLiteral` expression - Moved all type alias replacement code into a new method; `doTypeAlias(Container, Statement)` - Added some rudiementary support for replacing any `IdentExpression` containing `size_t` with `uint` IdentExpression - Made it `MStatementSearchable` and `MStatementReplaceable` Test cases - Updated test case `meta/sizeof.t` to test the `sizeof(<expr>)` AST node in the `MetaProcessor` Documentation - Added diagram showing the `MStatementSearchable` and `MStatementReplaceable` in action * Compiler - If the T compiler was built on `X86` then set the maximum width to 4 bytes - If the T compiler was built on `X86_64` then set the maximum width to 8 bytes - Pass in the `Compiler` instance to the `TypeChecker` in `doTypeCheck()` TypeChecker - Added `Compiler` field and now accept it in constructor - If just single parameter constructor then pass in `null` as the `Compiler` instance - Added `getCompiler()` to get the instance MetaProcessor - Extract the `CompilerConfiguration` via the `TypeChecker`'s `getCompiler()` - Implemented `getSystemType(string)` which will map `size_t`/`ssize_t` to the correct maximum width'd type your system supports via the `types:max_width` config entry * CompilerConfiguration - Added `defaultConfig()` * Compiler - Removed `defaultConfig()` - During construction call `CompilerConfiguration.defaultConfig()` in order to generate the default config - Pass the config into `TypeChecker` in `doTypeCheck()` * TypeChecker - No longer store a field for the `Compiler` but rather store a field for the `CompilerConfiguration` - Removed single parameter constructor for `TypeChecker` - Constructor now uses the default `CompilerConfiguration` if not specified; therefore fixing the issue with unit tests failing MetaProcessor - Extract the compiler configuration via `tc.getConfig()` - Updated `typeRewrite(MTypeRewritable)` to use `getSystemType(string)` to lookup concrete types for `size_t`/`ssize_t` - `doTypeAlias(Container, Statement)` now uses `getSsstemType(string)` to lookup the concrete types for alises such as `size_t`/`ssize_t` * MetaProcessor - Implemented `isSystemType(string)` which returns `true` if the provided type is a system type alias (such as `size_t` or `ssize_t`), `false` otherwise * MetaProcessor - Implemented `isTypeAlias(string)` which determines if the given type is a type alias. - Implemented `getConcreteType(string typeAlias)` which transforms the type alias into its concrete type; this method incorporates defensive programming in that it will only apply the transformation IF the provided type alias is infact a type alias, otherwise it performs an identity transformation and returns the "alias" untouched. * TypeChecker - Clean up * MetaProcessor - `doTypeAlias(Container, Statement)` now makes use of `isTypeAlias(string)` and `getConcreteType(string)` * - `typeRewrite(MTypeRewritable)` now makes use of `isTypeAlias(string)` and `getConcreteType(string)` * MetaProcessor - Cleaned up * MetaProcessor - Removed unused import * MetaProcessor - Removed now-completed TODO * MetaProcessor - Updated comment before call to `doTypeAlias(Container, Statement)` * Containers - `Module` now applies re-parenting in its `replace()` - `Struct` now applies re-parenting in its `replace()` - `Clazz` now applies re-parenting in its `replace()` Data - `Function` now applies re-parenting in its `replace()` * Test cases - Added `simple_template_type_def.t` for future test cases * - Updated `.gitignore` * Check - Removed `SymbolType.REPR` which was used for testing early versions of the `MetaProcessor` * Mcro - Removed `Repr` which was used for testing in the early stages of `MetaProcessor` * Check - Removed reference to `SymbolType.REPR` in checker * Parser - Removed reference to `SymbolType.REPR` and `Repr` which was used for testing the `MetaProcessor` in early stages
2023-05-29 15:02:28 +00:00
module meta_sizeof;
size_t myVar1 = sizeof(uint);
size_t myVar2 = sizeof(ubyte);
size_t myVar3 = sizeof(ushort)+1;
myVar3 = sizeof(ulong)+sizeof(size_t);