@Test void testGetLocalVariable() { var parentScope = new Scope(null); var childScope = parentScope.createChild(); parentScope.declareLocalVariable("parent_var", PrimitiveType.INT); assertNotNull(childScope.getLocalVariable("parent_var")); childScope.declareLocalVariable("child_var", PrimitiveType.INT); assertNull(parentScope.getLocalVariable("child_var")); assertNotNull(childScope.getLocalVariable("child_var")); assertEquals(PrimitiveType.INT, childScope.getLocalVariable("parent_var").getType()); assertEquals(PrimitiveType.INT, childScope.getLocalVariable("child_var").getType()); }
public Local getLocalVariable(String name) { var variable = variables.get(name); if (variable == null && parent != null) { variable = parent.getLocalVariable(name); } return variable; }
Scope { public Local getLocalVariable(String name) { var variable = variables.get(name); if (variable == null && parent != null) { variable = parent.getLocalVariable(name); } return variable; } }
Scope { public Local getLocalVariable(String name) { var variable = variables.get(name); if (variable == null && parent != null) { variable = parent.getLocalVariable(name); } return variable; } Scope(Scope parent); }
Scope { public Local getLocalVariable(String name) { var variable = variables.get(name); if (variable == null && parent != null) { variable = parent.getLocalVariable(name); } return variable; } Scope(Scope parent); Local declareLocalVariable(String name, Type type); Local getLocalVariable(String name); ArrayInfo declareArray(String name, PrimitiveType type); ArrayInfo declareArray(int index, String name, PrimitiveType type); ArrayInfo getArray(String name); Scope createChild(); }
Scope { public Local getLocalVariable(String name) { var variable = variables.get(name); if (variable == null && parent != null) { variable = parent.getLocalVariable(name); } return variable; } Scope(Scope parent); Local declareLocalVariable(String name, Type type); Local getLocalVariable(String name); ArrayInfo declareArray(String name, PrimitiveType type); ArrayInfo declareArray(int index, String name, PrimitiveType type); ArrayInfo getArray(String name); Scope createChild();  }