mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-01-02 05:30:53 +00:00
store symbol full names instead of constructing on demand. (~5% overall compiler speed improvement)
This commit is contained in:
parent
fa2024296b
commit
073845093b
@ -13,12 +13,21 @@ public class Label implements Symbol {
|
||||
/** The containing scope */
|
||||
private Scope scope;
|
||||
|
||||
/** Full name of label (scope::name or name) */
|
||||
private String fullName;
|
||||
|
||||
private boolean intermediate;
|
||||
|
||||
public Label(String name, Scope scope, boolean intermediate) {
|
||||
this.name = name;
|
||||
this.scope = scope;
|
||||
this.intermediate = intermediate;
|
||||
setFullName();
|
||||
}
|
||||
|
||||
private void setFullName() {
|
||||
String scopeName = (scope == null) ? "" : scope.getFullName();
|
||||
fullName = (scopeName.length() > 0) ? scopeName + "::" + name : name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -47,7 +56,7 @@ public class Label implements Symbol {
|
||||
|
||||
@Override
|
||||
public String getFullName() {
|
||||
return Scope.getFullName(this);
|
||||
return fullName;
|
||||
}
|
||||
|
||||
public boolean isIntermediate() {
|
||||
|
@ -20,27 +20,25 @@ public abstract class Scope implements Symbol {
|
||||
private int intermediateLabelCount = 1;
|
||||
private int blockCount = 1;
|
||||
private Scope parentScope;
|
||||
private String fullName;
|
||||
|
||||
public Scope(String name, Scope parentScope) {
|
||||
this.name = name;
|
||||
this.parentScope = parentScope;
|
||||
this.symbols = new LinkedHashMap<>();
|
||||
setFullName();
|
||||
}
|
||||
|
||||
public Scope() {
|
||||
this.name = "";
|
||||
this.parentScope = null;
|
||||
this.symbols = new LinkedHashMap<>();
|
||||
setFullName();
|
||||
}
|
||||
|
||||
public static String getFullName(Symbol symbol) {
|
||||
if(symbol.getScope() != null) {
|
||||
String scopeName = symbol.getScope().getFullName();
|
||||
if(scopeName.length() > 0) {
|
||||
return scopeName + "::" + symbol.getLocalName();
|
||||
}
|
||||
}
|
||||
return symbol.getLocalName();
|
||||
private void setFullName() {
|
||||
String scopeName = (parentScope == null) ? "" : parentScope.getFullName();
|
||||
fullName = (scopeName.length() > 0) ? scopeName + "::" + name : name;
|
||||
}
|
||||
|
||||
public HashMap<String, Symbol> getSymbols() {
|
||||
@ -54,7 +52,7 @@ public abstract class Scope implements Symbol {
|
||||
|
||||
@Override
|
||||
public String getFullName() {
|
||||
return getFullName(this);
|
||||
return fullName;
|
||||
}
|
||||
|
||||
public ScopeRef getRef() {
|
||||
@ -69,6 +67,7 @@ public abstract class Scope implements Symbol {
|
||||
@Override
|
||||
public void setScope(Scope scope) {
|
||||
this.parentScope = scope;
|
||||
setFullName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -41,12 +41,21 @@ public abstract class SymbolVariable implements Symbol {
|
||||
/** Comments preceding the procedure in the source code. */
|
||||
private List<Comment> comments;
|
||||
|
||||
/** Full name of variable (scope::name or name) */
|
||||
private String fullName;
|
||||
|
||||
public SymbolVariable(String name, Scope scope, SymbolType type) {
|
||||
this.name = name;
|
||||
this.scope = scope;
|
||||
this.type = type;
|
||||
this.inferredType = false;
|
||||
this.comments = new ArrayList<>();
|
||||
setFullName();
|
||||
}
|
||||
|
||||
private void setFullName() {
|
||||
String scopeName = (scope == null) ? "" : scope.getFullName();
|
||||
fullName = (scopeName.length() > 0) ? scopeName + "::" + name : name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -56,7 +65,7 @@ public abstract class SymbolVariable implements Symbol {
|
||||
|
||||
@Override
|
||||
public String getFullName() {
|
||||
return Scope.getFullName(this);
|
||||
return this.fullName;
|
||||
}
|
||||
|
||||
public SymbolType getType() {
|
||||
@ -86,6 +95,7 @@ public abstract class SymbolVariable implements Symbol {
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
setFullName();
|
||||
}
|
||||
|
||||
public String getAsmName() {
|
||||
@ -102,6 +112,7 @@ public abstract class SymbolVariable implements Symbol {
|
||||
|
||||
public void setScope(Scope scope) {
|
||||
this.scope = scope;
|
||||
setFullName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user