Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.
*/
package flash.tools.debugger.expression;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import flash.tools.debugger.*;
import org.apache.royale.abc.ABCConstants;
import org.apache.royale.compiler.constants.IASLanguageConstants;
import org.apache.royale.compiler.definitions.IDefinition;
import org.apache.royale.compiler.definitions.ITypeDefinition;
import org.apache.royale.compiler.internal.definitions.NamespaceDefinition;
import org.apache.royale.compiler.internal.semantics.SemanticUtils;
import org.apache.royale.compiler.internal.tree.as.IdentifierNode;
import org.apache.royale.compiler.internal.tree.as.MemberAccessExpressionNode;
import org.apache.royale.compiler.internal.tree.as.NumericLiteralNode;
import org.apache.royale.compiler.internal.tree.as.RegExpLiteralNode;
import org.apache.royale.compiler.projects.ICompilerProject;
import org.apache.royale.compiler.tree.ASTNodeID;
import org.apache.royale.compiler.tree.as.INumericLiteralNode.INumericValue;
import org.apache.royale.compiler.tree.as.IASNode;
import org.apache.royale.compiler.tree.as.IExpressionNode;
import org.apache.royale.compiler.tree.as.IIdentifierNode;
import flash.tools.debugger.concrete.DValue;
/**
* Reducer for the debugger - equivalent to the old DebuggerEvaluator
*/
public class AS3DebuggerReducer {
private final ContextStack contextStack;
private final ICompilerProject project;
public static class ContextStack {
private final List ctxStckInternal;
public ContextStack(Context context) {
ctxStckInternal = new ArrayList();
pushScope(context);
}
public Context scope(int i) {
return ctxStckInternal.get(i);
}
public void pushScope(Context scope) {
ctxStckInternal.add(scope);
}
public void popScope() {
assert (!ctxStckInternal.isEmpty());
ctxStckInternal.remove(ctxStckInternal.size() - 1);
}
public Context scope() {
return ctxStckInternal.get(ctxStckInternal.size() - 1);
}
}
public AS3DebuggerReducer(Context context, ICompilerProject project) {
super();
this.contextStack = new ContextStack(context);
this.project = project;
}
static final int ERROR_TRAP = 268435456;
// TODO: IMPORTANT, SET IT TO FALSE BEFORE COMMIT or it won't work in IntelliJ.
private boolean hookallreducercalls = false;
private void hookforreducercalls(String name)
{
System.out.println(name);
}
private Object callFunction(Context cx, boolean isConstructor,
Object function, Object[] args) throws PlayerDebugException {
if (hookallreducercalls)
hookforreducercalls("callFunction");
Session session = cx.getSession();
flash.tools.debugger.Value thisObject = cx.toValue();
if (thisObject == null)
thisObject = DValue.forPrimitive(null, cx.getIsolateId());
flash.tools.debugger.Value[] valueArgs = new flash.tools.debugger.Value[args.length];
for (int i = 0; i < args.length; ++i) {
/**
* context.toValue() may return null while
* PlayerSession::buildCallFunctionMessage expects the Value to be a
* value that depicts null. For example,
* xmlVar.childNode[nonexistentornullvar] will run into this case.
* (Came to notice via bug FB-25660)
*/
flash.tools.debugger.Value tempValue = cx.toValue(args[i]);
if (tempValue == null) {
tempValue = DValue.forPrimitive(null, cx.getIsolateId());
}
valueArgs[i] = tempValue;
}
String functionName;
if (function instanceof Variable) {
// Sometimes, the function will show up as a Variable. This happens,
// for example, if the user wrote "MyClass.myFunction = function() {
// ... }";
// String.fromCharCode(), for example, is defined that way.
functionName = ((Variable) function).getQualifiedName();
} else {
functionName = function.toString();
}
IsolateSession workerSession = session.getWorkerSession(cx
.getIsolateId());
if (isConstructor)
{
return ((IsolateController) session).callConstructorWorker(functionName, valueArgs, thisObject.getIsolateId());
}
else
{
return ((IsolateController) session).callFunctionWorker(thisObject, functionName, valueArgs, thisObject.getIsolateId());
}
}
Object compoundBinaryAssignmentBracketExpr(IASNode iNode, Object stem,
Object index, Object r, int opcode) {
if (hookallreducercalls)
hookforreducercalls("compoundBinaryAssignmentBracketExpr");
Object leftVariable = reduce_arrayIndexExpr(iNode, stem, false, index);
DebuggerValue operationValue = (DebuggerValue) binaryOp(iNode,
leftVariable, r, opcode);
return reduce_assignToBracketExpr_to_expression(iNode, stem, index,
operationValue, false);
}
Object compoundBinaryAssignmentMemberExpr(IASNode iNode, Object stem,
Object member, Object r, int opcode) {
if (hookallreducercalls)
hookforreducercalls("compoundBinaryAssignmentMemberExpr");
Object leftVariable = reduce_memberAccessExpr(iNode, stem, member, -1);
DebuggerValue operationValue = (DebuggerValue) binaryOp(iNode,
leftVariable, r, opcode);
return reduce_assignToMemberExpr_to_expression(iNode, stem, member,
operationValue);
}
Object compoundBinaryAssignmentNameExpr(IASNode iNode, Object l, Object r,
int opcode) {
if (hookallreducercalls)
hookforreducercalls("compoundBinaryAssignmentNameExpr");
Object leftVariable = transform_name_to_expression(iNode, l);
DebuggerValue operationValue = (DebuggerValue) binaryOp(iNode,
leftVariable, r, opcode);
return reduce_assignToNameExpr_to_expression(iNode, l, operationValue);
}
/**
* Generate a binary operator.
*
* @param l
* - the left-hand operand.
* @param r
* - the right-hand operand.
* @param opcode
* - the operator's opcode.
* @return the combined instruction sequence with the operator appended.
*/
Object binaryOp(IASNode iNode, Object l, Object r, int opcode) {
if (hookallreducercalls)
hookforreducercalls("binaryOp");
// REFER : ASC : public Value evaluate(macromedia.asc.util.Context cx,
// BinaryExpressionNode node)
switch (opcode) {
case ABCConstants.OP_add:
break;
}
DebuggerValue lhs = (DebuggerValue) l;
DebuggerValue rhs = (DebuggerValue) r;
Context eeContext = contextStack.scope();
Session session = eeContext.getSession();
switch (opcode) {
case ABCConstants.OP_multiply: {
// ECMA 11.5
double d1 = ECMA.toNumber(session,
eeContext.toValue(lhs.debuggerValue));
double d2 = ECMA.toNumber(session,
eeContext.toValue(rhs.debuggerValue));
return new DebuggerValue(Double.valueOf(d1 * d2));
}
case ABCConstants.OP_divide: {
// ECMA 11.5
double d1 = ECMA.toNumber(session,
eeContext.toValue(lhs.debuggerValue));
double d2 = ECMA.toNumber(session,
eeContext.toValue(rhs.debuggerValue));
return new DebuggerValue(Double.valueOf(d1 / d2));
}
case ABCConstants.OP_modulo: {
// ECMA 11.5
double d1 = ECMA.toNumber(session,
eeContext.toValue(lhs.debuggerValue));
double d2 = ECMA.toNumber(session,
eeContext.toValue(rhs.debuggerValue));
return new DebuggerValue(Double.valueOf(d1 % d2));
}
case ABCConstants.OP_add: {
// E4X 11.4.1 and ECMA 11.6.1
flash.tools.debugger.Value v1 = eeContext
.toValue(lhs.debuggerValue);
flash.tools.debugger.Value v2 = eeContext
.toValue(rhs.debuggerValue);
boolean isXMLConcat = false;
if (v1.getType() == VariableType.OBJECT
&& v2.getType() == VariableType.OBJECT) {
String type1 = v1.getTypeName();
String type2 = v2.getTypeName();
int at;
at = type1.indexOf('@');
if (at != -1)
type1 = type1.substring(0, at);
at = type2.indexOf('@');
if (at != -1)
type2 = type2.substring(0, at);
if (type1.equals("XML") || type1.equals("XMLList")) //$NON-NLS-1$ //$NON-NLS-2$
if (type2.equals("XML") || type2.equals("XMLList")) //$NON-NLS-1$ //$NON-NLS-2$
isXMLConcat = true;
}
if (isXMLConcat) {
try {
IsolateSession workerSession = session.getWorkerSession(v1
.getIsolateId());
flash.tools.debugger.Value xml1 = workerSession
.callFunction(
v1,
"toXMLString", new flash.tools.debugger.Value[0]); //$NON-NLS-1$
flash.tools.debugger.Value xml2 = session.getWorkerSession(
v2.getIsolateId()).callFunction(v2,
"toXMLString", new flash.tools.debugger.Value[0]); //$NON-NLS-1$
String allXML = xml1.getValueAsString()
+ xml2.getValueAsString();
flash.tools.debugger.Value allXMLValue = DValue
.forPrimitive(allXML, v1.getIsolateId());
flash.tools.debugger.Value retval = workerSession
.callConstructor(
"XMLList", new flash.tools.debugger.Value[] { allXMLValue }); //$NON-NLS-1$
return new DebuggerValue(retval);
} catch (PlayerDebugException e) {
throw new ExpressionEvaluatorException(e);
}
} else {
v1 = ECMA.toPrimitive(session, v1, null,
eeContext.getIsolateId());
v2 = ECMA.toPrimitive(session, v2, null,
eeContext.getIsolateId());
if (v1.getType() == VariableType.STRING
|| v2.getType() == VariableType.STRING) {
return new DebuggerValue(ECMA.toString(session, v1)
+ ECMA.toString(session, v2));
} else {
return new DebuggerValue(Double.valueOf(ECMA.toNumber(session,
v1) + ECMA.toNumber(session, v2)));
}
}
}
case ABCConstants.OP_subtract: {
// ECMA 11.6.2
double d1 = ECMA.toNumber(session,
eeContext.toValue(lhs.debuggerValue));
double d2 = ECMA.toNumber(session,
eeContext.toValue(rhs.debuggerValue));
return new DebuggerValue(Double.valueOf(d1 - d2));
}
case ABCConstants.OP_lshift: {
// ECMA 11.7.1
int n1 = ECMA
.toInt32(session, eeContext.toValue(lhs.debuggerValue));
int n2 = (int) (ECMA.toUint32(session,
eeContext.toValue(rhs.debuggerValue)) & 0x1F);
return new DebuggerValue(Double.valueOf(n1 << n2));
}
case ABCConstants.OP_rshift: {
// ECMA 11.7.1
int n1 = ECMA
.toInt32(session, eeContext.toValue(lhs.debuggerValue));
int n2 = (int) (ECMA.toUint32(session,
eeContext.toValue(rhs.debuggerValue)) & 0x1F);
return new DebuggerValue(Double.valueOf(n1 >> n2));
}
case ABCConstants.OP_urshift: {
// ECMA 11.7.1
long n1 = ECMA.toUint32(session,
eeContext.toValue(lhs.debuggerValue));
long n2 = (ECMA.toUint32(session,
eeContext.toValue(rhs.debuggerValue)) & 0x1F);
return new DebuggerValue(Double.valueOf(n1 >>> n2));
}
case ABCConstants.OP_lessthan: {
// ECMA 11.8.1
flash.tools.debugger.Value lessThan = ECMA.lessThan(session,
eeContext.toValue(lhs.debuggerValue),
eeContext.toValue(rhs.debuggerValue));
boolean result;
if (lessThan.getType() == VariableType.UNDEFINED) {
result = false;
} else {
result = ECMA.toBoolean(lessThan);
}
return new DebuggerValue(result);
}
case ABCConstants.OP_greaterthan: {
// ECMA 11.8.2
flash.tools.debugger.Value greaterThan = ECMA.lessThan(session,
eeContext.toValue(rhs.debuggerValue),
eeContext.toValue(lhs.debuggerValue));
boolean result;
if (greaterThan.getType() == VariableType.UNDEFINED) {
result = false;
} else {
result = ECMA.toBoolean(greaterThan);
}
return new DebuggerValue(result);
}
case ABCConstants.OP_lessequals: {
// ECMA 11.8.3
flash.tools.debugger.Value lessThan = ECMA.lessThan(session,
eeContext.toValue(rhs.debuggerValue),
eeContext.toValue(lhs.debuggerValue));
boolean result;
if (lessThan.getType() == VariableType.UNDEFINED) {
result = false;
} else {
result = !ECMA.toBoolean(lessThan);
}
return new DebuggerValue(result);
}
case ABCConstants.OP_greaterequals: {
// ECMA 11.8.4
flash.tools.debugger.Value lessThan = ECMA.lessThan(session,
eeContext.toValue(lhs.debuggerValue),
eeContext.toValue(rhs.debuggerValue));
boolean result;
if (lessThan.getType() == VariableType.UNDEFINED) {
result = false;
} else {
result = !ECMA.toBoolean(lessThan);
}
return new DebuggerValue(result);
}
case ABCConstants.OP_instanceof: {
try {
return new DebuggerValue(session.getWorkerSession(
eeContext.getIsolateId()).evalInstanceof(
eeContext.toValue(lhs.debuggerValue),
eeContext.toValue(rhs.debuggerValue)));
} catch (PlayerDebugException e) {
throw new ExpressionEvaluatorException(e);
} catch (PlayerFaultException e) {
throw new ExpressionEvaluatorException(e);
}
}
case ABCConstants.OP_in: {
try {
return new DebuggerValue(session.getWorkerSession(
eeContext.getIsolateId()).evalIn(
eeContext.toValue(lhs.debuggerValue),
eeContext.toValue(rhs.debuggerValue)));
} catch (PlayerDebugException e) {
throw new ExpressionEvaluatorException(e);
} catch (PlayerFaultException e) {
throw new ExpressionEvaluatorException(e);
}
}
case ABCConstants.OP_istypelate: {
try {
return new DebuggerValue(session.getWorkerSession(
eeContext.getIsolateId()).evalIs(
eeContext.toValue(lhs.debuggerValue),
eeContext.toValue(rhs.debuggerValue)));
} catch (PlayerDebugException e) {
throw new ExpressionEvaluatorException(e);
} catch (PlayerFaultException e) {
throw new ExpressionEvaluatorException(e);
}
}
case ABCConstants.OP_astypelate: {
try {
return new DebuggerValue(session.getWorkerSession(
eeContext.getIsolateId()).evalAs(
eeContext.toValue(lhs.debuggerValue),
eeContext.toValue(rhs.debuggerValue)));
} catch (PlayerDebugException e) {
throw new ExpressionEvaluatorException(e);
} catch (PlayerFaultException e) {
throw new ExpressionEvaluatorException(e);
}
}
case ABCConstants.OP_equals: {
// ECMA 11.9.1
return new DebuggerValue(Boolean.valueOf(ECMA.equals(session,
eeContext.toValue(lhs.debuggerValue),
eeContext.toValue(rhs.debuggerValue))));
}
// ASC3 notequals is a sepearate reducer nequals
// case ABCConstants.op_Tokens.NOTEQUALS_TOKEN:
// {
// // ECMA 11.9.2
// return new DebuggerValue(Boolean.valueOf(!ECMA.equals(session,
// eeContext.toValue(lhs.debuggerValue), eeContext
// .toValue(rhs.debuggerValue))));
// }
case ABCConstants.OP_strictequals: {
// ECMA 11.9.4
return new DebuggerValue(Boolean.valueOf(ECMA.strictEquals(
eeContext.toValue(lhs.debuggerValue),
eeContext.toValue(rhs.debuggerValue))));
}
// ASC3 notequals is a sepearate reducer nequals
/*
* case Tokens.STRICTNOTEQUALS_TOKEN: { // ECMA 11.9.5 return new
* DebuggerValue(new
* Boolean(!ECMA.strictEquals(eeContext.toValue(lhs.debuggerValue),
* eeContext .toValue(rhs.debuggerValue)))); }
*/
case ABCConstants.OP_bitand: {
// ECMA 11.10
return new DebuggerValue(Double.valueOf(ECMA.toInt32(session,
eeContext.toValue(lhs.debuggerValue))
& ECMA.toInt32(session,
eeContext.toValue(rhs.debuggerValue))));
}
case ABCConstants.OP_bitxor: {
// ECMA 11.10
return new DebuggerValue(Double.valueOf(ECMA.toInt32(session,
eeContext.toValue(lhs.debuggerValue))
^ ECMA.toInt32(session,
eeContext.toValue(rhs.debuggerValue))));
}
case ABCConstants.OP_bitor: {
// ECMA 11.10
return new DebuggerValue(Double.valueOf(ECMA.toInt32(session,
eeContext.toValue(lhs.debuggerValue))
| ECMA.toInt32(session,
eeContext.toValue(rhs.debuggerValue))));
}
/*
* ASC3 reduce_logicalAndExpr & reduce_logicalOrExpr sepearate reducers
* case Tokens.LOGICALAND_TOKEN: { // ECMA 11.11
* flash.tools.debugger.Value result =
* eeContext.toValue(lhs.debuggerValue); if (ECMA.toBoolean(result)) {
* rhs = (DebuggerValue) node.rhs.evaluate(cx, this); result =
* eeContext.toValue(rhs.debuggerValue); } return new
* DebuggerValue(result); } case Tokens.LOGICALOR_TOKEN: { // ECMA 11.11
* flash.tools.debugger.Value result =
* eeContext.toValue(lhs.debuggerValue); if (!ECMA.toBoolean(result)) {
* rhs = (DebuggerValue) node.rhs.evaluate(cx, this); result =
* eeContext.toValue(rhs.debuggerValue); } return new
* DebuggerValue(result); }
*/
// case Tokens.EMPTY_TOKEN:
// // do nothing, already been folded
// return new DebuggerValue(null);
default:
//cx.internalError(ASTBuilder.getLocalizationManager().getLocalizedTextString("unrecognizedBinaryOperator")); //$NON-NLS-1$
return new DebuggerValue(null);
}
}
/**
* Resolve a dotted name, e.g., foo.bar.baz
*/
Object dottedName(IASNode iNode, String qualifiers, String base_name) {
if (hookallreducercalls)
hookforreducercalls("dottedName");
return qualifiers + "." + base_name;
}
/**
* Error trap.
*/
public Object error_namespaceAccess(IASNode iNode, IASNode raw_qualifier,
Object qualified_name) {
if (hookallreducercalls)
hookforreducercalls("error_namespaceAccess");
return null;
}
/**
* Error trap.
*/
public Object error_reduce_Op_AssignId(IASNode iNode, Object non_lvalue,
Object rvalue) {
if (hookallreducercalls)
hookforreducercalls("error_reduce_Op_AssignId");
return null;
}
/**
* @return the double content of a numeric literal.
* @param iNode
* - the literal node.
*/
Double getDoubleContent(IASNode iNode) {
if (hookallreducercalls)
hookforreducercalls("getDoubleContent");
return SemanticUtils.getDoubleContent(iNode);
}
/**
* @return the double content of a numeric literal.
* @param iNode
* - the literal node.
*/
Float getFloatContent(IASNode iNode) {
if (hookallreducercalls)
hookforreducercalls("getFloatContent");
//return SemanticUtils.getFloatContent(iNode);
return null;
}
/**
* @return the name of an identifier.
* @param iNode
* - the IIdentifier node.
*/
String getIdentifierContent(IASNode iNode) {
if (hookallreducercalls)
hookforreducercalls("getIdentifierContent");
return SemanticUtils.getIdentifierContent(iNode);
}
/**
* @return the int content of a numeric literal.
* @param iNode
* - the literal node.
*/
Integer getIntegerContent(IASNode iNode) {
if (hookallreducercalls)
hookforreducercalls("getIntegerContent");
return SemanticUtils.getIntegerContent(iNode);
}
/**
* @return always zero.
* @param iNode
* - the literal node.
*/
Integer getIntegerZeroContent(IASNode iNode) {
if (hookallreducercalls)
hookforreducercalls("getIntegerZeroContent");
return 0;
}
/**
* @return always zero.
* @param iNode
* - the literal node.
*/
Long getIntegerZeroContentAsLong(IASNode iNode) {
if (hookallreducercalls)
hookforreducercalls("getIntegerZeroContentAsLong");
return 0L;
}
/**
* @return the string content of a literal.
* @param iNode
* - the literal node.
*/
String getStringLiteralContent(IASNode iNode) {
if (hookallreducercalls)
hookforreducercalls("getStringLiteralContent");
return SemanticUtils.getStringLiteralContent(iNode);
}
/**
* @return the uint content of a numeric literal.
* @param iNode
* - the literal node.
*/
Long getUintContent(IASNode iNode) {
if (hookallreducercalls)
hookforreducercalls("getUintContent");
return SemanticUtils.getUintContent(iNode);
}
/*
* *******************************
* ** Cost/Decision Functions ** *******************************
*/
public int isIntLiteral(IASNode iNode) {
if (hookallreducercalls)
hookforreducercalls("isIntLiteral");
if (iNode.getNodeID() == ASTNodeID.LiteralNumberID) {
INumericValue numericVal = ((NumericLiteralNode) iNode)
.getNumericValue();
if (numericVal.getAssumedType() == IASLanguageConstants.BuiltinType.INT) {
return 1;
}
}
return Integer.MAX_VALUE;
}
public int isUintLiteral(IASNode iNode) {
if (hookallreducercalls)
hookforreducercalls("isUintLiteral");
if (iNode.getNodeID() == ASTNodeID.LiteralNumberID) {
INumericValue numericVal = ((NumericLiteralNode) iNode)
.getNumericValue();
if (numericVal.getAssumedType() == IASLanguageConstants.BuiltinType.UINT) {
return 1;
}
}
return Integer.MAX_VALUE;
}
public int isDoubleLiteral(IASNode iNode) {
if (hookallreducercalls)
hookforreducercalls("isDoubleLiteral");
if (iNode.getNodeID() == ASTNodeID.LiteralDoubleID) {
return 2;
}
return Integer.MAX_VALUE;
}
/*
public int isFloatLiteral(IASNode iNode) {
if (iNode.getNodeID() == ASTNodeID.LiteralNumberID) {
INumericValue numericVal = ((NumericLiteralNode) iNode)
.getNumericValue();
if (numericVal.getAssumedType() == IASLanguageConstants.BuiltinType.NUMBER) {
return 1;
}
return Integer.MAX_VALUE;
}
return Integer.MAX_VALUE;
}
*/
/**
* Explore a MemberAccessNode and decide if its stem is a reference to a
* package. This method will always return a result greater than what
* isPackageName will return, as package name must "win" over dotted name.
*/
int isDottedName(IASNode n) {
if (hookallreducercalls)
hookforreducercalls("isDottedName");
int result = Integer.MAX_VALUE;
if (n instanceof MemberAccessExpressionNode) {
MemberAccessExpressionNode ma = (MemberAccessExpressionNode) n;
if (ma.stemIsPackage())
// This needs to be greater than the value returned from
// isPackageName,
// so that isPackageName wins
result = 2;
}
return result;
}
/**
* Explore a MemberAccessNode and decide if it is a reference to a package.
* This method will always return a result less than what isDottedName will
* return, as package name must "win" over dotted name.
*/
int isPackageName(IASNode n) {
if (hookallreducercalls)
hookforreducercalls("isPackageName");
int result = Integer.MAX_VALUE;
if (n instanceof MemberAccessExpressionNode) {
MemberAccessExpressionNode ma = (MemberAccessExpressionNode) n;
if (ma.isPackageReference())
// This needs to be less than the value returned from
// isDottedName,
// so that isPackageName wins
result = 1;
}
return result;
}
/**
* Get the definition associated with a node's qualifier and decide if the
* qualifier is a compile-time constant.
*
* @param iNode
* - the node to check.
* @pre - the node has an IdentifierNode 0th child.
* @return an attractive cost if the child has a known namespace, i.e., it's
* a compile-time constant qualifier.
*/
int qualifierIsCompileTimeConstant(IASNode iNode) {
if (hookallreducercalls)
hookforreducercalls("qualifierIsCompileTimeConstant");
IdentifierNode qualifier = (IdentifierNode) SemanticUtils
.getNthChild(iNode, 0);
IDefinition def = qualifier.resolve(project);
int result = def instanceof NamespaceDefinition ? 1 : Integer.MAX_VALUE;
return result;
}
/**
* @return a feasible cost if a node has a compile-time constant defintion.
*/
int isCompileTimeConstant(IASNode iNode) {
if (hookallreducercalls)
hookforreducercalls("isCompileTimeConstant");
if (SemanticUtils.transformNameToConstantValue(iNode, project) != null)
return 1;
else
return Integer.MAX_VALUE;
}
/**
* @return a feasible cost if a node has a compile-time constant defintion.
*/
int isCompileTimeConstantFunction(IASNode iNode) {
if (hookallreducercalls)
hookforreducercalls("isCompileTimeConstantFunction");
IDefinition def = ((IdentifierNode)iNode).resolve(project);
if (SemanticUtils.isConstDefinition(def))
return 1;
else
return Integer.MAX_VALUE;
}
/**
* @return a feasible cost if the parameterized type's base and parameter
* types are compile-time constants, ERROR_TRAP if not.
*/
int parameterTypeIsConstant(IASNode iNode) {
if (hookallreducercalls)
hookforreducercalls("parameterTypeIsConstant");
return Math.max(isKnownType(SemanticUtils.getNthChild(iNode, 0)),
isKnownType(SemanticUtils.getNthChild(iNode, 1)));
}
/**
* @return a feasible cost if the given node is a known type, ERROR_TRAP
* otherwise.
*/
int isKnownType(IASNode iNode) {
if (hookallreducercalls)
hookforreducercalls("isKnownType");
boolean isConstant = false;
if (iNode instanceof IExpressionNode) {
isConstant = ((IExpressionNode) iNode).resolve(project) instanceof ITypeDefinition;
}
return isConstant ? 1 : ERROR_TRAP;
}
/**
* Reduce a function call to a constant value. This is only possible for a
* limited set of function calls, and you should call
* isCompileTimeConstantFunction first to make sure this is possible.
*
* @param iNode
* the IFunctionCallNode
* @param method
* the Object of the method to call
* @param constant_args
* the constant_values used as arguments to the function call
* @return A constant value that that would be the result of calling the
* function at runtime with the specified arguments
*/
public Object transform_constant_function_to_value(IASNode iNode,
Object method, Vector