Commit Graph

1037 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire 788279c3dd Merge branch 'vardec_varass_dependency' into feature/unused_vars_detection 2024-04-01 21:53:12 +02:00
Tristan B. Velloza Kildaire b98fa1fd38 Merge branch 'vardec_varass_dependency' into feature/unused_vars_detection 2024-04-01 21:48:40 +02:00
Tristan B. Velloza Kildaire 7a2ea96140 Containers
- Added a TODO
2024-03-18 15:28:48 +02:00
Tristan B. Velloza Kildaire 48f078077b Container
- Documented
2024-03-18 15:05:17 +02:00
Tristan B. Velloza Kildaire 4424043ccb Parser
- Fixed the parsing of bodies of structs and classes. Previously they would call `parseName()` when hitting a `SymbolType.IDENT_NAME` however this would allow assignments and function calls, we don't want this. Switched to `parseTypedDeclaration()` + checking the symbol left in lexer after it (ensuring it was a semicolon) and then consuming it)
2024-02-29 19:41:38 +02:00
Tristan B. Velloza Kildaire df6dfe14d0
🧹🧼 Cleanup: Pool provider (#33)
* IPoolManager

- Added new interface

* Pool

- Added missing imports

* IPoolManager

- Moved to the `interfaces` module

* IPoolManager

- Updated API to take in a `DNodeGenerator` as the first argument to `pool(..., ...)`

* Revert "IPoolManager"

This reverts commit 4f92a29da2.

* PoolManager

- Added an implementation of the `IPoolManager` interface

* DNodeGenerator

- Now constructs a new `IPoolManager` on constructions

* IPoolManager

- Added a templatised variant of the `pool(Statement)` method

* PoolManager

- Added a templatised variant of the `pool(Statement)` method
- The `pool(Statement)` method now uses the `poolT!(DNodeType, EntityType)(EntityType)` method

* IPoolManager

- Removed the templatised `poolT!(DNodeType, EntityType)(EntityType)` method
- Added `poolExpression(Expression expression)`
- Added `poolVariable(Variable variable)`
- Added `poolStaticVariable(Variable variable)`
- Added `poolFuncDec(Function func)`

* IPoolManager

- Removed uneeded import

* PoolManager

- Removed the templatised `poolT!(DNodeType, EntityType)(EntityType)` method
- Implemented `poolExpression(Expression expression)`
- Implemented `poolVariable(Variable variable)`
- Implemented `poolStaticVariable(Variable variable)`
- Implemented `poolFuncDec(Function func)`

* ExpressionDNode

- No longer takes in a `DNodeGenerator`

AccessDNode

- No longer takes in a `DNodeGenerator`
- Save the incoming `Entity`
- Updated `initName()` to use the `toString()` of the `Entity`

ClassVirtualInit

- No longer takes in a `DNodeGenerator`
- Save the incoming `Clazz`
- Updated `initName()` to use the `toString()` of the `Clazz`

ClassStaticNode

- No longer takes in a `DNodeGenerator`
- Save the incoming `Clazz`
- Updated `initName()` to use the `toString()` of the `Clazz`

ObjectInitializationNode

- No longer takes in a `DNodeGenerator`

VariableNode

- No longer takes in a `DNodeGenerator`
- Updated `initName()` to use the `toString()` of the `Variable`

FuncDecNode

- No longer takes in a `DNodeGenerator`
- Updated `initName()` to use the `toString()` of the `Function`

ModuleVariableDeclaration

- No longer takes in a `DNodeGenerator`
- Updated `initName()` to use the `toString()` of the `Variable`

StaticVariableDeclaration

- No longer takes in a `DNodeGenerator`
- Updated `initName()` to use the `toString()` of the `Variable`

VariableAssignmentNode

- No longer takes in a `DNodeGenerator`
- Updated `initName()` to use the `toString()` of the `VariableAssignment`

* PoolManager

- No longer takes in a `DNodeGenerator` for its constructor
- We no longer require it
- No longer pass a `DNodeGenerator` to the `DNodeType(...)`s created in `poolT!(...)(...)`

PoolManager (unittests)

- Updated unittests

* Depencency (module)

- The `addFunctionDef(...)` method now takes in an extra first argument which is the `IPoolManager` it
should use when it constructs its `DFunctionInnerGenerator`

DNode

- Removed the `DNodeGenerator` instance (i.e. the `dnodegen` field)
- Removed the `Resolver` instance (i.e. the `resolver` field)
- Calling `pool(Statement entity)` will now forward that call to the `IPoolManager`'s `pool(Statement)`
- Calling `DNodeType poolT(DNodeType, EntityType)(EntityType entity)` will now forward that call to the `IPoolManager`'s `pool(Statement)` with the correct types decided at compile-time using static if's
- `objectInitialize(Clazz clazz, NewExpression newExpression)` now constructs a `ObjectInitializationNode` with
its new API
- `pool_module_vardec(Variable entity)` now constructs a `ModuleVariableDeclaration` with its new API
- When `generalStatement(Container c, Context context, Statement entity)` comes across a function definition
(i.e. a `Function`) and has to add its function definition it now uses the updated `addFunctionDef(...)`
- `poolClassStatic(Clazz clazz)` now constructs a `ClassStaticNode` with its new API

DFunctionInnerGenerator

- Constructor now accepts an `IPoolManager` instance

DNodeGenerator

- Constructor now accepts an `IPoolManager` instance
- We now use the `IPoolManager` as our pooling mechanism

* TypeChecker

- When we call `dependencyCheck()` we now first construct the pooling mechanism we want to use
by constructing some kind-of `IPoolManager`, we then pass this to the constructor for the
`DNodeGenerator`

* IPoolManager

- Added `poolModuleVariableDeclaration(Variable variable)`

* PoolManager

- Impemented `poolModuleVariableDeclaration(Variable variable)`

* DNodeGenerator

- `pool_module_vardec(Variable entity)` now calls `poolModuleVariableDeclaration(Variable)` from `IPoolManager`
- Removed the static `nodePool`

* IPoolManager

- Added some stuff

* IPoolManager

- Nah, removed that

* IPoolManager

- Added `poolClassStatic(Clazz clazz)`

* PoolManager

- Implemented `poolClassStatic(Clazz clazz)`

* DNodeGenerator

- Calling `poolClassStatic(Clazz clazz)` now calls `IPoolManager`'s `poolClassStatic(Clazz)`

* IPoolManager

- Documented module

* PoolManager

- Documented module

* Merge branch 'vardec_varass_dependency' into feature/poolmngr
2024-02-27 10:30:34 +02:00
Tristan B. Velloza Kildaire c55cd74596
🧹🧼 Cleanup: addFuncDef/clearFuncDefs should all use a non-static pool (#34)
* IFuncDefStore

- Added new interface

* FuncDefStore

- Implemented new `IFuncDefStore` type

* FuncDefStore

- The constructor now takes in a `TypeChecker` instance
- Implemented `addFunctionDef(Function func)`

* FuncDefStore

- Added a TODO + some code for a future naming setup I want to se

* IPoolManager

- Added documentation
- Added new method `grabFunctionDef(string name)` to the API

* FuncDefStoreException

- Added new exception type

* IPoolManager

- Added more docs for `grabFunctionDef(string name)`

* FuncDefStore

- Pass in ourselves (a `IFuncDefStore`) into the `DFunctionInnerGenerator` when adding a function definition
- Implemented `grabFunctionDef(string name)` from the updated `IFuncDefStore` API

* DNodeGenerator

- Constructor now takes in a `IFuncDefStore`
- When we encounter a `Function` we will add it to the store of function definitions
by using the new `IFuncDefStore` (instead of the old `addFunctionDef(TypeChecker, Function)`
- Removed unused method `saveFunctionDefinitionNode(DNode funcDefNode)`
- Removed unused method `retrieveFunctionDefinitionNode(string functionAbsolutePath)`
- Removed the old method `addFunctionDef(TypeChecker tc, Function func)` (as we are now using the `IFuncDefStore`)
- Removed the `clearFuncDefs()` as we are now using the `IFuncDefStore`
- Removed the `grabFunctionDefs()` as we are now using the `IFuncDefStore`
- Removed the `FunctionData[string]` as we are now using the `IFuncDefStore`

DFunctionInnerGenerator

- Constructor now takes in a `IFuncDefStore`

* TypeChecker

- `dependencyCheck()` no lomger calls the removed `clearFuncDefs()` from the `dependency.core` module
- `dependencyCheck()` now constructs a new `IFuncDefStore` and then passes it into the `DNodeGenerator`
when dependency generation needs to occur

* IFuncDefStore

- Added module-level documentation

* FuncDefStore

- Documented class
- Documented module

* FuncDefStoreException

- Documented constructor and class

* IFuncDefStore

- `addFunctionDef(Function func)` may now throw a `FuncDefStoreException` when you add a function that already exists

* FuncDefStore

- `addFunctionDef(Function func)` now throws a `FuncDefStoreException` when you provide a `Function` that has already been added

* IFuncDefStore

- Moved import to the top

* FuncDefStore

- Cleaned up
2024-02-27 09:33:18 +02:00
Tristan B. Velloza Kildaire ee537f2b25
Feature: Lexer improvements (#18)
* Created brsnch

* Created brsnch (removed placeholder)

* Lexer

- Added tab handling for the presence such as spaces would be in.
- Added unit tests for the new tab processing
- Resolved issues where whitepsace was allowed before and or after the
  '.' character
- Renamed isSpliter to isSplitter
- Some Code styling

* Check

- Added two new `SymbolType`s for comments
- `SINGLE_LINE_COMMENT` (for `//`) and `MULTI_LINE_COMMENT` (for `/*`)

* Parser

- Added a bogus `parseComment()` which returns nothing, prints out the comment, consumes the `Token` and returns
- `parseStatement()` now supports `parseComment()` whenever a single-line or multi-line comment is detected

* Parser

- Fixed token consumption code in `parseComment()`

* BasicLexer

- Fixed style mishaps

* ArrLexer

- Implemented dummy lexer

* Parser

- Added some comment related functions (for testing)
- Added `pushComment(Token)`, `hasCommentsOnStack() and `getCommentCount()`
- `parseComment()` now pushes the current comment-based `Token` onto the comment-stack
- Added a comment stack

Unit tests

- Added testing for various examples of comment-type `Token`s

* Lexer
- Replaced the characters with Enumerated type
- Working Comment lexing, single and multiline
- Working escape codes for strings
- Working Signage and Size Encoder indicators

- Removed floatMode in favour of float lexing function
- Added doComment for the comment lexing instead of comment mode
- Added doEscapeCode for escape codes in string

Testing
- Added unit tests for comments
- Added unit tests numerical encoders
- Added unit tests numerical encoders

TODO
- ADD unit tests for all valid escape sequences and some invalid

* Lexer
- Removed stringMode in favour of soString

TODO
- Decide on miltiline strings, currently not supported

* Parser

- Test comments which appear at a non-Module but rather statement lavel

* Parser

- Changed to using `BasicLexer` for comment tests now seeing as it is now implemented therein

* Basic

- Added `roll()` and `shourt()` to mark unittests

* Basic

- `shout()` now adds line number to print out

* Lexer rewrite
- flush
- underscores in numbers
- escape codes
- character escapes
- bug fixes

* Basic

- Fixed `shourt(int)`

* Basic

- Remved crashing (on purpose_ unittest

* Resolved bug where isSplitter evaluated to true every time

* Basic

- Removed `goggaWithLineInfo(...)`

* Basic

- Updated `shout()` to remove rolling
- Removed `roll()`
- Added function and module name as well

* Basic

- Documented `shout()`

* Lexer Done and 100% coverage

* LexerSymbols

- Documented
- Formatted

* Lexer (module)

- Added `LS` alias
- Added `isOperator(char c)`, `isSplitter(char c)`, `isNumericalEncoder_Size(char character)`, `isNumericalEncoder_Signage(char character)` and `isValidEscape_String(char character)`

* BasicLexer

- Documented constructor `hasToken()`, `performLex()`, `doIdentOrPath()`, `doChar()`, `doString()`, `doComment()`, `doEscapeCode()`, `doNumber()`, `doEncoder()`, `doFloat()`, `flush()`, `buildAdvance()`, `improvedAdvance()`, `advanceLine()`, `isOperator(char)`, `isSplitter(char)`, `isValidDotPrecede(char character)`, `isNumericalEncoder(char character)`, `isNumericalEncoder_Size(char character)`, `isNumericalEncoder_Signage(char character)` and `isValidEscape_String(char character)`
- Tried reformatting some of `doChar()`, `doString()`, `flush()`, `buildAdvance()`, `improvedAdvance()`, `advanceLine()`, `isOperator(char)`, `isSplitter(char)`

* Basic

- Removed `LS` alias

Lexer

- Made `LS` alias public

* BasicLexer

- Removed methods `isValidEscape_String(char character)`, `isNumericalEncoder_Signage(char character)`, `isNumericalEncoder_Size(char character)`, `isNumericalEncoder(char character)`, `isSplitter(char c)` and ` isOperator(char c)`

Lexer

- Added method `isNumericalEncoder(char character)`

* BasicLexer

- Documented `isValidDotPrecede(char character)`

* Lexer

- Added method `isValidDotPrecede(char character)`

* BasicLexer

- Removed method `isValidDotPrecede(char character)`

* BasicLexer (unittests)

- Documented the unittests
- Fixed formatting

* BasicLexer

- Typo fixes

* BasicLexer (unittests)

- Only compile-in `shourt(...)` when in unittest build mode

* BasicLexer

- Documented `isForward()` and `isBackward()`
- Made `isBackward()` private

---------

Co-authored-by: GMeyer <21568499@sun.ac.za>
Co-authored-by: GMeyer <gustav.meyer1999@gmail.com>
2023-12-27 08:18:17 +02:00
Tristan B. Velloza Kildaire 4c3a72b026 Pipelines
- Run `apt update` before doing an `apt install`
2023-12-08 18:27:42 +02:00
Tristan B. Velloza Kildaire 48fe528922 TypeChecker
- Fixed message which prints out when an unused variable is detected
2023-11-05 21:30:17 +02:00
Tristan B. Velloza Kildaire 4aaaaf03ec Pipelines
- Added tests for `unused_vars.t` and `unused_vars_none.t`
2023-11-05 21:27:15 +02:00
Tristan B. Velloza Kildaire ecc07a013b TypeChecker (unittests)
- Added a negative test case for the unused variables detection mechanism
2023-11-05 16:37:41 +02:00
Tristan B. Velloza Kildaire 54ce4be447 TypeChecker (unittests)
- Check the variable is equal to the one we are looking for (`j`)
2023-11-05 16:35:57 +02:00
Tristan B. Velloza Kildaire 89ad16ecde TypeChecker (unittests)
- Added a positive test case unittest for the unused variables detection mechanism
2023-11-05 16:34:20 +02:00
Tristan B. Velloza Kildaire ade7f1ba84 Compiler
- Made `gibFileData(string sourceFile)` public
- Added `getTypeChecker()` to the `Compiler` class
2023-11-05 16:33:16 +02:00
Tristan B. Velloza Kildaire b29be46675 TypeChecker
- Use `getName()` on the `Variable` when printing out the names of unused variables
2023-11-05 16:26:00 +02:00
Tristan B. Velloza Kildaire eee9735345 Configuration
- `defaultConfig()` now adds an entry for `typecheck:warnUnusedVars` set to `true`
2023-11-04 22:57:31 +02:00
Tristan B. Velloza Kildaire aa1849e4bc TypeChecker
- Added `doPostChecks()`
- Moved the reference counting code to `doPostChecks()`
2023-11-04 15:51:26 +02:00
Tristan B. Velloza Kildaire 9f466505fa TypeChecker
- We now respect the `typecheck:warnUnusedVars` option
2023-11-04 13:57:29 +02:00
Tristan B. Velloza Kildaire e3e2fbd442 Commands
- Added commands to `TypeCheckerBase!()` mixin template
- Added `TypeCheckerInit(Compiler compiler)`
- Use the template in both `compile` command and the`typecheck` command
2023-11-04 13:56:02 +02:00
Tristan B. Velloza Kildaire 2d90d01175 TypeChecker
- Moved the reference counting mechanism into the `TypeChecker` to avoid problem of seperate `DNodeGenerator` instances having their own seperate counts
- We now check the reference count values after function definition processing so as to get a proper count

Dependency

- Use the reference counting from `TypeChecker`
- Removed reference counting code

Test cases

- Added a positive case in the form of `unused_vars.t`
- Added a negative case in the form of `unused_vars_none.t`
2023-11-04 13:13:33 +02:00
Tristan B. Velloza Kildaire 94555a3770 Dependency
- Added `getUnusedVariables()` which returns all variables which were declared but not used
2023-11-03 22:16:24 +02:00
Tristan B. Velloza Kildaire 36c29f104e Dependency
- VAriables that appear in expressions must increase the ref count
2023-11-03 22:10:58 +02:00
Tristan B. Velloza Kildaire 39042e4fa6 Dependency
- Make variable declaration count as the first reference
2023-11-03 22:05:06 +02:00
Tristan B. Velloza Kildaire 064557644d Dependency
- When handling a standalone assignment to a variable increment it's reference count
- This was updated in the handling of `VariableAssignmentStdAlone`
2023-11-03 21:58:23 +02:00
Tristan B. Velloza Kildaire 32c71f93b1 Dependency
- Added `varRefCounts` which maps a given `Variable` to its reference count. This includes the declaration thereof.
- Added `touch(Variable variable)` which Increments the given variable's reference count
2023-11-03 21:55:09 +02:00
Tristan B. Velloza Kildaire 472ca36141 Pipelines
- Cleaned up
2023-09-24 18:10:18 +02:00
Tristan B. Velloza Kildaire c40cecf077 Pipelines
- Wrap in `""`
2023-09-24 18:07:46 +02:00
Tristan B. Velloza Kildaire 52d04de0b2 Pipelines
- Try this
2023-09-24 18:06:47 +02:00
Tristan B. Velloza Kildaire 202d7988d4 Pipelines
- Does this even work?
2023-09-24 18:05:18 +02:00
Tristan B. Velloza Kildaire c681206cef Pipelines
- Manually specify branches to run on for pull requests
2023-09-24 18:04:18 +02:00
Tristan B. Velloza Kildaire efb093319f Pipelines
- Try get builds to ALWAYS run on ANY branch AND for any pull requests
2023-09-24 18:03:22 +02:00
Tristan B. Velloza Kildaire e878ad4c90
Try fix Coveralls 2023-09-02 19:55:53 +02:00
Tristan B. Velloza Kildaire e1d034cbe0
🐞️ Bugfix: Module-level static members may cause consecutive compilation errors (#30)
* Compiler

- Re-enabled compilation tests (partially)

* Dependency

- Fixed comment
- Implemented `clearFuncDefs()`

* TypeChecker

- Clear the `FunctionData[string]` table after a batch of typechecking/codegen such that we don't have lingering data from previous compilations which gets reliniearzed resulting in an exception being thrown as it was marked as linearized from its first time from a previous compilation

* Compiler

- Re-enabled unit tests for compilation
- Added TODO relating to adding failing test cases as well

* Compiler

- Added unit test for failing tests

* TypeCheck

- Use a scopre guard to call `clearFuncDefs()` such that it is called even when exceptions are thrown during depgen, typecheck/codegen ensuring we have it cleared for the next run

* Compiler

- Added `gibeFileData(string)` to easily read the source text
- Added all `typecheck` (good and bad) tests

* Pipelines

- Updated name

* Compiler (unittests)

- Re-ordered the test cases
- Commented them out

* Compiler

- Added documentation for `gibFileData(string)`
- Made `gibFileData(string)` private

* Compiler (unit tests)

- Documented unit test

* Compiler

- Cleaned up imports

* Compiler (unit tests)

- Added TODO
- Added spacing
2023-08-27 12:53:18 +02:00
Tristan B. Velloza Kildaire 16caf6ebec
Update d.yml 2023-08-21 14:57:12 +02:00
Tristan B. Velloza Kildaire f62ec5667f
Update README.md 2023-08-21 14:41:22 +02:00
Tristan B. Velloza Kildaire 8831ea51de
Update d.yml 2023-08-21 14:38:19 +02:00
Tristan B. Velloza Kildaire a60ce2a66f
Update d.yml 2023-08-21 14:36:07 +02:00
Tristan B. Velloza Kildaire e66b7750ab
Update d.yml 2023-08-21 14:33:58 +02:00
Tristan B. Velloza Kildaire ef9a461de2
Update d.yml 2023-08-21 14:33:12 +02:00
Tristan B. Velloza Kildaire 706d5053db
Update d.yml 2023-08-21 14:30:20 +02:00
Tristan B. Velloza Kildaire a8e3dae81f
Update d.yml 2023-08-21 14:25:38 +02:00
Tristan B. Velloza Kildaire 1b9b688337
Update d.yml 2023-08-21 14:23:20 +02:00
Tristan B. Velloza Kildaire 8201718774
Update d.yml 2023-08-21 14:22:04 +02:00
Tristan B. Velloza Kildaire 2417a5afe8
Update d.yml 2023-08-21 14:20:15 +02:00
Tristan B. Velloza Kildaire 3cf280d128
Update d.yml 2023-08-21 14:18:19 +02:00
Tristan B. Velloza Kildaire d226cdf761
Update d.yml 2023-08-21 14:17:03 +02:00
Tristan B. Velloza Kildaire caaf5ff4c4
Update d.yml 2023-08-21 14:14:55 +02:00
Tristan B. Velloza Kildaire 02fe3347eb
Update d.yml 2023-08-21 14:12:32 +02:00
Tristan B. Velloza Kildaire f7a8631729
Update d.yml 2023-08-21 14:10:50 +02:00