001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package EDU.purdue.cs.bloat.tree;
022:
023: import java.util.*;
024:
025: /**
026: * Type0Visitor searches up the tree, starting at a LocalExpr, looking for an
027: * earlier instance of the same definition of that LocalExpr in a Type 0
028: * relation.
029: *
030: * @author Thomas VanDrunen
031: */
032: public class Type0Visitor extends AscendVisitor {
033:
034: boolean found; // have we found an earlier occurence
035:
036: static boolean DEBUG = false;
037:
038: public Type0Visitor(final Hashtable defInfoMap,
039: final Hashtable useInfoMap) {
040: super (defInfoMap, useInfoMap);
041: }
042:
043: public boolean search(final LocalExpr start) {
044: this .start = start;
045: previous = this .start;
046: found = false;
047: this .start.parent().visit(this );
048: return found;
049: }
050:
051: public void check(final Node node) {
052:
053: if (node instanceof ExprStmt) {
054: check(((ExprStmt) node).expr()); // might be something we want
055: }
056:
057: // the next conditional should be true if the node is a
058: // Stmt but not an ExprStmt OR if it is an ExprStmt but the
059: // above thing didn't find a match
060:
061: if (!found && (node instanceof Stmt)) {
062: found = (new Type0DownVisitor(useInfoMap, defInfoMap))
063: .search(node, start);
064: }
065:
066: else if (node instanceof StoreExpr) { // if it's a StoreExpr, we need
067: final StoreExpr n = (StoreExpr) node; // to see if the target
068: // matches
069:
070: if (((n.target() instanceof LocalExpr // this funny condition))
071: && ((n.expr() instanceof LocalExpr // weeds out moves between))
072: && (((LocalExpr) n.target()).index() // identically colored
073: == ((LocalExpr) n.expr()).index())))))) {
074: ; // local vars
075: } else {
076: check(n.target());
077: }
078: }
079:
080: else if (node instanceof InitStmt) { // if it's an InitStmt,
081: final LocalExpr[] targets = ((InitStmt) node).targets(); // check
082: // the
083: // last
084: if (targets.length > 0) {
085: check(targets[targets.length - 1]);
086: }
087: }
088:
089: // if it's a LocalExpr...
090: else if (node instanceof LocalExpr) {
091: if (((((LocalExpr) node).index() == start.index() // compare
092: // index))
093: && (((LocalExpr) node).def() == start.def())))) { // and def
094: // we've found a match
095: // update information
096:
097: ((UseInformation) useInfoMap.get(start)).type = 0;
098: ((UseInformation) useInfoMap.get(node)).type0s++;
099: found = true;
100: }
101: }
102:
103: }
104:
105: }
106:
107: class Type0DownVisitor extends DescendVisitor {
108:
109: public Type0DownVisitor(final Hashtable useInfoMap,
110: final Hashtable defInfoMap) {
111: super (useInfoMap, defInfoMap);
112: }
113:
114: public void visitLocalExpr(final LocalExpr expr) {
115: if ((expr.index() == start.index())
116: && (expr.def() == start.def())) {
117: // we've found a match
118: // update information
119: ((UseInformation) useInfoMap.get(start)).type = 0;
120: final UseInformation ui = (UseInformation) useInfoMap
121: .get(expr);
122: ui.type0s++;
123: if (exchangeFactor == 1) {
124: ui.type0_x1s++;
125:
126: }
127: if (exchangeFactor == 2) {
128: ui.type0_x2s++;
129: }
130:
131: found = true;
132: }
133: }
134:
135: }
|