public override void AddLocalName (string name, INamedBlockVariable li)
{
if (names == null)
names = new Dictionary<string, object> ();
object value;
if (!names.TryGetValue (name, out value)) {
names.Add (name, li);
return;
}
INamedBlockVariable existing = value as INamedBlockVariable;
List<INamedBlockVariable> existing_list;
if (existing != null) {
existing_list = new List<INamedBlockVariable> ();
existing_list.Add (existing);
names[name] = existing_list;
} else {
existing_list = (List<INamedBlockVariable>) value;
}
//
// A collision checking between local names
//
for (int i = 0; i < existing_list.Count; ++i) {
existing = existing_list[i];
Block b = existing.Block;
// Collision at same level
if (li.Block == b) {
li.Block.Error_AlreadyDeclared (name, li);
break;
}
// Collision with parent
b = li.Block;
while ((b = b.Parent) != null) {
if (existing.Block == b) {
li.Block.Error_AlreadyDeclared (name, li, "parent or current");
i = existing_list.Count;
break;
}
}
// Collision with with children
b = existing.Block;
while ((b = b.Parent) != null) {
if (li.Block == b) {
li.Block.Error_AlreadyDeclared (name, li, "child");
i = existing_list.Count;
break;
}
}
}
existing_list.Add (li);
}