You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemml.apache.org by lr...@apache.org on 2015/12/03 19:45:49 UTC
[18/78] [abbrv] [partial] incubator-systemml git commit: Move files
to new package folder structure
http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/276d9257/src/main/java/com/ibm/bi/dml/parser/IfStatementBlock.java
----------------------------------------------------------------------
diff --git a/src/main/java/com/ibm/bi/dml/parser/IfStatementBlock.java b/src/main/java/com/ibm/bi/dml/parser/IfStatementBlock.java
deleted file mode 100644
index 4de36e5..0000000
--- a/src/main/java/com/ibm/bi/dml/parser/IfStatementBlock.java
+++ /dev/null
@@ -1,537 +0,0 @@
-/**
- * (C) Copyright IBM Corp. 2010, 2015
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package com.ibm.bi.dml.parser;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map.Entry;
-
-import com.ibm.bi.dml.hops.Hop;
-import com.ibm.bi.dml.hops.HopsException;
-import com.ibm.bi.dml.hops.OptimizerUtils;
-import com.ibm.bi.dml.hops.recompile.Recompiler;
-import com.ibm.bi.dml.lops.Lop;
-import com.ibm.bi.dml.parser.Expression.DataType;
-
-
-public class IfStatementBlock extends StatementBlock
-{
-
- private Hop _predicateHops;
- private Lop _predicateLops = null;
- private boolean _requiresPredicateRecompile = false;
-
- @Override
- public VariableSet validate(DMLProgram dmlProg, VariableSet ids, HashMap<String,ConstIdentifier> constVars, boolean conditional)
- throws LanguageException, ParseException, IOException
- {
- if (_statements.size() > 1){
- raiseValidateError("IfStatementBlock should only have 1 statement (IfStatement)", conditional);
- }
-
- IfStatement ifstmt = (IfStatement) _statements.get(0);
-
- //validate conditional predicate (incl constant propagation)
- Expression pred = ifstmt.getConditionalPredicate().getPredicate();
- pred.validateExpression(ids.getVariables(), constVars, conditional);
- if( pred instanceof DataIdentifier && constVars.containsKey( ((DataIdentifier)pred).getName()) ) {
- ifstmt.getConditionalPredicate().setPredicate(constVars.get(((DataIdentifier)pred).getName()));
- }
-
- HashMap<String,ConstIdentifier> constVarsIfCopy = new HashMap<String,ConstIdentifier>(constVars);
- HashMap<String,ConstIdentifier> constVarsElseCopy = new HashMap<String,ConstIdentifier> (constVars);
-
- VariableSet idsIfCopy = new VariableSet(ids);
- VariableSet idsElseCopy = new VariableSet(ids);
- VariableSet idsOrigCopy = new VariableSet(ids);
-
- // handle if stmt body
- _dmlProg = dmlProg;
- ArrayList<StatementBlock> ifBody = ifstmt.getIfBody();
- for(StatementBlock sb : ifBody){ //conditional exec
- idsIfCopy = sb.validate(dmlProg, idsIfCopy, constVarsIfCopy, true);
- constVarsIfCopy = sb.getConstOut();
- }
-
- // handle else stmt body
- ArrayList<StatementBlock> elseBody = ifstmt.getElseBody();
- for(StatementBlock sb : elseBody){ //conditional exec
- idsElseCopy = sb.validate(dmlProg,idsElseCopy, constVarsElseCopy, true);
- constVarsElseCopy = sb.getConstOut();
- }
-
-
- /////////////////////////////////////////////////////////////////////////////////
- // check data type and value type are same for updated variables in both
- // if statement and else statement
- // (reject conditional data type change)
- /////////////////////////////////////////////////////////////////////////////////
- for (String updatedVar : this._updated.getVariableNames()){
- DataIdentifier origVersion = idsOrigCopy.getVariable(updatedVar);
- DataIdentifier ifVersion = idsIfCopy.getVariable(updatedVar);
- DataIdentifier elseVersion = idsElseCopy.getVariable(updatedVar);
-
- //data type handling: reject conditional data type change
- if( ifVersion != null && elseVersion != null ) //both branches exist
- {
- if (!ifVersion.getOutput().getDataType().equals(elseVersion.getOutput().getDataType())){
- raiseValidateError("IfStatementBlock has unsupported conditional data type change of variable '"+updatedVar+"' in if/else branch.", conditional);
- }
- }
- else if( origVersion !=null ) //only if branch exists
- {
- if (!ifVersion.getOutput().getDataType().equals(origVersion.getOutput().getDataType())){
- raiseValidateError("IfStatementBlock has unsupported conditional data type change of variable '"+updatedVar+"' in if branch.", conditional);
- }
- }
-
- //value type handling
- if (ifVersion != null && elseVersion != null && !ifVersion.getOutput().getValueType().equals(elseVersion.getOutput().getValueType())){
- LOG.warn(elseVersion.printWarningLocation() + "Variable " + elseVersion.getName() + " defined with different value type in if and else clause.");
- }
- }
-
- // handle constant variable propagation -- (IF UNION ELSE) MINUS updated vars
-
- //////////////////////////////////////////////////////////////////////////////////
- // handle constant variables
- // 1) (IF UNION ELSE) MINUS updated const vars
- // 2) reconcile updated const vars
- // a) IF updated const variables have same value and datatype in both if / else branch, THEN set updated size to updated size
- // b) ELSE leave out of reconciled set
- /////////////////////////////////////////////////////////////////////////////////
-
- HashMap<String,ConstIdentifier> recConstVars = new HashMap<String,ConstIdentifier>();
-
- // STEP 1: (IF UNION ELSE) MINUS updated vars
- for (Entry<String,ConstIdentifier> e : constVarsIfCopy.entrySet() ){
- String varName = e.getKey();
- if (!_updated.containsVariable(varName))
- recConstVars.put(varName, e.getValue());
- }
- for (Entry<String,ConstIdentifier> e : constVarsElseCopy.entrySet() ){
- String varName = e.getKey();
- if (!_updated.containsVariable(varName))
- recConstVars.put(varName, e.getValue());
- }
-
-
- // STEP 2: check that updated const values have in both if / else branches
- // a) same data type,
- // b) same value type (SCALAR),
- // c) same value
- for (String updatedVar : _updated.getVariableNames()){
- DataIdentifier ifVersion = idsIfCopy.getVariable(updatedVar);
- DataIdentifier elseVersion = idsElseCopy.getVariable(updatedVar);
-
- if (ifVersion != null && elseVersion != null
- && ifVersion.getOutput().getDataType().equals(DataType.SCALAR)
- && elseVersion.getOutput().getDataType().equals(DataType.SCALAR)
- && ifVersion.getOutput().getValueType().equals(elseVersion.getOutput().getValueType()))
- {
- ConstIdentifier ifConstVersion = constVarsIfCopy.get(updatedVar);
- ConstIdentifier elseConstVersion = constVarsElseCopy.get(updatedVar);
- // IntIdentifier
- if (ifConstVersion != null && elseConstVersion != null && ifConstVersion instanceof IntIdentifier && elseConstVersion instanceof IntIdentifier){
- if ( ((IntIdentifier)ifConstVersion).getValue() == ((IntIdentifier) elseConstVersion).getValue() )
- recConstVars.put(updatedVar, ifConstVersion);
- }
- // DoubleIdentifier
- else if (ifConstVersion != null && elseConstVersion != null && ifConstVersion instanceof DoubleIdentifier && elseConstVersion instanceof DoubleIdentifier){
- if ( ((DoubleIdentifier)ifConstVersion).getValue() == ((DoubleIdentifier) elseConstVersion).getValue() )
- recConstVars.put(updatedVar, ifConstVersion);
- }
- // Boolean
- else if (ifConstVersion != null && elseConstVersion != null && ifConstVersion instanceof BooleanIdentifier && elseConstVersion instanceof BooleanIdentifier){
- if ( ((BooleanIdentifier)ifConstVersion).getValue() == ((BooleanIdentifier) elseConstVersion).getValue() )
- recConstVars.put(updatedVar, ifConstVersion);
- }
-
- // String
- else if (ifConstVersion != null && elseConstVersion != null && ifConstVersion instanceof StringIdentifier && elseConstVersion instanceof StringIdentifier){
- if ( ((StringIdentifier)ifConstVersion).getValue().equals(((StringIdentifier) elseConstVersion).getValue()) )
- recConstVars.put(updatedVar, ifConstVersion);
- }
- }
- }
-
- //////////////////////////////////////////////////////////////////////////////////
- // handle DataIdentifier variables
- // 1) (IF UNION ELSE) MINUS updated vars
- // 2) reconcile size updated variables
- // a) IF updated variables have same size in both if / else branch, THEN set updated size to updated size
- // b) ELSE set size updated to (-1,-1)
- // 3) add updated vars to reconciled set
- /////////////////////////////////////////////////////////////////////////////////
-
- // STEP 1: (IF UNION ELSE) MINUS updated vars
- VariableSet recVars = new VariableSet();
-
- for (String varName : idsIfCopy.getVariableNames()){
- if (!_updated.containsVariable(varName))
- recVars.addVariable(varName,idsIfCopy.getVariable(varName));
- }
- for (String varName : idsElseCopy.getVariableNames()){
- if (!_updated.containsVariable(varName))
- recVars.addVariable(varName,idsElseCopy.getVariable(varName));
- }
-
- // STEP 2: reconcile size of updated variables
- for (String updatedVar : _updated.getVariableNames()){
- DataIdentifier ifVersion = idsIfCopy.getVariable(updatedVar);
- DataIdentifier elseVersion = idsElseCopy.getVariable(updatedVar);
- DataIdentifier origVersion = idsOrigCopy.getVariable(updatedVar);
-
- if (ifVersion != null && elseVersion != null) {
- long updatedDim1 = -1, updatedDim2 = -1;
- long updatedNnz = -1;
-
- long ifVersionDim1 = (ifVersion instanceof IndexedIdentifier) ? ((IndexedIdentifier)ifVersion).getOrigDim1() : ifVersion.getDim1();
- long elseVersionDim1 = (elseVersion instanceof IndexedIdentifier) ? ((IndexedIdentifier)elseVersion).getOrigDim1() : elseVersion.getDim1();
-
- long ifVersionDim2 = (ifVersion instanceof IndexedIdentifier) ? ((IndexedIdentifier)ifVersion).getOrigDim2() : ifVersion.getDim2();
- long elseVersionDim2 = (elseVersion instanceof IndexedIdentifier) ? ((IndexedIdentifier)elseVersion).getOrigDim2() : elseVersion.getDim2();
-
- if( ifVersionDim1 == elseVersionDim1 ){
- updatedDim1 = ifVersionDim1;
- }
- if( ifVersionDim2 == elseVersionDim2 ){
- updatedDim2 = ifVersionDim2;
- }
-
-
- //NOTE: nnz not propagated via validate, and hence, we conservatively assume that nnz have been changed.
- //if( ifVersion.getNnz() == elseVersion.getNnz() ){
- // updatedNnz = ifVersion.getNnz();
- //}
-
- // add reconsiled version (deep copy of ifVersion, cast as DataIdentifier)
- DataIdentifier recVersion = new DataIdentifier(ifVersion);
- recVersion.setDimensions(updatedDim1, updatedDim2);
- recVersion.setNnz(updatedNnz);
- recVars.addVariable(updatedVar, recVersion);
- }
- else {
- // CASE: defined only if branch
- DataIdentifier recVersion = null;
- if (ifVersion != null){
- // add reconciled version (deep copy of ifVersion, cast as DataIdentifier)
- recVersion = new DataIdentifier(ifVersion);
- recVars.addVariable(updatedVar, recVersion);
- }
- // CASE: defined only else branch
- else if (elseVersion != null){
- // add reconciled version (deep copy of elseVersion, cast as DataIdentifier)
- recVersion = new DataIdentifier(elseVersion);
- recVars.addVariable(updatedVar, recVersion);
- }
- // CASE: updated, but not in either if or else branch
- else {
- // add reconciled version (deep copy of elseVersion, cast as DataIdentifier)
- recVersion = new DataIdentifier(_updated.getVariable(updatedVar));
- recVars.addVariable(updatedVar, recVersion);
- }
-
-
- long updatedDim1 = -1, updatedDim2 = -1;
- long updatedNnz = -1;
-
- if( origVersion != null ) {
- long origVersionDim1 = (origVersion instanceof IndexedIdentifier) ? ((IndexedIdentifier)origVersion).getOrigDim1() : origVersion.getDim1();
- long recVersionDim1 = recVersion.getDim1(); //always DataIdentifier (see above)
- long origVersionDim2 = (origVersion instanceof IndexedIdentifier) ? ((IndexedIdentifier)origVersion).getOrigDim2() : origVersion.getDim2();
- long recVersionDim2 = recVersion.getDim2(); //always DataIdentifier (see above)
-
- if( origVersionDim1 == recVersionDim1 ){
- updatedDim1 = origVersionDim1;
- }
- if( origVersionDim2 == recVersionDim2 ){
- updatedDim2 = origVersionDim2;
- }
- //NOTE: nnz not propagated via validate, and hence, we conservatively assume that nnz have been changed.
- //if( origVersion.getNnz() == recVersion.getNnz() ){
- // updatedNnz = recVersion.getNnz();
- //}
- }
-
- recVersion.setDimensions(updatedDim1, updatedDim2);
- recVersion.setNnz(updatedNnz);
- }
- }
-
- // propagate updated variables
- VariableSet allIdVars = new VariableSet(recVars);
-
- _constVarsIn.putAll(constVars);
- _constVarsOut.putAll(recConstVars);
-
- return allIdVars;
- }
-
- @Override
- public VariableSet initializeforwardLV(VariableSet activeInPassed)
- throws LanguageException
- {
- IfStatement ifstmt = (IfStatement)_statements.get(0);
- if (_statements.size() > 1){
- LOG.error(ifstmt.printErrorLocation() + "IfStatementBlock should have only 1 statement (if statement)");
- throw new LanguageException(ifstmt.printErrorLocation() + "IfStatementBlock should have only 1 statement (if statement)");
- }
- _read = new VariableSet();
- _gen = new VariableSet();
- _kill = new VariableSet();
- _warnSet = new VariableSet();
-
- ///////////////////////////////////////////////////////////////////////
- // HANDLE PREDICATE
- ///////////////////////////////////////////////////////////////////////
- _read.addVariables(ifstmt.getConditionalPredicate().variablesRead());
- _updated.addVariables(ifstmt.getConditionalPredicate().variablesUpdated());
- _gen.addVariables(ifstmt.getConditionalPredicate().variablesRead());
-
- ///////////////////////////////////////////////////////////////////////
- // IF STATEMENT
- ///////////////////////////////////////////////////////////////////////
-
- // initialize forward for each statement block in if body
- VariableSet ifCurrent = new VariableSet(activeInPassed);
- VariableSet genIfBody = new VariableSet();
- VariableSet killIfBody = new VariableSet();
- VariableSet updatedIfBody = new VariableSet();
- VariableSet readIfBody = new VariableSet();
-
- for (StatementBlock sb : ifstmt.getIfBody())
- {
- ifCurrent = sb.initializeforwardLV(ifCurrent);
-
- // for each generated variable in this block, check variable not killed
- // (assigned value) in prior statement block in ifstmt blody
- for (String varName : sb._gen.getVariableNames()){
-
- // IF the variable is NOT set in the while loop PRIOR to this stmt block,
- // THEN needs to be generated
- if (!killIfBody.getVariableNames().contains(varName)){
- genIfBody.addVariable(varName, sb._gen.getVariable(varName));
- }
- }
-
- readIfBody.addVariables(sb._read);
- updatedIfBody.addVariables(sb._updated);
-
- // only add kill variables for statement blocks guaranteed to execute
- if (!(sb instanceof WhileStatementBlock) && !(sb instanceof ForStatementBlock) ){
- killIfBody.addVariables(sb._kill);
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // ELSE STATEMENT
- ///////////////////////////////////////////////////////////////////////
-
- // initialize forward for each statement block in if body
- VariableSet elseCurrent = new VariableSet(activeInPassed);
- VariableSet genElseBody = new VariableSet();
- VariableSet killElseBody = new VariableSet();
- VariableSet updatedElseBody = new VariableSet();
- VariableSet readElseBody = new VariableSet();
-
- // initialize forward for each statement block in else body
- for (StatementBlock sb : ifstmt.getElseBody())
- {
- elseCurrent = sb.initializeforwardLV(elseCurrent);
-
- // for each generated variable in this block, check variable not killed
- // (assigned value) in prior statement block in ifstmt blody
- for (String varName : sb._gen.getVariableNames()){
-
- // IF the variable is NOT set in the while loop PRIOR to this stmt block,
- // THEN needs to be generated
- if (!killElseBody.getVariableNames().contains(varName)){
- genElseBody.addVariable(varName, sb._gen.getVariable(varName));
- }
- }
-
- readElseBody.addVariables(sb._read);
- updatedElseBody.addVariables(sb._updated);
-
- // only add kill variables for statement blocks guaranteed to execute
- if (!(sb instanceof WhileStatementBlock) && !(sb instanceof ForStatementBlock) ){
- killElseBody.addVariables(sb._kill);
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // PERFORM RECONCILIATION
- ///////////////////////////////////////////////////////////////////////
-
- // "conservative" read -- union of read sets for if and else path
- _read.addVariables(readIfBody);
- _read.addVariables(readElseBody);
-
- // "conservative" update -- union of updated
- _updated.addVariables(updatedIfBody);
- _updated.addVariables(updatedElseBody);
-
- // "conservative" gen -- union of gen
- _gen.addVariables(genIfBody);
- _gen.addVariables(genElseBody);
-
- // "conservative" kill -- kill set is intersection of if-kill and else-kill
- for ( String varName : killIfBody.getVariableNames()){
- if (killElseBody.containsVariable(varName)){
- _kill.addVariable(varName, killIfBody.getVariable(varName));
- }
- }
-
- // set preliminary "warn" set -- variables that if used later may cause runtime error
- // if the loop is not executed
- // warnSet = (updated MINUS (updatedIfBody INTERSECT updatedElseBody)) MINUS current
- for (String varName : _updated.getVariableNames()){
- if (!((updatedIfBody.containsVariable(varName) && updatedElseBody.containsVariable(varName))
- || activeInPassed.containsVariable(varName))) {
- _warnSet.addVariable(varName, _updated.getVariable(varName));
- }
- }
-
-
- // set activeOut to (if body current UNION else body current) UNION updated
- _liveOut = new VariableSet();
- _liveOut.addVariables(ifCurrent);
- _liveOut.addVariables(elseCurrent);
- _liveOut.addVariables(_updated);
- return _liveOut;
- }
-
- @Override
- public VariableSet initializebackwardLV(VariableSet loPassed)
- throws LanguageException
- {
- IfStatement ifstmt = (IfStatement)_statements.get(0);
- if (_statements.size() > 1){
- LOG.error(ifstmt.printErrorLocation() + "IfStatementBlock should have only 1 statement (if statement)");
- throw new LanguageException(ifstmt.printErrorLocation() + "IfStatementBlock should have only 1 statement (if statement)");
- }
-
- VariableSet currentLiveOutIf = new VariableSet(loPassed);
- VariableSet currentLiveOutElse = new VariableSet(loPassed);
-
- int numBlocks = ifstmt.getIfBody().size();
- for (int i = numBlocks - 1; i >= 0; i--){
- currentLiveOutIf = ifstmt.getIfBody().get(i).analyze(currentLiveOutIf);
- }
-
- numBlocks = ifstmt.getElseBody().size();
- for (int i = numBlocks - 1; i >= 0; i--){
- currentLiveOutElse = ifstmt.getElseBody().get(i).analyze(currentLiveOutElse);
- }
-
- // Any variable defined in either if-body or else-body is available for later use
- VariableSet bothPathsLiveOut = new VariableSet();
- bothPathsLiveOut.addVariables(currentLiveOutIf);
- bothPathsLiveOut.addVariables(currentLiveOutElse);
-
- return bothPathsLiveOut;
-
- }
-
- public void setPredicateHops(Hop hops) {
- _predicateHops = hops;
- }
-
- public ArrayList<Hop> get_hops() throws HopsException{
-
- if (_hops != null && _hops.size() > 0){
- LOG.error(this.printBlockErrorLocation() + "error there should be no HOPs in IfStatementBlock");
- throw new HopsException(this.printBlockErrorLocation() + "error there should be no HOPs in IfStatementBlock");
- }
-
- return _hops;
- }
-
- public Hop getPredicateHops(){
- return _predicateHops;
- }
-
- public Lop get_predicateLops() {
- return _predicateLops;
- }
-
- public void set_predicateLops(Lop predicateLops) {
- _predicateLops = predicateLops;
- }
-
- public VariableSet analyze(VariableSet loPassed) throws LanguageException{
-
- VariableSet predVars = ((IfStatement)_statements.get(0)).getConditionalPredicate().variablesRead();
- predVars.addVariables(((IfStatement)_statements.get(0)).getConditionalPredicate().variablesUpdated());
-
- VariableSet candidateLO = new VariableSet(loPassed);
- VariableSet origLiveOut = new VariableSet(_liveOut);
-
- _liveOut = new VariableSet();
- for (String name : candidateLO.getVariableNames()){
- if (origLiveOut.containsVariable(name)){
- _liveOut.addVariable(name, candidateLO.getVariable(name));
- }
- }
-
- initializebackwardLV(_liveOut);
-
- // set final warnSet: remove variables NOT in live out
- VariableSet finalWarnSet = new VariableSet();
- for (String varName : _warnSet.getVariableNames()){
- if (_liveOut.containsVariable(varName)){
- finalWarnSet.addVariable(varName,_warnSet.getVariable(varName));
- }
- }
- _warnSet = finalWarnSet;
-
- // for now just print the warn set
- for (String varName : _warnSet.getVariableNames()){
- LOG.warn(_warnSet.getVariable(varName).printWarningLocation() + "Initialization of " + varName + " depends on if-else execution");
- }
-
- //data flow equation: liveout = gen \cup (liveout - kill)
- _liveIn = new VariableSet();
- _liveIn.addVariables(_liveOut);
- _liveIn.removeVariables(_kill);
- _liveIn.addVariables(_gen);
-
- VariableSet liveInReturn = new VariableSet();
- liveInReturn.addVariables(_liveIn);
- return liveInReturn;
- }
-
-
- /////////
- // materialized hops recompilation flags
- ////
-
- public void updatePredicateRecompilationFlag()
- throws HopsException
- {
- _requiresPredicateRecompile = OptimizerUtils.ALLOW_DYN_RECOMPILATION
- && Recompiler.requiresRecompilation(getPredicateHops());
- }
-
- public boolean requiresPredicateRecompilation()
- {
- return _requiresPredicateRecompile;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/276d9257/src/main/java/com/ibm/bi/dml/parser/ImportStatement.java
----------------------------------------------------------------------
diff --git a/src/main/java/com/ibm/bi/dml/parser/ImportStatement.java b/src/main/java/com/ibm/bi/dml/parser/ImportStatement.java
deleted file mode 100644
index 87c9a4d..0000000
--- a/src/main/java/com/ibm/bi/dml/parser/ImportStatement.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/**
- * (C) Copyright IBM Corp. 2010, 2015
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package com.ibm.bi.dml.parser;
-
-
-
-public class ImportStatement extends Statement
-{
-
- /*
- // indicates the imported list of function names
- private ArrayList<String> _importVarList;
-
- // Indicates if the "import all" option (import moudle (*)) is being used
- private boolean _importAll;
- */
-
- // Stores the namespace methods for
- private String _namespace;
-
- // Stores the filepath with the DML file location
- private String _filePath;
-
- // store "complete path" -- DML working dir + filepath
- private String _completePath;
-
-
- public ImportStatement(){
- _namespace = null;
- _filePath = null;
- _completePath = null;
-
- }
-
- public void setNamespace(String passed){
- _namespace = passed;
- }
-
- public String getNamespace(){
- return _namespace;
- }
-
- public String getFilePath() {
- return _filePath;
- }
-
- public void setFilePath(String filePath) {
- _filePath = filePath;
- }
-
- public String getCompletePath() {
- return _completePath;
- }
-
- public void setCompletePath(String filePath) {
- _completePath = filePath;
- }
-
-
- public Statement rewriteStatement(String prefix) throws LanguageException{
- LOG.error(this.printErrorLocation() + "rewriting for inlining not supported for ImportStatement");
- throw new LanguageException(this.printErrorLocation() + "rewriting for inlining not supported for ImportStatement");
- }
-
- public void initializeforwardLV(VariableSet activeIn){}
-
- public VariableSet initializebackwardLV(VariableSet lo){
- return lo;
- }
-
- @Override
- public VariableSet variablesRead() {
- return null;
- }
-
- @Override
- public VariableSet variablesUpdated() {
- return null;
- }
-
- @Override
- public boolean controlStatement() {
- return false;
- }
-
- public String toString(){
- StringBuilder sb = new StringBuilder();
- sb.append(Statement.SOURCE + "(");
- sb.append(this._filePath + ")");
-
- if (this._namespace != null){
- sb.append(" AS " + this._namespace);
- }
- sb.append(";");
- return sb.toString();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/276d9257/src/main/java/com/ibm/bi/dml/parser/IndexedIdentifier.java
----------------------------------------------------------------------
diff --git a/src/main/java/com/ibm/bi/dml/parser/IndexedIdentifier.java b/src/main/java/com/ibm/bi/dml/parser/IndexedIdentifier.java
deleted file mode 100644
index a23c663..0000000
--- a/src/main/java/com/ibm/bi/dml/parser/IndexedIdentifier.java
+++ /dev/null
@@ -1,782 +0,0 @@
-/**
- * (C) Copyright IBM Corp. 2010, 2015
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package com.ibm.bi.dml.parser;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-
-import com.ibm.bi.dml.runtime.util.UtilFunctions;
-
-
-
-public class IndexedIdentifier extends DataIdentifier
-{
-
- // stores the expressions containing the ranges for the
- private Expression _rowLowerBound = null, _rowUpperBound = null, _colLowerBound = null, _colUpperBound = null;
-
- // stores whether row / col indices have same value (thus selecting either (1 X n) row-vector OR (n X 1) col-vector)
- private boolean _rowLowerEqualsUpper = false, _colLowerEqualsUpper = false;
-
- // for IndexedIdentifier, dim1 and dim2 will ultimately be the dimensions of the indexed region and NOT the dims of what is being indexed
- // E.g., for A[1:10,1:10], where A = Rand (rows = 20, cols = 20), dim1 = 10, dim2 = 10, origDim1 = 20, origDim2 = 20
-
- // stores the dimensions of Identifier prior to indexing
- private long _origDim1, _origDim2;
-
- public boolean getRowLowerEqualsUpper(){
- return _rowLowerEqualsUpper;
- }
-
- public boolean getColLowerEqualsUpper() {
- return _colLowerEqualsUpper;
- }
-
- public void setRowLowerEqualsUpper(boolean passed){
- _rowLowerEqualsUpper = passed;
- }
-
- public void setColLowerEqualsUpper(boolean passed) {
- _colLowerEqualsUpper = passed;
- }
-
- public IndexedIdentifier(String name, boolean passedRows, boolean passedCols){
- super(name);
- _rowLowerBound = null;
- _rowUpperBound = null;
- _colLowerBound = null;
- _colUpperBound = null;
-
- _rowLowerEqualsUpper = passedRows;
- _colLowerEqualsUpper = passedCols;
-
- _origDim1 = -1L;
- _origDim2 = -1L;
- }
-
- /**
- *
- * @param ids
- * @param currConstVars
- * @param conditional
- * @return
- * @throws LanguageException
- */
- public IndexPair calculateIndexedDimensions(HashMap<String,DataIdentifier> ids, HashMap<String, ConstIdentifier> currConstVars, boolean conditional)
- throws LanguageException
- {
- // stores the updated row / col dimension info
- long updatedRowDim = -1, updatedColDim = -1;
-
- boolean isConst_rowLowerBound = false;
- boolean isConst_rowUpperBound = false;
- boolean isConst_colLowerBound = false;
- boolean isConst_colUpperBound = false;
-
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // STEP 1 : perform constant propagation for index boundaries
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // PROCESS ROW LOWER BOUND
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
- // process row lower bound
- if (_rowLowerBound instanceof ConstIdentifier && ( _rowLowerBound instanceof IntIdentifier || _rowLowerBound instanceof DoubleIdentifier )){
-
- Long rowLB_1_1 = -1L;
- if (_rowLowerBound instanceof IntIdentifier)
- rowLB_1_1 = ((IntIdentifier)_rowLowerBound).getValue();
- else
- rowLB_1_1 = UtilFunctions.toLong(((DoubleIdentifier)_rowLowerBound).getValue());
-
- if (rowLB_1_1 < 1){
- raiseValidateError("lower-bound row index " + rowLB_1_1 + " initialized to out of bounds value. Value must be >= 1", conditional);
- }
- if ((this.getOrigDim1() > 0) && (rowLB_1_1 > this.getOrigDim1())) {
- raiseValidateError("lower-bound row index " + rowLB_1_1 + " initialized to out of bounds value. Rows in " + this.getName() + ": " + this.getOrigDim1(), conditional);
- }
- // valid lower row bound value
- isConst_rowLowerBound = true;
- }
-
- else if (_rowLowerBound instanceof ConstIdentifier) {
- raiseValidateError("assign lower-bound row index for Indexed Identifier " + this.toString() + " the non-numeric value " + _rowLowerBound.toString(), conditional);
- }
-
- // perform constant propogation for row lower bound
- else if (_rowLowerBound != null && _rowLowerBound instanceof DataIdentifier && !(_rowLowerBound instanceof IndexedIdentifier)) {
- String identifierName = ((DataIdentifier)_rowLowerBound).getName();
-
- // CASE: rowLowerBound is a constant DataIdentifier
- if (currConstVars.containsKey(identifierName)){
- ConstIdentifier constValue = currConstVars.get(identifierName);
-
- if (!(constValue instanceof IntIdentifier || constValue instanceof DoubleIdentifier ))
- LOG.info(this.printInfoLocation() + "attempted to assign lower row bound for " + this.toString() + "the non-numeric value " + constValue.getOutput().toString() + " assigned to " + identifierName + ". May cause runtime exception ");
-
- else {
-
- // test constant propogation
- long tempRowLB = -1L;
- boolean validRowLB = true;
- if (constValue instanceof IntIdentifier)
- tempRowLB = ((IntIdentifier)constValue).getValue();
- else
- tempRowLB = UtilFunctions.toLong(((DoubleIdentifier)constValue).getValue());
-
- if (tempRowLB < 1){
- LOG.info(this.printInfoLocation() + "lower-bound row index " + identifierName + " initialized to " + tempRowLB + " May cause runtime exception (runtime value must be >= 1)");
- validRowLB = false;
- }
- if (this.getOrigDim1() > 0 && tempRowLB > this.getOrigDim1()){
- LOG.info(this.printInfoLocation() + "lower-bound row index " + identifierName
- + " initialized to " + tempRowLB + " May cause runtime exception (Rows in "
- + this.getName() + ": " + this.getOrigDim1() +")");
- validRowLB = false;
- }
-
- if (validRowLB) {
- if (constValue instanceof IntIdentifier){
- _rowLowerBound = new IntIdentifier((IntIdentifier)constValue,
- constValue.getFilename(), constValue.getBeginLine(), constValue.getBeginColumn(),
- constValue.getEndLine(), constValue.getEndColumn());
-
- }
- else{
- _rowLowerBound = new DoubleIdentifier((DoubleIdentifier)constValue,
- constValue.getFilename(), constValue.getBeginLine(), constValue.getBeginColumn(),
- constValue.getEndLine(), constValue.getEndColumn());
- }
- isConst_rowLowerBound = true;
- }
- } // end else -- if (!(constValue instanceof IntIdentifier || constValue instanceof DoubleIdentifier ))
- } // end if (currConstVars.containsKey(identifierName))
- } // end constant propogation for row LB
-
- // check 1 < indexed row lower-bound < rows in IndexedIdentifier
- // (assuming row dims available for upper bound)
- Long rowLB_1 = -1L;
- if (isConst_rowLowerBound) {
-
- if (_rowLowerBound instanceof IntIdentifier)
- rowLB_1 = ((IntIdentifier)_rowLowerBound).getValue();
- else
- rowLB_1 = UtilFunctions.toLong(((DoubleIdentifier)_rowLowerBound).getValue());
- }
-
-
-
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // PROCESS ROW UPPER BOUND
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
- if (_rowUpperBound instanceof ConstIdentifier && ( _rowUpperBound instanceof IntIdentifier || _rowUpperBound instanceof DoubleIdentifier )){
-
- Long rowUB_1_1 = -1L;
- if (_rowUpperBound instanceof IntIdentifier)
- rowUB_1_1 = ((IntIdentifier)_rowUpperBound).getValue();
- else
- rowUB_1_1 = UtilFunctions.toLong(((DoubleIdentifier)_rowUpperBound).getValue());
-
- if (rowUB_1_1 < 1){
- raiseValidateError("upper-bound row index " + rowUB_1_1 + " out of bounds value. Value must be >= 1", conditional);
- }
- if ((this.getOrigDim1() > 0) && (rowUB_1_1 > this.getOrigDim1())) {
- raiseValidateError("upper-bound row index " + rowUB_1_1 + " out of bounds value. Rows in " + this.getName() + ": " + this.getOrigDim1(), conditional);
- }
- if (isConst_rowLowerBound && rowUB_1_1 < rowLB_1){
- raiseValidateError("upper-bound row index " + rowUB_1_1 + " greater than lower-bound row index " + rowLB_1, conditional);
- }
- isConst_rowUpperBound = true;
- }
- else if (_rowUpperBound instanceof ConstIdentifier){
- raiseValidateError("assign upper-bound row index for " + this.toString() + " the non-numeric value " + _rowUpperBound.toString(), conditional);
- }
-
- // perform constant propogation for upper row index
- else if (_rowUpperBound != null && _rowUpperBound instanceof DataIdentifier && !(_rowUpperBound instanceof IndexedIdentifier)) {
- String identifierName = ((DataIdentifier)_rowUpperBound).getName();
-
- if (currConstVars.containsKey(identifierName)){
- ConstIdentifier constValue = currConstVars.get(identifierName);
-
- if (!(constValue instanceof IntIdentifier || constValue instanceof DoubleIdentifier ))
- LOG.info(this.printInfoLocation() + "attempted to assign upper row bound for " + this.toString() + "the non-numeric value " + constValue.getOutput().toString() + " assigned to " + identifierName + ". May cause runtime exception ");
-
- else {
- // test constant propogation
- long tempRowUB = -1L;
- boolean validRowUB = true;
- if (constValue instanceof IntIdentifier)
- tempRowUB = ((IntIdentifier)constValue).getValue();
- else
- tempRowUB = UtilFunctions.toLong(((DoubleIdentifier)constValue).getValue());
-
- if (tempRowUB < 1){
- LOG.info(this.printInfoLocation() + "upper-bound row index " + identifierName + " initialized to " + tempRowUB + " May cause runtime exception (runtime value must be >= 1)");
- validRowUB = false;
- }
- if (this.getOrigDim1() > 0 && tempRowUB > this.getOrigDim1()){
- LOG.info(this.printInfoLocation() + "upper-bound row index " + identifierName + " initialized to " + tempRowUB + " May cause runtime exception (Rows in " + this.getName() + ": " + this.getOrigDim1() +")");
- validRowUB = false;
- }
- if (isConst_rowLowerBound && tempRowUB < rowLB_1){
- LOG.info(this.printInfoLocation() + "upper-bound row index "
- + identifierName + " initialized to " + tempRowUB
- + ", which is greater than lower-bound row index value "
- + rowLB_1 + " May cause runtime exception");
- validRowUB = false;
- }
-
- if (validRowUB) {
- if (constValue instanceof IntIdentifier){
- _rowUpperBound = new IntIdentifier((IntIdentifier)constValue,
- constValue.getFilename(), constValue.getBeginLine(),
- constValue.getBeginColumn(), constValue.getEndLine(),
- constValue.getEndColumn());
- }
- else{
- _rowUpperBound = new DoubleIdentifier((DoubleIdentifier)constValue,
- constValue.getFilename(), constValue.getBeginLine(),
- constValue.getBeginColumn(), constValue.getEndLine(),
- constValue.getEndColumn());
- }
- isConst_rowUpperBound = true;
- }
- } // end else -- if (!(constValue instanceof IntIdentifier || constValue instanceof DoubleIdentifier ))
- } // end if (currConstVars.containsKey(identifierName)){
-
- } // end constant propagation for row UB
-
-
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // PROCESS COLUMN LOWER BOUND
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
- // process column lower bound
- if (_colLowerBound instanceof ConstIdentifier && ( _colLowerBound instanceof IntIdentifier || _colLowerBound instanceof DoubleIdentifier )){
-
- Long colLB_1_1 = -1L;
- if (_colLowerBound instanceof IntIdentifier)
- colLB_1_1 = ((IntIdentifier)_colLowerBound).getValue();
- else
- colLB_1_1 = UtilFunctions.toLong(((DoubleIdentifier)_colLowerBound).getValue());
-
- if (colLB_1_1 < 1){
- raiseValidateError("lower-bound column index " + colLB_1_1 + " initialized to out of bounds value. Value must be >= 1", conditional);
- }
- if ((this.getOrigDim2() > 0) && (colLB_1_1 > this.getOrigDim2())){
- raiseValidateError("lower-bound column index " + colLB_1_1 + " initialized to out of bounds value. Columns in " + this.getName() + ": " + this.getOrigDim2(), conditional);
- }
- // valid lower row bound value
- isConst_colLowerBound = true;
- }
-
- else if (_colLowerBound instanceof ConstIdentifier) {
- raiseValidateError("assign lower-bound column index for Indexed Identifier " + this.toString() + " the non-numeric value " + _colLowerBound.toString(), conditional);
- }
-
- // perform constant propogation for column lower bound
- else if (_colLowerBound != null && _colLowerBound instanceof DataIdentifier && !(_colLowerBound instanceof IndexedIdentifier)) {
- String identifierName = ((DataIdentifier)_colLowerBound).getName();
- if (currConstVars.containsKey(identifierName)){
- ConstIdentifier constValue = currConstVars.get(identifierName);
-
- if (!(constValue instanceof IntIdentifier || constValue instanceof DoubleIdentifier ))
- LOG.info(this.printInfoLocation() + "attempted to assign lower column bound for " + this.toString() + "the non-numeric value " + constValue.getOutput().toString() + " assigned to " + identifierName + ". May cause runtime exception ");
-
- else {
-
- // test constant propogation
- long tempColLB = -1L;
- boolean validColLB = true;
- if (constValue instanceof IntIdentifier)
- tempColLB = ((IntIdentifier)constValue).getValue();
- else
- tempColLB = UtilFunctions.toLong(((DoubleIdentifier)constValue).getValue());
-
- if (tempColLB < 1){
- LOG.info(this.printInfoLocation() + "lower-bound column index " + identifierName + " initialized to " + tempColLB + " May cause runtime exception (runtime value must be >= 1)");
- validColLB = false;
- }
- if (this.getOrigDim2() > 0 && tempColLB > this.getOrigDim2()){
- LOG.info(this.printInfoLocation() + "lower-bound column index "
- + identifierName + " initialized to " + tempColLB
- + " May cause runtime exception (Columns in " + this.getName()
- + ": " + this.getOrigDim2() +")");
- validColLB = false;
- }
-
- if (validColLB) {
- if (constValue instanceof IntIdentifier){
- _colLowerBound = new IntIdentifier((IntIdentifier)constValue,
- constValue.getFilename(), constValue.getBeginLine(),
- constValue.getBeginColumn(), constValue.getEndLine(),
- constValue.getEndColumn());
- }
- else{
- _colLowerBound = new DoubleIdentifier((DoubleIdentifier)constValue,
- constValue.getFilename(), constValue.getBeginLine(),
- constValue.getBeginColumn(), constValue.getEndLine(),
- constValue.getEndColumn());
- }
- isConst_colLowerBound = true;
- }
- } // end else -- if (!(constValue instanceof IntIdentifier || constValue instanceof DoubleIdentifier ))
- }
- } // end constant propogation for column LB
-
- // check 1 < indexed column lower-bound < columns in IndexedIdentifier
- // (assuming column dims available for upper bound)
- Long colLB_1 = -1L;
- if (isConst_colLowerBound) {
-
- if (_colLowerBound instanceof IntIdentifier)
- colLB_1 = ((IntIdentifier)_colLowerBound).getValue();
- else
- colLB_1 = UtilFunctions.toLong(((DoubleIdentifier)_colLowerBound).getValue());
- }
-
-
-
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // PROCESS ROW UPPER BOUND
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
- if (_colUpperBound instanceof ConstIdentifier && ( _colUpperBound instanceof IntIdentifier || _colUpperBound instanceof DoubleIdentifier )){
-
- Long colUB_1_1 = -1L;
- if (_colUpperBound instanceof IntIdentifier)
- colUB_1_1 = ((IntIdentifier)_colUpperBound).getValue();
- else
- colUB_1_1 = UtilFunctions.toLong(((DoubleIdentifier)_colUpperBound).getValue());
-
- if (colUB_1_1 < 1){
- raiseValidateError("upper-bound column index " + colUB_1_1 + " out of bounds value. Value must be >= 1", conditional);
- }
- if ((this.getOrigDim2() > 0) && (colUB_1_1 > this.getOrigDim2())) {
- raiseValidateError("upper-bound column index " + colUB_1_1 + " out of bounds value. Columns in " + this.getName() + ": " + this.getOrigDim2(), conditional);
- }
- if (isConst_rowLowerBound && colUB_1_1 < colLB_1) {
- raiseValidateError("upper-bound column index " + colUB_1_1 + " greater than lower-bound row index " + colLB_1, conditional);
- }
-
- isConst_colUpperBound = true;
- }
- else if (_colUpperBound instanceof ConstIdentifier){
- raiseValidateError("assign upper-bound column index for " + this.toString() + " the non-numeric value " + _colUpperBound.toString(), conditional);
- }
-
- // perform constant propogation for upper row index
- else if (_colUpperBound != null && _colUpperBound instanceof DataIdentifier
- && !(_colUpperBound instanceof IndexedIdentifier)) {
- String identifierName = ((DataIdentifier)_colUpperBound).getName();
-
-
- if (currConstVars.containsKey(identifierName)){
- ConstIdentifier constValue = currConstVars.get(identifierName);
-
- if (!(constValue instanceof IntIdentifier || constValue instanceof DoubleIdentifier ))
- LOG.info(this.printInfoLocation() + "attempted to assign upper column bound for "
- + this.toString() + "the non-numeric value " + constValue.getOutput().toString()
- + " assigned to " + identifierName + ". May cause runtime exception ");
-
- else {
- // test constant propogation
- long tempColUB = -1L;
- boolean validColUB = true;
- if (constValue instanceof IntIdentifier)
- tempColUB = ((IntIdentifier)constValue).getValue();
- else
- tempColUB = UtilFunctions.toLong(((DoubleIdentifier)constValue).getValue());
-
- if (tempColUB < 1){
- LOG.info(this.printInfoLocation() + "upper-bound column index "
- + identifierName + " initialized to " + tempColUB
- + " May cause runtime exception (runtime value must be >= 1)");
- validColUB = false;
- }
- if (this.getOrigDim2() > 0 && tempColUB > this.getOrigDim2()){
- LOG.info(this.printInfoLocation() + "upper-bound column index "
- + identifierName + " initialized to " + tempColUB
- + " May cause runtime exception (Columns in " + this.getName()
- + ": " + this.getOrigDim2() + ")");
- validColUB = false;
- }
- if (isConst_colLowerBound && tempColUB < colLB_1){
- LOG.info(this.printInfoLocation() + "upper-bound column index "
- + identifierName + " initialized to " + tempColUB
- + ", which is greater than lower-bound column index value " + colLB_1
- + " May cause runtime exception");
- validColUB = false;
- }
-
- if (validColUB) {
- if (constValue instanceof IntIdentifier){
- _colUpperBound = new IntIdentifier((IntIdentifier)constValue,
- constValue.getFilename(), constValue.getBeginLine(),
- constValue.getBeginColumn(), constValue.getEndLine(),
- constValue.getEndColumn());
- }
- else{
- _colUpperBound = new DoubleIdentifier((DoubleIdentifier)constValue,
- constValue.getFilename(), constValue.getBeginLine(),
- constValue.getBeginColumn(), constValue.getEndLine(),
- constValue.getEndColumn());
- }
- isConst_colUpperBound = true;
- }
- } // end else -- if (!(constValue instanceof IntIdentifier || constValue instanceof DoubleIdentifier ))
- }
- } // end constant propagation for column UB
-
- ///////////////////////////////////////////////////////////////////////
- // STEP 2: update row dimensions
- ///////////////////////////////////////////////////////////////////////
-
- // CASE: lower == upper --> updated row dim = 1
- if (_rowLowerEqualsUpper)
- updatedRowDim = 1;
-
- // CASE: (lower == null && upper == null) --> updated row dim = (rows of input)
- else if (_rowLowerBound == null && _rowUpperBound == null){
- updatedRowDim = this.getOrigDim1();
- }
-
- // CASE: (lower == null) && (upper == constant) --> updated row dim = (constant)
- else if (_rowLowerBound == null && isConst_rowUpperBound) {
- if (_rowUpperBound instanceof IntIdentifier)
- updatedRowDim = ((IntIdentifier)_rowUpperBound).getValue();
- else if (_rowUpperBound instanceof DoubleIdentifier)
- updatedRowDim = UtilFunctions.toLong(((DoubleIdentifier)_rowUpperBound).getValue());
- }
-
- // CASE: (lower == constant) && (upper == null) && (dimIndex > 0) --> rowCount - lower bound + 1
- else if (isConst_rowLowerBound && _rowUpperBound == null && this.getOrigDim1() > 0) {
- long rowCount = this.getOrigDim1();
- if (_rowLowerBound instanceof IntIdentifier)
- updatedRowDim = rowCount - ((IntIdentifier)_rowLowerBound).getValue() + 1;
- else if (_rowLowerBound instanceof DoubleIdentifier)
- updatedRowDim = UtilFunctions.toLong(rowCount - ((DoubleIdentifier)_rowLowerBound).getValue() + 1);
- }
- // CASE: (lower == constant) && (upper == constant) --> upper bound - lower bound + 1
- else if (isConst_rowLowerBound && isConst_rowUpperBound) {
- if (_rowLowerBound instanceof IntIdentifier && _rowUpperBound instanceof IntIdentifier)
- updatedRowDim = ((IntIdentifier)_rowUpperBound).getValue() - ((IntIdentifier)_rowLowerBound).getValue() + 1;
-
- else if (_rowLowerBound instanceof DoubleIdentifier && _rowUpperBound instanceof DoubleIdentifier)
- updatedRowDim = UtilFunctions.toLong( ((DoubleIdentifier)_rowUpperBound).getValue() - ((DoubleIdentifier)_rowLowerBound).getValue() + 1);
-
- else if (_rowLowerBound instanceof IntIdentifier && _rowUpperBound instanceof DoubleIdentifier)
- updatedRowDim = UtilFunctions.toLong( ((DoubleIdentifier)_rowUpperBound).getValue() - ((IntIdentifier)_rowLowerBound).getValue() + 1);
-
- else if (_rowLowerBound instanceof DoubleIdentifier && _rowUpperBound instanceof IntIdentifier)
- updatedRowDim = UtilFunctions.toLong( ((IntIdentifier)_rowUpperBound).getValue() - ((DoubleIdentifier)_rowLowerBound).getValue() + 1);
-
- }
-
- // CASE: row dimension is unknown --> assign -1
- else{
- updatedRowDim = -1;
- }
-
-
- //////////////////////////////////////////////////////////////////////
- // STEP 3: update column dimensions
- ///////////////////////////////////////////////////////////////////////
-
- // CASE: lower == upper --> updated col dim = 1
- if (_colLowerEqualsUpper)
- updatedColDim = 1;
-
- // CASE: (lower == null && upper == null) --> updated col dim = (cols of input)
- else if (_colLowerBound == null && _colUpperBound == null){
- updatedColDim = this.getOrigDim2();
- }
- // CASE: (lower == null) && (upper == constant) --> updated col dim = (constant)
- else if (_colLowerBound == null && isConst_colUpperBound) {
- if (_colUpperBound instanceof IntIdentifier)
- updatedColDim = ((IntIdentifier)_colUpperBound).getValue();
- else if (_colUpperBound instanceof DoubleIdentifier)
- updatedColDim = UtilFunctions.toLong(((DoubleIdentifier)_colUpperBound).getValue());
- }
-
- // CASE: (lower == constant) && (upper == null) && (dimIndex > 0) --> colCount - lower bound + 1
- else if (isConst_colLowerBound && _colUpperBound == null && this.getOrigDim2() > 0) {
- long colCount = this.getOrigDim2();
- if (_colLowerBound instanceof IntIdentifier)
- updatedColDim = colCount - ((IntIdentifier)_colLowerBound).getValue() + 1;
- else if (_colLowerBound instanceof DoubleIdentifier)
- updatedColDim = UtilFunctions.toLong(colCount - ((DoubleIdentifier)_colLowerBound).getValue() + 1);
- }
-
- // CASE: (lower == constant) && (upper == constant) --> upper bound - lower bound + 1
- else if (isConst_colLowerBound && isConst_colUpperBound) {
- if (_colLowerBound instanceof IntIdentifier && _colUpperBound instanceof IntIdentifier)
- updatedColDim = ((IntIdentifier)_colUpperBound).getValue() - ((IntIdentifier)_colLowerBound).getValue() + 1;
-
- else if (_colLowerBound instanceof DoubleIdentifier && _colUpperBound instanceof DoubleIdentifier)
- updatedColDim = UtilFunctions.toLong( ((DoubleIdentifier)_colUpperBound).getValue() - ((DoubleIdentifier)_colLowerBound).getValue() + 1);
-
- else if (_colLowerBound instanceof IntIdentifier && _colUpperBound instanceof DoubleIdentifier)
- updatedColDim = UtilFunctions.toLong( ((DoubleIdentifier)_colUpperBound).getValue() - ((IntIdentifier)_colLowerBound).getValue() + 1);
-
- else if (_colLowerBound instanceof DoubleIdentifier && _colUpperBound instanceof IntIdentifier)
- updatedColDim = UtilFunctions.toLong( ((IntIdentifier)_colUpperBound).getValue() - ((DoubleIdentifier)_colLowerBound).getValue() + 1);
-
- }
-
- // CASE: column dimension is unknown --> assign -1
- else{
- updatedColDim = -1;
- }
-
- return new IndexPair(updatedRowDim, updatedColDim);
-
- }
-
- public void setOriginalDimensions(long passedDim1, long passedDim2){
- this._origDim1 = passedDim1;
- this._origDim2 = passedDim2;
- }
-
- public long getOrigDim1() { return this._origDim1; }
- public long getOrigDim2() { return this._origDim2; }
-
-
- public Expression rewriteExpression(String prefix) throws LanguageException {
-
- IndexedIdentifier newIndexedIdentifier = new IndexedIdentifier(this.getName(), this._rowLowerEqualsUpper, this._colLowerEqualsUpper);
-
- newIndexedIdentifier.setFilename(getFilename());
- newIndexedIdentifier.setBeginLine(this.getBeginLine());
- newIndexedIdentifier.setBeginColumn(this.getBeginColumn());
- newIndexedIdentifier.setEndLine(this.getEndLine());
- newIndexedIdentifier.setEndColumn(this.getEndColumn());
-
- // set dimensionality information and other Identifier specific properties for new IndexedIdentifier
- newIndexedIdentifier.setProperties(this);
- newIndexedIdentifier.setOriginalDimensions(this._origDim1, this._origDim2);
-
- // set remaining properties (specific to DataIdentifier)
- newIndexedIdentifier._kind = Kind.Data;
- newIndexedIdentifier._name = prefix + this._name;
- newIndexedIdentifier._valueTypeString = this.getValueType().toString();
- newIndexedIdentifier._defaultValue = this._defaultValue;
-
- // creates rewritten expression (deep copy)
- newIndexedIdentifier._rowLowerBound = (_rowLowerBound == null) ? null : _rowLowerBound.rewriteExpression(prefix);
- newIndexedIdentifier._rowUpperBound = (_rowUpperBound == null) ? null : _rowUpperBound.rewriteExpression(prefix);
- newIndexedIdentifier._colLowerBound = (_colLowerBound == null) ? null : _colLowerBound.rewriteExpression(prefix);
- newIndexedIdentifier._colUpperBound = (_colUpperBound == null) ? null : _colUpperBound.rewriteExpression(prefix);
-
- return newIndexedIdentifier;
- }
-
- public void setIndices(ArrayList<ArrayList<Expression>> passed) throws DMLParseException {
- if (passed.size() != 2){
- throw new DMLParseException(this.getFilename(), this.printErrorLocation() + "matrix indices must be specified for 2 dimensions");
- }
- ArrayList<Expression> rowIndices = passed.get(0);
- ArrayList<Expression> colIndices = passed.get(1);
-
- // case: both upper and lower are defined
- if (rowIndices.size() == 2){
- _rowLowerBound = rowIndices.get(0);
- _rowUpperBound = rowIndices.get(1);
- }
- // case: only one index is defined --> thus lower = upper
- else if (rowIndices.size() == 1){
- _rowLowerBound = rowIndices.get(0);
- _rowUpperBound = rowIndices.get(0);
- _rowLowerEqualsUpper = true;
- }
- else {
- throw new DMLParseException(this.getFilename(), this.printErrorLocation() + "row indices are length " + rowIndices.size() + " -- should be either 1 or 2");
- }
-
- // case: both upper and lower are defined
- if (colIndices.size() == 2){
- _colLowerBound = colIndices.get(0);
- _colUpperBound = colIndices.get(1);
- }
- // case: only one index is defined --> thus lower = upper
- else if (colIndices.size() == 1){
- _colLowerBound = colIndices.get(0);
- _colUpperBound = colIndices.get(0);
- _colLowerEqualsUpper = true;
- }
- else {
- throw new DMLParseException(this.getFilename(), this.printErrorLocation() + "column indices are length " + + colIndices.size() + " -- should be either 1 or 2");
- }
-
- if (_rowLowerBound instanceof FunctionCallIdentifier || _rowUpperBound instanceof FunctionCallIdentifier
- || _colLowerBound instanceof FunctionCallIdentifier || _colUpperBound instanceof FunctionCallIdentifier){
- throw new DMLParseException(this.getFilename(), this.printErrorLocation() + "UDF functions not supported for row or column indices");
- }
-
- }
-
- public Expression getRowLowerBound(){ return this._rowLowerBound; }
- public Expression getRowUpperBound(){ return this._rowUpperBound; }
- public Expression getColLowerBound(){ return this._colLowerBound; }
- public Expression getColUpperBound(){ return this._colUpperBound; }
-
- public void setRowLowerBound(Expression passed){ this._rowLowerBound = passed; }
- public void setRowUpperBound(Expression passed){ this._rowUpperBound = passed; }
- public void setColLowerBound(Expression passed){ this._colLowerBound = passed; }
- public void setColUpperBound(Expression passed){ this._colUpperBound = passed; }
-
- @Override
- public String toString() {
- String retVal = getName();
- if (_rowLowerBound != null || _rowUpperBound != null || _colLowerBound != null || _colUpperBound != null){
- retVal += "[";
-
- if (_rowLowerBound != null && _rowUpperBound != null){
- if (_rowLowerBound.toString().equals(_rowUpperBound.toString()))
- retVal += _rowLowerBound.toString();
- else
- retVal += _rowLowerBound.toString() + ":" + _rowUpperBound.toString();
- }
- else {
- if (_rowLowerBound != null || _rowUpperBound != null){
- if (_rowLowerBound != null)
- retVal += _rowLowerBound.toString();
-
- retVal += ":";
-
- if (_rowUpperBound != null)
- retVal += _rowUpperBound.toString();
- }
- }
-
- retVal += ",";
-
- if (_colLowerBound != null && _colUpperBound != null){
- if (_colLowerBound.toString().equals(_colUpperBound.toString()))
- retVal += _colLowerBound.toString();
- else
- retVal += _colLowerBound.toString() + ":" + _colUpperBound.toString();
- }
- else {
- if (_colLowerBound != null || _colUpperBound != null) {
-
- if (_colLowerBound != null)
- retVal += _colLowerBound.toString();
-
- retVal += ":";
-
- if (_colUpperBound != null)
- retVal += _colUpperBound.toString();
- }
- }
-
-
- retVal += "]";
- }
- return retVal;
- }
-
- @Override
- // handles case when IndexedIdentifier is on RHS for assignment
- public VariableSet variablesRead() {
- VariableSet result = new VariableSet();
-
- // add variable being indexed to read set
- result.addVariable(this.getName(), this);
-
- // add variables for indexing expressions
- if (_rowLowerBound != null)
- result.addVariables(_rowLowerBound.variablesRead());
- if (_rowUpperBound != null)
- result.addVariables(_rowUpperBound.variablesRead());
- if (_colLowerBound != null)
- result.addVariables(_colLowerBound.variablesRead());
- if (_colUpperBound != null)
- result.addVariables(_colUpperBound.variablesRead());
-
- return result;
- }
-
- public void setAllPositions (String filename, int blp, int bcp, ArrayList<ArrayList<Expression>> exprListList){
- setFilename(filename);
- setBeginLine(blp);
- setBeginColumn(bcp);
-
- Expression rightMostIndexExpr = null;
- if (exprListList != null){
- for(ArrayList<Expression> exprList : exprListList){
- if (exprList != null){
- for (Expression expr : exprList){
- if (expr != null) {
- rightMostIndexExpr = expr;
- }
- }
- }
- }
- }
-
- if (rightMostIndexExpr != null){
- setEndLine(rightMostIndexExpr.getEndLine());
- setEndColumn(rightMostIndexExpr.getEndColumn());
- }
- else {
- setEndLine(blp);
- setEndColumn(bcp);
- }
- }
-
-
- public void setProperties(Identifier i){
- _dataType = i.getDataType();
- _valueType = i.getValueType();
- _dim1 = i.getDim1();
- _dim2 = i.getDim2();
- _rows_in_block = i.getRowsInBlock();
- _columns_in_block = i.getColumnsInBlock();
- _nnz = i.getNnz();
- _formatType = i.getFormatType();
-
- if (i instanceof IndexedIdentifier){
- _origDim1 = ((IndexedIdentifier)i).getOrigDim1();
- _origDim2 = ((IndexedIdentifier)i).getOrigDim2();
- }
- else{
- _origDim1 = i.getDim1();
- _origDim2 = i.getDim2();
- }
- }
-
- @Override
- public boolean multipleReturns() {
- return false;
- }
-
-} // end class
-
-class IndexPair {
-
- public long _row, _col;
-
- public IndexPair (long row, long col){
- _row = row;
- _col = col;
- }
-} // end class
http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/276d9257/src/main/java/com/ibm/bi/dml/parser/IntIdentifier.java
----------------------------------------------------------------------
diff --git a/src/main/java/com/ibm/bi/dml/parser/IntIdentifier.java b/src/main/java/com/ibm/bi/dml/parser/IntIdentifier.java
deleted file mode 100644
index cb5446c..0000000
--- a/src/main/java/com/ibm/bi/dml/parser/IntIdentifier.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * (C) Copyright IBM Corp. 2010, 2015
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package com.ibm.bi.dml.parser;
-
-
-
-public class IntIdentifier extends ConstIdentifier
-{
-
- private long _val;
-
- public Expression rewriteExpression(String prefix) throws LanguageException{
- return this;
- }
-
- public IntIdentifier(long val, String filename, int blp, int bcp, int elp, int ecp){
- super();
- _val = val;
- _kind = Kind.Data;
- this.setDimensions(0,0);
- this.computeDataType();
- this.setValueType(ValueType.INT);
- this.setAllPositions(filename, blp, bcp, elp, ecp);
- }
-
- public IntIdentifier(IntIdentifier i, String filename, int blp, int bcp, int elp, int ecp){
- super();
- _val = i.getValue();
- _kind = Kind.Data;
- this.setDimensions(0,0);
- this.computeDataType();
- this.setValueType(ValueType.INT);
- this.setAllPositions(filename, blp, bcp, elp, ecp);
- }
-
- // Used only by the parser for unary operation
- public void multiplyByMinusOne() {
- _val = -1 * _val;
- }
-
- public long getValue(){
- return _val;
- }
-
- public String toString(){
- return Long.toString(_val);
- }
-
- @Override
- public VariableSet variablesRead() {
- return null;
- }
-
- @Override
- public VariableSet variablesUpdated() {
- return null;
- }
-
- @Override
- public long getLongValue(){
- return getValue();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/276d9257/src/main/java/com/ibm/bi/dml/parser/IterablePredicate.java
----------------------------------------------------------------------
diff --git a/src/main/java/com/ibm/bi/dml/parser/IterablePredicate.java b/src/main/java/com/ibm/bi/dml/parser/IterablePredicate.java
deleted file mode 100644
index 0fab6db..0000000
--- a/src/main/java/com/ibm/bi/dml/parser/IterablePredicate.java
+++ /dev/null
@@ -1,219 +0,0 @@
-/**
- * (C) Copyright IBM Corp. 2010, 2015
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package com.ibm.bi.dml.parser;
-
-import java.util.HashMap;
-
-import com.ibm.bi.dml.lops.Lop;
-
-
-public class IterablePredicate extends Expression
-{
-
- private DataIdentifier _iterVar; // variable being iterated over
- private Expression _fromExpr;
- private Expression _toExpr;
- private Expression _incrementExpr;
- private HashMap<String,String> _parforParams;
-
-
- public IterablePredicate(DataIdentifier iterVar, Expression fromExpr, Expression toExpr,
- Expression incrementExpr, HashMap<String,String> parForParamValues,
- String filename, int blp, int bcp, int elp, int ecp)
- {
- _iterVar = iterVar;
- _fromExpr = fromExpr;
- _toExpr = toExpr;
- _incrementExpr = incrementExpr;
-
- _parforParams = parForParamValues;
- this.setAllPositions(filename, blp, bcp, elp, ecp);
- }
-
- public String toString()
- {
- StringBuilder sb = new StringBuilder();
- sb.append( "(" );
- sb.append( _iterVar.getName() );
- sb.append(" in seq(");
- sb.append(_fromExpr.toString());
- sb.append(",");
- sb.append(_toExpr.toString());
- sb.append(",");
- sb.append(_incrementExpr.toString());
- sb.append( ")" );
- if (_parforParams != null && _parforParams.size() > 0){
- for (String key : _parforParams.keySet())
- {
- sb.append( "," );
- sb.append( key );
- sb.append( "=" );
- sb.append( _parforParams.get(key) );
- }
- }
- sb.append( ")" );
- return sb.toString();
- }
-
-
- public VariableSet variablesRead()
- {
- VariableSet result = new VariableSet();
- result.addVariables( _fromExpr.variablesRead() );
- result.addVariables( _toExpr.variablesRead() );
- result.addVariables( _incrementExpr.variablesRead() );
-
- return result;
- }
-
-
- public VariableSet variablesUpdated()
- {
- VariableSet result = new VariableSet();
- result.addVariable(_iterVar.getName(), _iterVar);
-
- return result;
- }
-
- @Override
- public Expression rewriteExpression(String prefix) throws LanguageException {
- //DataIdentifier newIterVar = (DataIdentifier)_iterVar.rewriteExpression(prefix);
- //return new IterablePredicate(newIterVar, _from, _to, _increment);
- LOG.error(this.printErrorLocation() + "rewriteExpression not supported for IterablePredicate");
- throw new LanguageException(this.printErrorLocation() + "rewriteExpression not supported for IterablePredicate");
-
- }
-
- @Override
- public void validateExpression(HashMap<String, DataIdentifier> ids, HashMap<String, ConstIdentifier> constVars, boolean conditional)
- throws LanguageException
- {
-
- //recursive validate
- if (_iterVar instanceof FunctionCallIdentifier
- || _fromExpr instanceof FunctionCallIdentifier
- || _toExpr instanceof FunctionCallIdentifier
- || _incrementExpr instanceof FunctionCallIdentifier){
- raiseValidateError("user-defined function calls not supported for iterable predicates",
- false, LanguageException.LanguageErrorCodes.UNSUPPORTED_EXPRESSION);
- }
-
-
-
- //1) VALIDATE ITERATION VARIABLE (index)
- // check the variable has either 1) not been defined already OR 2) defined as integer scalar
- if (ids.containsKey(_iterVar.getName())){
- DataIdentifier otherDI = ids.get(_iterVar.getName());
- if( otherDI.getDataType() != DataType.SCALAR || otherDI.getValueType() != ValueType.INT ){
- raiseValidateError("iterable predicate in for loop '" + _iterVar.getName() + "' must be a scalar integer", conditional);
- }
- }
-
- // set the values for DataIdentifer iterable variable
- _iterVar.setIntProperties();
-
- // add the iterVar to the variable set
- ids.put(_iterVar.getName(), _iterVar);
-
-
- //2) VALIDATE FOR PREDICATE in (from, to, increment)
- //recursively validate the individual expression
- _fromExpr.validateExpression(ids, constVars, conditional);
- _toExpr.validateExpression(ids, constVars, conditional);
- _incrementExpr.validateExpression(ids, constVars, conditional);
-
- //check for scalar expression output
- checkNumericScalarOutput( _fromExpr );
- checkNumericScalarOutput( _toExpr );
- checkNumericScalarOutput( _incrementExpr );
- }
-
- public DataIdentifier getIterVar() {
- return _iterVar;
- }
-
- public void setIterVar(DataIdentifier iterVar) {
- _iterVar = iterVar;
- }
-
- public Expression getFromExpr() {
- return _fromExpr;
- }
-
- public void setFromExpr(Expression from) {
- _fromExpr = from;
- }
-
- public Expression getToExpr() {
- return _toExpr;
- }
-
- public void setToExpr(Expression to) {
- _toExpr = to;
- }
-
- public Expression getIncrementExpr() {
- return _incrementExpr;
- }
-
- public void setIncrementExpr(Expression increment) {
- _incrementExpr = increment;
- }
-
- public HashMap<String,String> getParForParams(){
- return _parforParams;
- }
-
- public void setParForParams(HashMap<String,String> params){
- _parforParams = params;
- }
-
- public static String[] createIterablePredicateVariables( String varName, Lop from, Lop to, Lop incr )
- {
- String[] ret = new String[4]; //varname, from, to, incr
-
- ret[0] = varName;
-
- if( from.getType()==Lop.Type.Data )
- ret[1] = from.getOutputParameters().getLabel();
- if( to.getType()==Lop.Type.Data )
- ret[2] = to.getOutputParameters().getLabel();
- if( incr.getType()==Lop.Type.Data )
- ret[3] = incr.getOutputParameters().getLabel();
-
- return ret;
- }
-
- private void checkNumericScalarOutput( Expression expr )
- throws LanguageException
- {
- if( expr == null || expr.getOutput() == null )
- return;
-
- Identifier ident = expr.getOutput();
- if( ident.getDataType() == DataType.MATRIX || ident.getDataType() == DataType.OBJECT ||
- (ident.getDataType() == DataType.SCALAR && (ident.getValueType() == ValueType.BOOLEAN ||
- ident.getValueType() == ValueType.STRING ||
- ident.getValueType() == ValueType.OBJECT)) )
- {
- LOG.error(this.printErrorLocation() + "expression in iterable predicate in for loop '" + expr.toString() + "' must return a numeric scalar");
- throw new LanguageException(this.printErrorLocation() + "expression in iterable predicate in for loop '" + expr.toString() + "' must return a numeric scalar");
- }
- }
-
-} // end class
http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/276d9257/src/main/java/com/ibm/bi/dml/parser/LanguageException.java
----------------------------------------------------------------------
diff --git a/src/main/java/com/ibm/bi/dml/parser/LanguageException.java b/src/main/java/com/ibm/bi/dml/parser/LanguageException.java
deleted file mode 100644
index 6fd636a..0000000
--- a/src/main/java/com/ibm/bi/dml/parser/LanguageException.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * (C) Copyright IBM Corp. 2010, 2015
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package com.ibm.bi.dml.parser;
-
-import com.ibm.bi.dml.api.DMLException;
-
-/**
- * <p>Exception occurring at the Language level.</p>
- */
-public class LanguageException extends DMLException
-{
-
- private static final long serialVersionUID = 1L;
-
- /**
- * @see java.lang.Exception#Exception()
- */
- public LanguageException() {
- super();
- }
-
- /**
- * @see java.lang.Exception#Exception(String)
- */
- public LanguageException(String message) {
- super(message);
- }
-
- /**
- * @see java.lang.Exception#Exception(Throwable)
- */
- public LanguageException(Throwable cause) {
- super(cause);
- }
-
- /**
- * @see java.lang.Exception#Exception(String, Throwable)
- */
- public LanguageException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public LanguageException(String message, String code) {
- super(code + ERROR_MSG_DELIMITER + message);
- }
-
- public static class LanguageErrorCodes {
- public static final String UNSUPPORTED_EXPRESSION = "Unsupported Expression";
- public static final String INVALID_PARAMETERS = "Invalid Parameters";
- public static final String UNSUPPORTED_PARAMETERS = "Unsupported Parameters";
- public static final String GENERIC_ERROR = "Language Syntax Error";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/276d9257/src/main/java/com/ibm/bi/dml/parser/LiveVariableAnalysis.java
----------------------------------------------------------------------
diff --git a/src/main/java/com/ibm/bi/dml/parser/LiveVariableAnalysis.java b/src/main/java/com/ibm/bi/dml/parser/LiveVariableAnalysis.java
deleted file mode 100644
index 735dc92..0000000
--- a/src/main/java/com/ibm/bi/dml/parser/LiveVariableAnalysis.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * (C) Copyright IBM Corp. 2010, 2015
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package com.ibm.bi.dml.parser;
-
-
-public abstract class LiveVariableAnalysis
-{
-
-
- VariableSet _read;
- VariableSet _updated;
- VariableSet _gen;
- VariableSet _kill;
- VariableSet _liveIn;
- VariableSet _liveOut;
- boolean _initialized = false;
-
- VariableSet _warnSet; // variables that may not be initialized
- // applicable for control blocks
-
- public VariableSet variablesRead(){
- return _read;
- }
-
- public VariableSet variablesUpdated() {
- return _updated;
- }
-
- public VariableSet getWarn(){
- return _warnSet;
- }
-
- public VariableSet liveIn() {
- return _liveIn;
- }
-
- public VariableSet liveOut() {
- return _liveOut;
- }
-
- public VariableSet getKill(){
- return _kill;
- }
-
- public void setLiveOut(VariableSet lo){
- _liveOut = lo;
- }
-
- public void setLiveIn(VariableSet li){
- _liveIn = li;
- }
-
- public void setUpdatedVariables( VariableSet vars ){
- _updated = vars;
- }
-
- public void setReadVariables( VariableSet vars ){
- _read = vars;
- }
-
- public abstract VariableSet initializeforwardLV(VariableSet activeIn) throws LanguageException;
- public abstract VariableSet initializebackwardLV(VariableSet loPassed) throws LanguageException;
- public abstract VariableSet analyze(VariableSet loPassed) throws LanguageException;
-
-
- public void updateLiveVariablesIn(VariableSet liveIn){
- updateLiveVariables(_liveIn,liveIn);
- }
-
- public void updateLiveVariablesOut(VariableSet liveOut){
- updateLiveVariables(_liveOut,liveOut);
- }
-
- private void updateLiveVariables(VariableSet origVars, VariableSet newVars){
- for (String var : newVars.getVariables().keySet()){
- if (origVars.containsVariable(var)){
- DataIdentifier varId = newVars.getVariable(var);
- if (varId != null){
- origVars.addVariable(var, varId);
- }
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/276d9257/src/main/java/com/ibm/bi/dml/parser/MultiAssignmentStatement.java
----------------------------------------------------------------------
diff --git a/src/main/java/com/ibm/bi/dml/parser/MultiAssignmentStatement.java b/src/main/java/com/ibm/bi/dml/parser/MultiAssignmentStatement.java
deleted file mode 100644
index 66e48b1..0000000
--- a/src/main/java/com/ibm/bi/dml/parser/MultiAssignmentStatement.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/**
- * (C) Copyright IBM Corp. 2010, 2015
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package com.ibm.bi.dml.parser;
-
-import java.util.ArrayList;
-
-import com.ibm.bi.dml.api.DMLScript;
-import com.ibm.bi.dml.debug.DMLBreakpointManager;
-
-
-
-public class MultiAssignmentStatement extends Statement
-{
-
- private ArrayList<DataIdentifier> _targetList;
- private Expression _source;
-
- // rewrites statement to support function inlining (creates deep copy)
- public Statement rewriteStatement(String prefix) throws LanguageException{
-
- ArrayList<DataIdentifier> newTargetList = new ArrayList<DataIdentifier>();
-
- // rewrite targetList (deep copy)
- for (DataIdentifier target : _targetList){
- DataIdentifier newTarget = (DataIdentifier) target.rewriteExpression(prefix);
- newTargetList.add(newTarget);
- }
-
- // rewrite source (deep copy)
- Expression newSource = _source.rewriteExpression(prefix);
-
- // create rewritten assignment statement (deep copy)
- MultiAssignmentStatement retVal = new MultiAssignmentStatement(newTargetList, newSource);
- retVal.setBeginLine(this.getBeginLine());
- retVal.setBeginColumn(this.getBeginColumn());
- retVal.setEndLine(this.getEndLine());
- retVal.setEndColumn(this.getEndColumn());
-
- return retVal;
- }
-
- public MultiAssignmentStatement(ArrayList<DataIdentifier> tList, Expression s){
- _targetList = tList;
- _source = s;
- }
-
- // NOTE: f is not used -- however, error is thrown "methods have same erasure" if not included in signature
- public MultiAssignmentStatement(ArrayList<ArrayList<Expression>> exprListList, Expression s, int f){
-
- _source = s;
-
- _targetList = new ArrayList<DataIdentifier>();
- for (ArrayList<Expression> exprList : exprListList){
- Expression expr = exprList.get(0);
- if( expr instanceof IndexedIdentifier )
- _targetList.add((IndexedIdentifier)expr);
- else
- _targetList.add(new DataIdentifier(expr.toString()));
- }
- }
-
- public ArrayList<DataIdentifier> getTargetList(){
- return _targetList;
- }
-
- public Expression getSource(){
- return _source;
- }
-
- @Override
- // conservative assignment to separate statement block; will merge later if possible
- public boolean controlStatement() {
- // ensure that breakpoints end up in own statement block
- if (DMLScript.ENABLE_DEBUG_MODE) {
- DMLBreakpointManager.insertBreakpoint(_source.getBeginLine());
- }
- return true;
- }
-
- public void initializeforwardLV(VariableSet activeIn){}
- public VariableSet initializebackwardLV(VariableSet lo){
- return lo;
- }
-
- public VariableSet variablesRead() {
- VariableSet result = new VariableSet();
-
- // add variables read by source expression
- result.addVariables(_source.variablesRead());
-
- // for any IndexedIdentifier on LHS, add variables for indexing expressions
- for (int i=0; i<_targetList.size(); i++){
- if (_targetList.get(i) instanceof IndexedIdentifier) {
- IndexedIdentifier target = (IndexedIdentifier) _targetList.get(i);
- result.addVariables(target.variablesRead());
- }
- }
-
- return result;
- }
-
- public VariableSet variablesUpdated() {
-
- VariableSet result = new VariableSet();
-
- // add target to updated list
- for (DataIdentifier target : _targetList){
- result.addVariable(target.getName(), target);
- }
- return result;
- }
-
- @Override
- public String toString()
- {
- StringBuilder sb = new StringBuilder();
- sb.append("[");
-
- for( int i=0; i< _targetList.size(); i++ )
- {
- sb.append(_targetList.get(i).toString());
- if (i < _targetList.size() - 1)
- sb.append(",");
- }
- sb.append("] = ");
- sb.append(_source.toString());
- sb.append(";");
-
- return sb.toString();
- }
-
- public void setSource(FunctionCallIdentifier s) {
- _source = s;
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/276d9257/src/main/java/com/ibm/bi/dml/parser/OutputStatement.java
----------------------------------------------------------------------
diff --git a/src/main/java/com/ibm/bi/dml/parser/OutputStatement.java b/src/main/java/com/ibm/bi/dml/parser/OutputStatement.java
deleted file mode 100644
index 3b9d6d6..0000000
--- a/src/main/java/com/ibm/bi/dml/parser/OutputStatement.java
+++ /dev/null
@@ -1,233 +0,0 @@
-/**
- * (C) Copyright IBM Corp. 2010, 2015
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package com.ibm.bi.dml.parser;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-
-import com.ibm.bi.dml.api.DMLScript;
-import com.ibm.bi.dml.debug.DMLBreakpointManager;
-import com.ibm.bi.dml.parser.Expression.DataOp;
-
-
-public class OutputStatement extends Statement
-{
-
- private DataIdentifier _id;
- private DataExpression _paramsExpr;
-
- public static final String[] WRITE_VALID_PARAM_NAMES = { DataExpression.IO_FILENAME,
- DataExpression.FORMAT_TYPE,
- DataExpression.DELIM_DELIMITER,
- DataExpression.DELIM_HAS_HEADER_ROW,
- DataExpression.DELIM_SPARSE};
-
- public DataIdentifier getIdentifier(){
- return _id;
- }
-
- public DataExpression getSource(){
- return _paramsExpr;
- }
-
- public void setIdentifier(DataIdentifier t) {
- _id = t;
- }
-
- public OutputStatement(DataIdentifier t, DataOp op,
- String filename, int blp, int bcp, int elp, int ecp){
- _id = t;
- _paramsExpr = new DataExpression(op, new HashMap<String,Expression>(),
- filename, blp, bcp, elp, ecp);
- }
-
- /**
- * Called by the parser (both javacc and antlr).
- *
- * @param fname
- * @param fci
- * @param filename
- * @param blp
- * @param bcp
- * @param elp
- * @param ecp
- * @throws DMLParseException
- */
- OutputStatement(String fname, FunctionCallIdentifier fci,
- String filename, int blp, int bcp, int elp, int ecp)
- throws DMLParseException
- {
-
- this.setAllPositions(filename, blp, bcp, elp, ecp);
- DataOp op = Expression.DataOp.WRITE;
- ArrayList<ParameterExpression> passedExprs = fci.getParamExprs();
- _paramsExpr = new DataExpression(op, new HashMap<String,Expression>(),
- filename, blp, bcp, elp, ecp);
- DMLParseException runningList = new DMLParseException(fname);
-
- //check number parameters and proceed only if this will not cause errors
- if (passedExprs.size() < 2)
- runningList.add(new DMLParseException(fci.getFilename(), fci.printErrorLocation() + "write method must specify both variable to write to file, and filename to write variable to"));
- else
- {
- ParameterExpression firstParam = passedExprs.get(0);
- if (firstParam.getName() != null || (!(firstParam.getExpr() instanceof DataIdentifier)))
- runningList.add(new DMLParseException(fci.getFilename(), fci.printErrorLocation() + "first argument to write method must be name of variable to be written out"));
- else
- _id = (DataIdentifier)firstParam.getExpr();
-
- ParameterExpression secondParam = passedExprs.get(1);
- if (secondParam.getName() != null || (secondParam.getName() != null && secondParam.getName().equals(DataExpression.IO_FILENAME)))
- runningList.add(new DMLParseException(fci.getFilename(), fci.printErrorLocation() + "second argument to write method must be filename of file variable written to"));
- else
- addExprParam(DataExpression.IO_FILENAME, secondParam.getExpr(), false);
-
- for (int i = 2; i< passedExprs.size(); i++){
- ParameterExpression currParam = passedExprs.get(i);
- try {
- addExprParam(currParam.getName(), currParam.getExpr(), false);
- } catch (DMLParseException e){
- runningList.add(e);
- }
- }
- if (fname.equals("writeMM")){
- StringIdentifier writeMMExpr = new StringIdentifier(DataExpression.FORMAT_TYPE_VALUE_MATRIXMARKET,
- this.getFilename(), this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
- addExprParam(DataExpression.FORMAT_TYPE, writeMMExpr, false);
- }
- else if (fname.equals("write.csv")){
- StringIdentifier delimitedExpr = new StringIdentifier(DataExpression.FORMAT_TYPE_VALUE_CSV,
- this.getFilename(), this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
- addExprParam(DataExpression.FORMAT_TYPE, delimitedExpr, false);
- }
- }
-
- if (runningList.size() > 0)
- throw runningList;
- }
-
- public void setExprParam(String name, Expression value) {
- _paramsExpr.addVarParam(name, value);
- }
-
- public static boolean isValidParamName(String key){
- for (String paramName : WRITE_VALID_PARAM_NAMES)
- if (paramName.equals(key))
- return true;
- return false;
- }
-
- public void addExprParam(String name, Expression value, boolean fromMTDFile) throws DMLParseException
- {
- DMLParseException runningList = new DMLParseException(value.getFilename());
-
- if( _paramsExpr.getVarParam(name) != null )
- runningList.add(new DMLParseException(value.getFilename(), value.printErrorLocation() + "attempted to add IOStatement parameter " + name + " more than once"));
-
- if( !OutputStatement.isValidParamName(name) )
- runningList.add(new DMLParseException(value.getFilename(), value.printErrorLocation() + "attempted to add invalid write statement parameter: " + name));
-
- _paramsExpr.addVarParam(name, value);
-
- if (runningList.size() > 0)
- throw runningList;
- }
-
- // rewrites statement to support function inlining (create deep copy)
- public Statement rewriteStatement(String prefix) throws LanguageException{
-
- OutputStatement newStatement = new OutputStatement(null,Expression.DataOp.WRITE,
- this.getFilename(), this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
-
- // rewrite outputStatement variable name (creates deep copy)
- newStatement._id = (DataIdentifier)this._id.rewriteExpression(prefix);
-
- // rewrite parameter expressions (creates deep copy)
- DataOp op = _paramsExpr.getOpCode();
- HashMap<String,Expression> newExprParams = new HashMap<String,Expression>();
- for (String key : _paramsExpr.getVarParams().keySet()){
- Expression newExpr = _paramsExpr.getVarParam(key).rewriteExpression(prefix);
- newExprParams.put(key, newExpr);
- }
- DataExpression newParamerizedExpr = new DataExpression(op, newExprParams,
- this.getFilename(), this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
- newStatement.setExprParams(newParamerizedExpr);
- return newStatement;
- }
-
- public void setExprParams(DataExpression newParamerizedExpr) {
- _paramsExpr = newParamerizedExpr;
- }
- public Expression getExprParam(String key){
- return _paramsExpr.getVarParam(key);
- }
-
- public void initializeforwardLV(VariableSet activeIn){}
- public VariableSet initializebackwardLV(VariableSet lo){
- return lo;
- }
-
- public String toString(){
- StringBuilder sb = new StringBuilder();
- sb.append(Statement.OUTPUTSTATEMENT + " ( " );
- sb.append( _id.toString() + ", " + _paramsExpr.getVarParam(DataExpression.IO_FILENAME).toString());
- for (String key : _paramsExpr.getVarParams().keySet()){
- if (!key.equals(DataExpression.IO_FILENAME))
- sb.append(", " + key + "=" + _paramsExpr.getVarParam(key));
- }
- sb.append(" );");
- return sb.toString();
- }
-
- @Override
- public VariableSet variablesRead() {
- VariableSet result = new VariableSet();
-
- // handle variable that is being written out
- result.addVariables(_id.variablesRead());
-
- // handle variables for output filename expression
- //result.addVariables(_filenameExpr.variablesRead());
-
- // add variables for parameter expressions
- for (String key : _paramsExpr.getVarParams().keySet())
- result.addVariables(_paramsExpr.getVarParam(key).variablesRead()) ;
-
- return result;
- }
-
- @Override
- public VariableSet variablesUpdated() {
- return null;
- }
-
- @Override
- public boolean controlStatement() {
- // ensure that breakpoints end up in own statement block
- if (DMLScript.ENABLE_DEBUG_MODE) {
- DMLBreakpointManager.insertBreakpoint(_paramsExpr.getBeginLine());
- return true;
- }
-
- Expression fmt = _paramsExpr.getVarParam(DataExpression.FORMAT_TYPE);
- if ( fmt != null && fmt.toString().equalsIgnoreCase("csv")) {
- return true;
- }
- return false;
- }
-}