MetaProcessor

- Added remaining methods for the `MetaProcessor`
- Added information about the usage of `getConcreteType(string)` in the "Type alias replacement" section
This commit is contained in:
Tristan B. Velloza Kildaire 2023-07-09 20:58:37 +02:00
parent 15862f4443
commit a09536cdce
2 changed files with 20 additions and 11 deletions

View File

@ -89,10 +89,15 @@ is just the original program.
TODO: Document me
| Method name | Return type | Description |
|----------------------------------------------|-------------|----------------------------------------------------------------------------|
| `process(Container)` | `void` | Processes the various types of meta statements in the provided `Container` |
| `doTypeAlias( Container, Statement)` | `void` | Performs the replacement of type aliases such as `size_t`, `ssize_t` |
| Method name | Return type | Description |
|----------------------------------------------|-------------|-------------------------------------------------------------------------------------------------------------------------|
| `process(Container)` | `void` | Processes the various types of meta statements in the provided `Container` |
| `doTypeAlias( Container, Statement)` | `void` | Performs the replacement of type aliases such as `size_t`, `ssize_t` |
| `typeRewrite( MTypeRewritable)` | `void` | Updates any type fields in `TypedEntity`s (these are the only ones really implementing the `MTypeRewritable` interface) |
| `getConcreteType( string)` | `string` | Given an assumed type alias this will try resolve it to its concrete type |
| `isTypeAlias(string)` | `bool` | Given an assumed type alias this checks if it is a type alias |
| `isSystemType(string)` | `bool` | Checks if the given type is a system alias (so, is it `size_t`/`ssize_t`) |
| `getSystemType(string)` | `string` | Resolves `size_t`/`ssize_t` to their concrete types using the `CompilerConfig` |
#### AST processing
@ -134,3 +139,5 @@ This does two checks:
would be that of `size_t` within the argument to `sizeof(...)`.
- We can then replace the `IdentExpression` there with one referring
to the concrete type
- The concrete type is retrieved by calling
`getConcreteType(string)` (with `"size_t"` in this case)

View File

@ -69,18 +69,19 @@ TODO: Add an example of it being used here please
The `MetaProcessor` is the actual processing facility which can apply different types of AST manipulations to a given `Container`. It is run prior to type checking but after parsing. This makes sense as we want to do AST node manipulation _just_ after the parse tree has been constructed, then we can pass the changed program to the `TypeChecker` and it wouldn't know any different. For all the type checker knows, this is just the original program.
TODO: Document me
| Method name | Return type | Description |
|---------------------------------------|--------------|----------------------------------------------------------------------------------|
| `process(Container)` | `void` | Processes the various types of meta statements in the provided `Container` |
| `doTypeAlias(
Container,
Statement)` | `void` | Performs the replacement of type aliases such as `size_t`, `ssize_t` |
| `typeRewrite(
MTypeRewritable)` | `void` | Updates any type fields in `TypedEntity`s (these are the only ones really implementing the `MTypeRewritable` interface) |
| `getConcreteType(
string)` | `string` | Given an assumed type alias this will try resolve it to its concrete type |
| `isTypeAlias(string)` | `bool` | Given an assumed type alias this checks if it is a type alias |
| `isSystemType(string)` | `bool` | Checks if the given type is a system alias (so, is it `size_t`/`ssize_t`) |
| `getSystemType(string)` | `string` | Resolves `size_t`/`ssize_t` to their concrete types using the `CompilerConfig` |
#### AST processing
@ -108,4 +109,5 @@ This does two checks:
* This means that the statement can be **searched** and have parts of it **replaced**
* A search is normally done via the `Container`, however, for any AST node of type `IdentExpression`
* We search for `IdentExpression` because, for example if you have `1+sizeof(size_t)`, then the identity expression (named variable) would be that of `size_t` within the argument to `sizeof(...)`.
* We can then replace the `IdentExpression` there with one referring to the concrete type
* We can then replace the `IdentExpression` there with one referring to the concrete type
* The concrete type is retrieved by calling `getConcreteType(string)` (with `"size_t"` in this case)