🧹️🧼 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 upfeature/container_methods
parent
ee537f2b25
commit
c55cd74596
@ -0,0 +1,119 @@
|
||||
/**
|
||||
* Provides implementation of the `IFuncDefStore`
|
||||
* interface
|
||||
*/
|
||||
module tlang.compiler.typecheck.dependency.store.impls;
|
||||
|
||||
import tlang.compiler.typecheck.dependency.store.interfaces;
|
||||
import tlang.compiler.symbols.data : Function;
|
||||
import tlang.compiler.typecheck.dependency.core : FunctionData, DFunctionInnerGenerator;
|
||||
import tlang.compiler.typecheck.core : TypeChecker;
|
||||
|
||||
/**
|
||||
* An implementation of the `IFuncDefStore`
|
||||
* which provides us with a way to store
|
||||
* function definitions and retrieve them
|
||||
* later
|
||||
*/
|
||||
public final class FuncDefStore : IFuncDefStore
|
||||
{
|
||||
/**
|
||||
* All declared functions
|
||||
*/
|
||||
private FunctionData[string] functions;
|
||||
|
||||
/**
|
||||
* The type checker instance
|
||||
*/
|
||||
private TypeChecker tc;
|
||||
|
||||
/**
|
||||
* Constructs a new function
|
||||
* definition store with
|
||||
* the provided type
|
||||
* checking instance
|
||||
*
|
||||
* Params:
|
||||
* typeChecker = the `TypeChecker`
|
||||
*/
|
||||
this(TypeChecker typeChecker)
|
||||
{
|
||||
this.tc = typeChecker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the function definition
|
||||
* to the store
|
||||
*
|
||||
* Params:
|
||||
* func = the function to add
|
||||
* Throws:
|
||||
* FuncDefStoreException if the function
|
||||
* has already been added
|
||||
*/
|
||||
public void addFunctionDef(Function func)
|
||||
{
|
||||
/* (Sanity Check) This should never be called again */
|
||||
foreach(string cFuncKey; functions.keys())
|
||||
{
|
||||
FunctionData cFuncData = functions[cFuncKey];
|
||||
Function cFunc = cFuncData.func;
|
||||
|
||||
if(cFunc == func)
|
||||
{
|
||||
throw new FuncDefStoreException("The provided Function already exists within the store");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the FunctionData, coupled with it own DNodeGenerator
|
||||
* context etc.
|
||||
*/
|
||||
FunctionData funcData;
|
||||
funcData.ownGenerator = new DFunctionInnerGenerator(tc, this, func);
|
||||
// TODO: Should we not generate a HELLA long name rather, to avoid duplication problems and overwrites of key values
|
||||
|
||||
funcData.name = tc.getResolver().generateName(tc.getModule(), func);
|
||||
|
||||
funcData.name = func.getName();
|
||||
funcData.func = func;
|
||||
|
||||
|
||||
functions[funcData.name] = funcData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs all of the function
|
||||
* definitions currently stored
|
||||
*
|
||||
* Returns: a `FunctionData[string]`
|
||||
* map
|
||||
*/
|
||||
public FunctionData[string] grabFunctionDefs()
|
||||
{
|
||||
return this.functions.dup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs a function definition by its
|
||||
* name
|
||||
*
|
||||
* Params:
|
||||
* name = the name of the function
|
||||
* Returns: the `FunctionData`
|
||||
* Throws:
|
||||
* FuncDefStoreException if the function
|
||||
* could not be found
|
||||
*/
|
||||
public FunctionData grabFunctionDef(string name)
|
||||
{
|
||||
if(name in this.functions)
|
||||
{
|
||||
return this.functions[name];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new FuncDefStoreException("Could not find function by name '"~name~"'");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Provides the definition of a function definition
|
||||
* store and retrieval system
|
||||
*/
|
||||
module tlang.compiler.typecheck.dependency.store.interfaces;
|
||||
|
||||
import tlang.compiler.symbols.data : Function;
|
||||
import tlang.compiler.typecheck.dependency.core : FunctionData;
|
||||
import misc.exceptions : TError;
|
||||
|
||||
/**
|
||||
* Represents a storage mechanism
|
||||
* which can store and retrieve
|
||||
* function definition datas
|
||||
*/
|
||||
public interface IFuncDefStore
|
||||
{
|
||||
/**
|
||||
* Adds the function definition
|
||||
* to the store
|
||||
*
|
||||
* Params:
|
||||
* func = the function to add
|
||||
* Throws:
|
||||
* FuncDefStoreException if the function
|
||||
* has already been added
|
||||
*/
|
||||
public void addFunctionDef(Function func);
|
||||
|
||||
/**
|
||||
* Grabs all of the function
|
||||
* definitions currently stored
|
||||
*
|
||||
* Returns: a `FunctionData[string]`
|
||||
* map
|
||||
*/
|
||||
public FunctionData[string] grabFunctionDefs();
|
||||
|
||||
/**
|
||||
* Grabs a function definition by its
|
||||
* name
|
||||
*
|
||||
* Params:
|
||||
* name = the name of the function
|
||||
* Returns: the `FunctionData`
|
||||
* Throws:
|
||||
* FuncDefStoreException if the function
|
||||
* could not be found
|
||||
*/
|
||||
public FunctionData grabFunctionDef(string name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception thrown when an error occurs
|
||||
* with the `IFuncDefStore` system
|
||||
*/
|
||||
public final class FuncDefStoreException : TError
|
||||
{
|
||||
/**
|
||||
* Constructs a new `FuncDefStoreException`
|
||||
* with the given error message
|
||||
*
|
||||
* Params:
|
||||
* msg = the error message
|
||||
*/
|
||||
this(string msg)
|
||||
{
|
||||
super(msg);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue