/** Add a symbol to our scope */ void add(Definition def) { // Check to see if we already have a definition Definition oldDef = (Definition) elements.get(def.getName()); // If so, we'll create a MultiDef to hold them if (oldDef != null) { // If the symbol there so far was not a MultiDef if (!(oldDef instanceof MultiDef)) { // remove the old definition elements.remove(oldDef); // create a new MultiDef MultiDef newMulti = new MultiDef(def.getName(), oldDef); // add the old symbol to the MultiDef newMulti.addDef(oldDef); oldDef = newMulti; // add the MultiDef back into the scope elements.put(def.getName(), oldDef); } // We now have a multidef, so add the new symbol to it ((MultiDef) oldDef).addDef(def); } // Otherwise, just add the new symbol to the scope else { elements.put(def.getName(), def); def.setParentScope(this); } }