/* // $Id: //guest/julian_hyde/saffron/src/main/saffron/util/RelEnvironment.java#1 $ // Saffron preprocessor and data engine // Copyright (C) 2002 Julian Hyde <julian.hyde@mail.com> // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public // License as published by the Free Software Foundation; either // version 2 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Library General Public License for more details. // // You should have received a copy of the GNU Library General Public // License along with this library; if not, write to the // Free Software Foundation, Inc., 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. // // See the COPYING file located in the top-level-directory of // the archive of this library for complete text of license. */ package saffron.util; import openjava.mop.Environment; import openjava.mop.OJClass; import openjava.ptree.FieldAccess; import openjava.ptree.Variable; import openjava.ptree.util.SyntheticClass; import saffron.rel.Rel; /** * todo: **/ public class RelEnvironment extends Environment { Rel rel; public RelEnvironment(Environment parent, Rel rel) { super(parent); this.rel = rel; } // implement Environment public String toString() { return "RelEnvironment: rel=" + rel.toString(); } // implement Environment public String getPackage() { return parent.getPackage(); } // implement Environment public OJClass lookupClass(String name) { return parent.lookupClass(name); } /** * Returns the ordinal of the input represented by the variable * <code>name</code>, or -1 if it does not represent an input. **/ public static int getInputOrdinal(String name) { if (name.startsWith("$input")) { if (name.equals("$input0")) { return 0; } else if (name.equals("$input1")) { return 1; } else { throw Util.newInternal( "unknown input variable: " + name); } } else { return -1; } } // implement Environment public OJClass lookupBind(String name) { if (name.startsWith("$corel")) { Rel corel = rel.getQuery().lookupCorel(name); if (corel != null) { return corel.getRowType(); } } int i = getInputOrdinal(name); if (i >= 0) { Rel input = rel.getInput(i); OJClass clazz = input.getRowType(); return clazz; } else { return parent.lookupBind(name); } } /** * Constructs the name for the <code>ordinal</code>th input. For example, * <code>makeName(0)</code> returns "$input0". */ public static String makeName(int ordinal) { return "$input" + ordinal; } /** * Constructs a reference to the <code>field</code><sup>th</sup> field of * the <code>ordinal</code><sup>th</sup> input. **/ public static FieldAccess makeFieldAccess(int ordinal, int field) { return new FieldAccess( new Variable(makeName(0)), SyntheticClass.makeField(field)); } // implement Environment public void record(String name, OJClass clazz) { throw new UnsupportedOperationException(); } // implement Environment public void bindVariable(String name, OJClass clazz) { throw new UnsupportedOperationException(); } } // End RelEnvironment.java
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 1801 | Julian Hyde |
saffron: add ObjectSchema; rules can now be matched more than once; started to implement correlations in queries in from list. |
||
#2 | 1748 | Julian Hyde |
saffron: convert unit tests to JUnit; add CallingConvention.ITERABLE; lots of other stuff; release 0.1. |
||
#1 | 1467 | Julian Hyde |
saffron: First saffron check-in; incorporate my changes to openjava. |