🧹️🧼 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
feature/container_methods
parent
c55cd74596
commit
df6dfe14d0
@ -0,0 +1,216 @@
|
||||
/**
|
||||
* Implementation of the `IPoolManager`
|
||||
* interface
|
||||
*/
|
||||
module tlang.compiler.typecheck.dependency.pool.impls;
|
||||
|
||||
import tlang.compiler.typecheck.dependency.pool.interfaces;
|
||||
import tlang.compiler.typecheck.dependency.core : DNode, DNodeGenerator;
|
||||
import tlang.compiler.typecheck.dependency.expression : ExpressionDNode;
|
||||
import tlang.compiler.typecheck.dependency.variables : VariableNode, FuncDecNode, StaticVariableDeclaration, ModuleVariableDeclaration;
|
||||
import tlang.compiler.typecheck.dependency.classes.classStaticDep : ClassStaticNode;
|
||||
import tlang.compiler.symbols.data : Statement, Expression, Variable, Function, Clazz;
|
||||
import std.traits : isAssignable;
|
||||
|
||||
/**
|
||||
* Provides an implementation of
|
||||
* the `IPoolManager` interface
|
||||
* such that you can use this
|
||||
* as part of the dependency
|
||||
* generation process
|
||||
*/
|
||||
public final class PoolManager : IPoolManager
|
||||
{
|
||||
/**
|
||||
* The pool itself
|
||||
*/
|
||||
private DNode[] nodePool;
|
||||
|
||||
/**
|
||||
* Constructs a new pooling manager
|
||||
*/
|
||||
this()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Pools the provided AST node
|
||||
* to a dependency node, creating
|
||||
* one if one did not yet exist
|
||||
*
|
||||
* Params:
|
||||
* statement = the AST node
|
||||
* Returns: the dependency node
|
||||
*/
|
||||
public DNode pool(Statement statement)
|
||||
{
|
||||
return poolT!(DNode, Statement)(statement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pools the provided `Clazz`
|
||||
* AST node but with an additional
|
||||
* check that it should match
|
||||
* against a `ClassStaticNode`
|
||||
* and if one does not exist
|
||||
* then one such dependency
|
||||
* node should be created
|
||||
*
|
||||
* Params:
|
||||
* clazz = the class to statcally
|
||||
* pool
|
||||
* Returns: the pooled `ClassStaticNode`
|
||||
*/
|
||||
public ClassStaticNode poolClassStatic(Clazz clazz)
|
||||
{
|
||||
foreach(DNode dnode; nodePool)
|
||||
{
|
||||
Statement entity = dnode.getEntity();
|
||||
if(entity == clazz && cast(ClassStaticNode)dnode)
|
||||
{
|
||||
return cast(ClassStaticNode)dnode;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If no DNode is found that is associated with
|
||||
* the provided Entity then create a new one and
|
||||
* pool it
|
||||
*/
|
||||
ClassStaticNode newDNode = new ClassStaticNode(clazz);
|
||||
nodePool ~= newDNode;
|
||||
|
||||
return newDNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pools the provided `Expression`
|
||||
* AST node into an `ExpressionDNode`
|
||||
*
|
||||
* Params:
|
||||
* expression = the AST node
|
||||
* Returns: the pooled `ExpressionDNode`
|
||||
*/
|
||||
public ExpressionDNode poolExpression(Expression expression)
|
||||
{
|
||||
return poolT!(ExpressionDNode, Expression)(expression);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pools the provided `Variable`
|
||||
* AST node into a `VariableNode`
|
||||
*
|
||||
* Params:
|
||||
* variable = the AST node
|
||||
* Returns: the pooled `VariableNode`
|
||||
*/
|
||||
public VariableNode poolVariable(Variable variable)
|
||||
{
|
||||
return poolT!(VariableNode, Variable)(variable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pools the provided `Variable`
|
||||
* AST node into a `StaticVariableDeclaration`
|
||||
*
|
||||
* Params:
|
||||
* variable = the AST node
|
||||
* Returns: the pooled `StaticVariableDeclaration`
|
||||
*/
|
||||
public StaticVariableDeclaration poolStaticVariable(Variable variable)
|
||||
{
|
||||
return poolT!(StaticVariableDeclaration, Variable)(variable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pools the provided `Variable`
|
||||
* AST node into a `ModuleVariableDeclaration`
|
||||
*
|
||||
* Params:
|
||||
* variable = the AST node
|
||||
* Returns: the pooled `ModuleVariableDeclaration`
|
||||
*/
|
||||
public ModuleVariableDeclaration poolModuleVariableDeclaration(Variable variable)
|
||||
{
|
||||
return poolT!(ModuleVariableDeclaration, Variable)(variable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pools the provided `Function`
|
||||
* AST node into a `FuncDecNode`
|
||||
*
|
||||
* Params:
|
||||
* func = the AST node
|
||||
* Returns: the pooled `FUncDecNode`
|
||||
*/
|
||||
public FuncDecNode poolFuncDec(Function func)
|
||||
{
|
||||
return poolT!(FuncDecNode, Function)(func);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pools the provided AST node
|
||||
* to a dependency node, creating
|
||||
* one if one did not yet exist.
|
||||
*
|
||||
* This is a templatised version
|
||||
* which lets you specify the
|
||||
* kind-of `DNode` to be constructed
|
||||
* (if it does not yet exist) and
|
||||
* the incoming type of AST node.
|
||||
*
|
||||
* Params:
|
||||
* entity = the AST node
|
||||
* Returns: the dependency node
|
||||
*/
|
||||
public DNodeType poolT(DNodeType, EntityType)(EntityType entity)
|
||||
if(isAssignable!(DNode, DNodeType))
|
||||
{
|
||||
foreach(DNode dnode; nodePool)
|
||||
{
|
||||
if(dnode.getEntity() == entity)
|
||||
{
|
||||
return cast(DNodeType)dnode;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If no DNode is found that is associated with
|
||||
* the provided Entity then create a new one and
|
||||
* pool it
|
||||
*/
|
||||
DNodeType newDNode = new DNodeType(entity);
|
||||
nodePool ~= newDNode;
|
||||
|
||||
return newDNode;
|
||||
}
|
||||
}
|
||||
|
||||
version(unittest)
|
||||
{
|
||||
import tlang.compiler.symbols.data : Module, Variable;
|
||||
import tlang.compiler.typecheck.core : TypeChecker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the pooling of AST nodes
|
||||
* to dependency nodes using the
|
||||
* `PoolManager` implementation
|
||||
*/
|
||||
unittest
|
||||
{
|
||||
// Create bogus module and type checker
|
||||
Module testModule = new Module("myModule");
|
||||
TypeChecker tc = new TypeChecker(testModule);
|
||||
|
||||
// Create a pool manager
|
||||
IPoolManager pool = new PoolManager();
|
||||
|
||||
// Pool an AST node
|
||||
Variable astNode = new Variable("int", "age");
|
||||
DNode astDNode = pool.pool(astNode);
|
||||
|
||||
// Now pool it (again) and ensure it matches
|
||||
// the dependency node just created
|
||||
assert(astDNode is pool.pool(astNode));
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
/**
|
||||
* Defines interfaces for managing
|
||||
* the pooling of AST nodes to
|
||||
* dependency nodes which are to be
|
||||
* used within the dependency generator
|
||||
* and later the codegen/typechecker
|
||||
* which consumes these dependency
|
||||
* nodes
|
||||
*/
|
||||
module tlang.compiler.typecheck.dependency.pool.interfaces;
|
||||
|
||||
import tlang.compiler.typecheck.dependency.core : DNode;
|
||||
import tlang.compiler.typecheck.dependency.expression : ExpressionDNode;
|
||||
import tlang.compiler.typecheck.dependency.variables : VariableNode, FuncDecNode, StaticVariableDeclaration, ModuleVariableDeclaration;
|
||||
import tlang.compiler.typecheck.dependency.classes.classStaticDep : ClassStaticNode;
|
||||
import tlang.compiler.symbols.data : Statement, Expression, Variable, Function, Clazz;
|
||||
|
||||
// TODO: In future if we do not require the specific `ExpressionDNode` et al
|
||||
// ... then remove them from the interface definition below
|
||||
|
||||
/**
|
||||
* Defines an interface by which
|
||||
* `Statement`s (i.e. AST nodes)
|
||||
* can be mapped to a `DNode`
|
||||
* and if one does not exist
|
||||
* then it is created on the
|
||||
* first use
|
||||
*/
|
||||
public interface IPoolManager
|
||||
{
|
||||
/**
|
||||
* Pools the provided AST node
|
||||
* to a dependency node
|
||||
*
|
||||
* Params:
|
||||
* statement = the AST node
|
||||
* Returns: the pooled `DNode`
|
||||
*/
|
||||
public DNode pool(Statement statement);
|
||||
|
||||
/**
|
||||
* Pools the provided `Clazz`
|
||||
* AST node but with an additional
|
||||
* check that it should match
|
||||
* against a `ClassStaticNode`
|
||||
* and if one does not exist
|
||||
* then one such dependency
|
||||
* node should be created
|
||||
*
|
||||
* Params:
|
||||
* clazz = the class to statcally
|
||||
* pool
|
||||
* Returns: the pooled `ClassStaticNode`
|
||||
*/
|
||||
public ClassStaticNode poolClassStatic(Clazz clazz);
|
||||
|
||||
/**
|
||||
* Pools the provided `Expression`
|
||||
* AST node into an `ExpressionDNode`
|
||||
*
|
||||
* Params:
|
||||
* expression = the AST node
|
||||
* Returns: the pooled `ExpressionDNode`
|
||||
*/
|
||||
public ExpressionDNode poolExpression(Expression expression);
|
||||
|
||||
/**
|
||||
* Pools the provided `Variable`
|
||||
* AST node into a `VariableNode`
|
||||
*
|
||||
* Params:
|
||||
* variable = the AST node
|
||||
* Returns: the pooled `VariableNode`
|
||||
*/
|
||||
public VariableNode poolVariable(Variable variable);
|
||||
|
||||
/**
|
||||
* Pools the provided `Variable`
|
||||
* AST node into a `StaticVariableDeclaration`
|
||||
*
|
||||
* Params:
|
||||
* variable = the AST node
|
||||
* Returns: the pooled `StaticVariableDeclaration`
|
||||
*/
|
||||
public StaticVariableDeclaration poolStaticVariable(Variable variable);
|
||||
|
||||
/**
|
||||
* Pools the provided `Variable`
|
||||
* AST node into a `ModuleVariableDeclaration`
|
||||
*
|
||||
* Params:
|
||||
* variable = the AST node
|
||||
* Returns: the pooled `ModuleVariableDeclaration`
|
||||
*/
|
||||
public ModuleVariableDeclaration poolModuleVariableDeclaration(Variable variable);
|
||||
|
||||
/**
|
||||
* Pools the provided `Function`
|
||||
* AST node into a `FuncDecNode`
|
||||
*
|
||||
* Params:
|
||||
* func = the AST node
|
||||
* Returns: the pooled `FUncDecNode`
|
||||
*/
|
||||
public FuncDecNode poolFuncDec(Function func);
|
||||
}
|
Loading…
Reference in New Issue