- Added new SymbolMapper class with a static method which will take a Container and an entity name, resolve the Entity and then generate the hash of the absolute path to said entity and return this as the `symbol name`

TypeChecker

- Set the static field to refer to this instance of the TypeChecker (in the SymbolMapper class)

VariableDeclaration

- Use the `symbolLookup()` method to transform the name
This commit is contained in:
Tristan B. Velloza Kildaire 2022-12-12 10:58:58 +02:00
parent 6a64ed40c9
commit d8e5f108e4
3 changed files with 52 additions and 0 deletions

View File

@ -106,8 +106,12 @@ public final class VariableDeclaration : StorageDeclaration
//simple_variables.x -> simple_variables_x
//NOTE: We may need to create a symbol table actually and add to that and use that as these names
//could get out of hand (too long)
// NOTE: Best would be identity-mapping Entity's to a name
string renamedSymbol = symbolRename(typedEntityVariableName);
import compiler.codegen.mapper : SymbolMapper;
renamedSymbol = SymbolMapper.symbolLookup(context.getContainer(), varName);
return varType~" "~renamedSymbol~";";
}
}

View File

@ -0,0 +1,44 @@
module compiler.codegen.mapper;
import compiler.typecheck.core;
import compiler.symbols.data;
/**
* SymbolMapper
*
* Maps Entity's to consistent but unique symbol
* names (strings)
*/
public final class SymbolMapper
{
// Used to map names to entities
public static TypeChecker tc;
// Entity map
// private string[Entity] symbolMap;
// this(TypeChecker tc)
// {
// this.tc = tc;
// }
public static string symbolLookup(Container container, string entityNameIn)
{
// Firstly translate the entity name to the full absolute path
auto entity = tc.getResolver().resolveBest(container, entityNameIn); //TODO: Remove `auto`
string entityNameAbsolute = tc.getResolver().generateName(tc.getModule(), entity);
// Hash the absolute path name
// FIXME: Ensure these hashes are unique (use the smbyol table!)
import std.digest : toHexString, LetterCase;
import std.digest.md : md5Of;
// Generate the name as `_<hexOfAbsPath>`
string symbolName = toHexString!(LetterCase.lower)(md5Of(entityNameAbsolute));
symbolName="_"~symbolName;
return symbolName;
}
}

View File

@ -71,6 +71,10 @@ public final class TypeChecker
// Allow Context class access to the type checker (used in Instruction where only Context is available)
Context.tc = this;
// Allow the SymbolMapper class to access the type checker
import compiler.codegen.mapper : SymbolMapper;
SymbolMapper.tc = this;
// DNodeGenerator.staticTC = this;