/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
//
/**
* @author Neeraj Joshi <jneeraj@us.ibm.com>
*
*/
package org.apache.imperius.spl.parser.statements.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import org.apache.imperius.spl.core.Argument;
import org.apache.imperius.spl.core.Expression;
import org.apache.imperius.spl.core.TypeConstants;
import org.apache.imperius.spl.core.TypeInfo;
import org.apache.imperius.spl.parser.compiler.symboltable.SPLSymbolTable;
import org.apache.imperius.spl.parser.exceptions.SPLException;
import org.apache.imperius.util.SPLLogger;
public class MacroDefinition
{
private String _macroName;
private int _retType;
private List _argList = new ArrayList();
private Expression _macroExpression;
private SPLSymbolTable _macroSymTab;
private SPLSymbolTable _symTab;
private static Logger logger = SPLLogger.getSPLLogger().getLogger();
private static final String sourceClass="MacroDefinition";
private boolean _isArray =false;
public MacroDefinition(String mName, String retType,boolean isArray, ArrayList aList,
Expression mE, SPLSymbolTable mSymTab, SPLSymbolTable sTab) throws SPLException
{
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "MacroDefinition");
this._macroName = mName;
this._retType = TypeConstants.getActualType(retType);
this._macroSymTab = mSymTab;
this._symTab = sTab;
this._isArray=isArray;
populateArgList(aList);
/*if(!array.equalsIgnoreCase(""))
{
this.isArray=true;
}*/
//System.out.println("created macro expression "+mName);
this._macroExpression = mE;
logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "MacroDefinition");
}
public SPLSymbolTable getMacroSymTab()
{
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getMacroSymTab");
logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getMacroSymTab");
return _macroSymTab;
}
public Object evaluate() throws SPLException
{
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
Object returnValue = null;
returnValue = _macroExpression.evaluate();
logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
return returnValue;
}
public void setMacroSymTab(SPLSymbolTable macroSymTab) {
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setMacroSymTab");
this._macroSymTab = macroSymTab;
logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setMacroSymTab");
}
public SPLSymbolTable getSymTab() {
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getSymTab");
logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getSymTab");
return _symTab;
}
public void setSymTab(SPLSymbolTable symTab) {
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setSymTab");
this._symTab = symTab;
logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setSymTab");
}
public void setRetType(int retType) {
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setRetType");
this._retType = retType;
logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setRetType");
}
private void populateArgList(ArrayList list)
{
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "populateArgList");
for(int i=0; i< list.size(); i++)
{
Argument e = (Argument)list.get(i);
TypeInfo argType = e.getType();
_argList.add(argType);
}
logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "populateArgList");
}
public List getArgList()
{
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getArgList");
logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getArgList");
return _argList;
}
public void setArgList(ArrayList argList)
{
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setArgList");
this._argList = argList;
logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setArgList");
}
public Expression getMacroExpression()
{
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getMacroExpression");
logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getMacroExpression");
return _macroExpression;
}
public void setMacroExpression(Expression macroExpression)
{
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setMacroExpression");
this._macroExpression = macroExpression;
logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setMacroExpression");
}
public String getMacroName()
{
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getMacroName");
logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getMacroName");
return _macroName;
}
public void setMacroName(String macroName)
{
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setMacroName");
this._macroName = macroName;
logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setMacroName");
}
public int getRetType()
{
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getRetType");
logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getRetType");
return _retType;
}
public void setRetType(String retType) throws SPLException
{
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setRetType");
this._retType = TypeConstants.getActualType(retType);
logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setRetType");
}
public String getReferenceTypeName() throws SPLException
{
String refTypeName = _macroExpression.getReferenceTypeName();
return refTypeName;
}
public boolean isArray()
{
return _isArray;
}
public void setArray(boolean isArray)
{
this._isArray = isArray;
}
}