package AST; import java.util.HashMap; import java.util.Map; aspect AG { static final int MARGIN = 0; syn lazy int Box.width(); syn lazy int Box.height(); eq BasicBox.width() = getWidth(); eq BasicBox.height() = getHeight(); eq BoundingBox.width() = getBox().width(); eq BoundingBox.height() = getBox().height(); eq HBox.width() { int w= MARGIN; int n=getNumBox(); for(int i=0;i BoundingBox.height_cache = new HashMap(); public int BoundingBox.compute_height() { for(Map.Entry e : height_cache.entrySet()) if(e.getKey().hit()) { if(Main.DEBUG) System.out.println("Height cached for "+getName()); return e.getValue(); } if(Main.DEBUG) System.out.println("Recomputing height for "+getName()); MemoLine line = Main.pushMemoLine(); Integer res = getRoot().height(); Main.popMemoLine(); height_cache.put(line, res); return res; } private Map BoundingBox.width_cache = new HashMap(); public int BoundingBox.compute_width() { for(Map.Entry e : width_cache.entrySet()) if(e.getKey().hit()) { if(Main.DEBUG) System.out.println("Width cached for "+getName()); return e.getValue(); } if(Main.DEBUG) System.out.println("Recomputing width for "+getName()); MemoLine line = Main.pushMemoLine(); Integer res = getRoot().width(); Main.popMemoLine(); width_cache.put(line, res); return res; } // Box private Map Box.getX_cache = new HashMap(); public final int Box.getX() { int res = compute_getX(); Main.registerDependency(new Dependency(this, Attribute.X), res); return res; } public int Box.compute_getX() { for(Map.Entry e : getX_cache.entrySet()) if(e.getKey().hit()) { if(Main.DEBUG) System.out.println("X cached for "+getName()); return e.getValue(); } if(Main.DEBUG) System.out.println("Recomputing X for "+getName()); getX_cache.clear(); MemoLine line = Main.pushMemoLine(); // int res = getParent().Define_getX(this); // Main.popMemoLine(); getX_cache.put(line, res); return res; } private Map Box.getY_cache = new HashMap(); public final int Box.getY() { int res = compute_getY(); Main.registerDependency(new Dependency(this, Attribute.Y), res); return res; } public int Box.compute_getY() { for(Map.Entry e : getY_cache.entrySet()) if(e.getKey().hit()) { if(Main.DEBUG) System.out.println("Y cached for "+getName()); return e.getValue(); } if(Main.DEBUG) System.out.println("Recomputing Y for "+getName()); getY_cache.clear(); MemoLine line = Main.pushMemoLine(); // int res = getParent().Define_getY(this); // Main.popMemoLine(); getY_cache.put(line, res); return res; } public final int Box.width() { int res = compute_width(); Main.registerDependency(new Dependency(this, Attribute.Width), res); return res; } public abstract int Box.compute_width(); public final int Box.height() { int res = compute_height(); Main.registerDependency(new Dependency(this, Attribute.Height), res); return res; } public abstract int Box.compute_height(); //refine public ASTNode ASTNode.getParent() { // ASTNode res = refined(); // Main.registerDependency(new Dependency(this, Attribute.Parent), res); // return res; //} */ public String Box.toString() { return "["+getName()+"]"; } /* public int ASTNode.Define_getX(Box box) { return getParent().Define_getX(box); } public int ASTNode.Define_getY(Box box) { return getParent().Define_getY(box); } // HBox // refine public ASTNode ASTNode.getChild(int index) { // ASTNode res = refined(index); // Main.registerDependency(new Dependency(this, Attribute.Child, i), res); // return res; // } // refine public int ASTNode.getNumChild(int index) { // int res = refined(index); // Main.registerDependency(new Dependency(this, Attribute.NumChild), res); // return res; // } private Map HBox.height_cache = new HashMap(); // height of an HBox is the maximum of all child heights public int HBox.compute_height() { for(Map.Entry e : height_cache.entrySet()) if(e.getKey().hit()) { if(Main.DEBUG) System.out.println("Height cached for "+getName()); return e.getValue(); } if(Main.DEBUG) System.out.println("Recomputing height for "+getName()); height_cache.clear(); MemoLine line = Main.pushMemoLine(); // int h =0; int n = getNumBox(); for(int i=0;i HBox.width_cache = new HashMap(); // width of an HBox is the sum of all child heights public int HBox.compute_width() { for(Map.Entry e : width_cache.entrySet()) if(e.getKey().hit()) { if(Main.DEBUG) System.out.println("Width cached for "+getName()); return e.getValue(); } if(Main.DEBUG) System.out.println("Recomputing width for "+getName()); width_cache.clear(); MemoLine line = Main.pushMemoLine(); // int w= MARGIN; int n=getNumBox(); for(int i=0;i VBox.height_cache = new HashMap(); // height of a VBox is the sum of all contained boxes public int VBox.compute_height() { for(Map.Entry e : height_cache.entrySet()) if(e.getKey().hit()) { if(Main.DEBUG) System.out.println("Height cached for "+getName()); return e.getValue(); } if(Main.DEBUG) System.out.println("Recomputing height for "+getName()); height_cache.clear(); MemoLine line = Main.pushMemoLine(); // int h= MARGIN; int n = getNumBox(); for(int i=0;i VBox.width_cache = new HashMap(); // width of a VBox is the maximum of all contained boxes public int VBox.compute_width() { for(Map.Entry e : width_cache.entrySet()) if(e.getKey().hit()) { if(Main.DEBUG) System.out.println("Width cached for "+getName()); return e.getValue(); } if(Main.DEBUG) System.out.println("Recomputing width for "+getName()); width_cache.clear(); MemoLine line = Main.pushMemoLine(); // int w = 0; int n=getNumBox(); for(int i=0;i