protected boolean atGlobalScope() { return !currentScope.hasParent(); }
private Scope findRootScope() { Scope candidate = currentScope; while (candidate.hasParent()) { candidate = candidate.getParent(); } return candidate; }
private int numNestedScopes() { int result = 0; Scope temp = currentScope; while (temp.hasParent()) { result++; temp = temp.getParent(); } return result; }
public void addLocal(String name, Type type) { assert currentScope.hasParent(); currentScope.add(name, type, Optional.empty()); }
/** * Removes and returns scope entry associated with the given name, if present. Otherwise * delegates removal to parent scope, if one exists. Otherwise returns null to indicate that * nothing was removed. * @param name Name of the key to be removed * @return Scope entry that has been removed, or null if no removal took place */ public ScopeEntry remove(String name) { if (variableMapping.containsKey(name)) { return variableMapping.remove(name); } if (hasParent()) { return parent.remove(name); } return null; }
/** * Look in current scope to see whether we have a struct definition type matching the struct name. * @param structName Name of struct type. * @return Corresponding struct definition, if found, otherwise null. */ public StructDefinitionType lookupStructName(String structName) { if (structMapping.containsKey(structName)) { return structMapping.get(structName); } if (hasParent()) { return getParent().lookupStructName(structName); } return null; }
public void addParameter(ParameterDecl parameterDecl) { assert currentScope.hasParent(); currentScope.add(parameterDecl.getName(), parameterDecl.getType(), Optional.of(parameterDecl)); }