// inherit.beh -- Inheritance backlinks construction // $Id: inherit.beh,v 1.1 1998/03/11 22:28:04 dougo Exp $ Program { /** Mark classes between "*visitors*" and "*endvisitors*" as visitors. */ private void markVisitors() to { BeginVisitors, EndVisitors, ClassDef } { (@ boolean visitor = false; @) before BeginVisitors (@ visitor = true; @) before EndVisitors (@ visitor = false; @) before ClassDef (@ if (visitor) host.markVisitor(); @) } } Program { /** Set inheritance links for alternates of an alternation class. Set the parent for all visitors to the universal visitor class. */ private void setInheritanceLinks() to Subclass { (@ ClassName parent_name; @) before ClassDef (@ parent_name = host.get_classname(); if (host.isVisitor() && !parent_name.equals(Program.univis)) { host.set_parent(Program.univis); } @) before Subclass (@ ClassName clname = host.get_classname(); ClassDef def = Program.prog.findClassDef(clname); if (def == null) { // should throw an exception... System.err.println("Error: no such class \"" + clname + "\""); } else { def.set_parent(parent_name); } @) } } ClassDef { /** Set or add a parent to a class or interface. */ void set_parent(ClassName parent_name) to Superclass_Commalist { (@ ClassName child_name; boolean isInterface; @) before ClassDef (@ child_name = host.get_classname(); isInterface = host.isInterface(); @) (@ static Superclass univis = Superclass.parse(Program.univis.toString()); @) (@ Superclass_Commalist parents; @) before Superclass_Commalist (@ parents = host; @) after ClassParents (@ if (parents == null || parents.contains(univis)) { parents = new Superclass_Commalist(); host.set_superclasses(new Superclasses( new ExtendsKeywordWithoutStars(), parents)); } Superclass newparent = Superclass.parse(parent_name.toString()); if (isInterface || parents.isEmpty()) { parents.addElement(newparent); } else if (!(newparent.equals(Program.univis) || parents.contains(newparent))) { System.err.println( "Error: class " + child_name + " cannot have more than one parent: " + parent_name + " (previous parent: " + parents + ")"); } @) } }