/** * Does the given node have an explicit stem reference, e.g., foo.bar? * @param iNode - the node of interest. * @return true if the node has an explicit stem (the foo in foo.bar). * @see #hasUnderlyingType which checks for explicit or implicit contexts for resolution. */ public static boolean hasExplicitStem(IASNode iNode) { return ( iNode instanceof MemberAccessExpressionNode ) || ( iNode instanceof FunctionCallNode && ((FunctionCallNode)iNode).getNameNode() instanceof MemberAccessExpressionNode ); }
public static boolean injectThisArgument(FunctionCallNode node, boolean allowMembers) { // if super isSuper checks the nameNode if (node.isSuperExpression() && !node.isNewExpression()) return true; ExpressionNodeBase base = node.getNameNode(); if (base.getNodeID() == ASTNodeID.IdentifierID) return false; if (allowMembers && base instanceof IMemberAccessExpressionNode) { // foo.super() IMemberAccessExpressionNode mnode = (IMemberAccessExpressionNode) base; if (mnode.getLeftOperandNode().getNodeID() == ASTNodeID.SuperID) return true; } return false; }
@Override protected FunctionCallNode copy() { return new FunctionCallNode(this); }
((FunctionCallNode)n).isNewExpression(); final boolean newFunctionCallAlreadyHasArgs = isNewExpression && ((FunctionCallNode)n).getArgumentsNode().getStart() != -1; n = new FunctionCallNode(n); if (newFunctionCallAlreadyHasArgs) { ((FunctionCallNode)n).setNewKeywordNode(oldNode.getNewKeywordNode()); oldNode.setNewKeywordNode(null); args = ((FunctionCallNode)n).getArgumentsNode(); args.startBefore(lpT); args.endAfter(lpT);
/** * Check if the node is for {@code super(this)} but not * {@code super(this).call()}. The incoming tree shape is: * * <pre> * MemberAccessExpressionID(FunctionCallID(SuperID(void), ContainerID(IdentifierID(void))), qname) * </pre> * * @return "0" if the node represents {@code super(this)}; * {@link Integer#MAX_VALUE} otherwise. */ public static int isSuperThisForFieldAccess(IASNode n) { // super(this).callSomething() is handled by another pattern that emits // "callsuper" instruction. if (n.getParent() instanceof FunctionCallNode) return Integer.MAX_VALUE; // The following unguarded casts are safe, because this is a cost // function and the pattern matcher has checked all the node IDs. final MemberAccessExpressionNode memberAccessNode = (MemberAccessExpressionNode)n; final FunctionCallNode callNode = (FunctionCallNode)memberAccessNode.getLeftOperandNode(); final IdentifierNode idNode = (IdentifierNode)callNode.getArgumentsNode().getChild(0); if (idNode.getName().equals(IASKeywordConstants.THIS)) return 1; else return Integer.MAX_VALUE; }
@Override public ITypeDefinition resolveType(ICompilerProject project) { IDefinition calledFunction = this.nameNode.resolve(project); if (calledFunction instanceof IFunctionDefinition && // call of an accessor is just like call of a var !(calledFunction instanceof IAccessorDefinition)) { // new foo() returns the * type if (getNewKeywordNode() != null) return project.getBuiltinType(BuiltinType.ANY_TYPE); else return ((IFunctionDefinition)calledFunction).resolveReturnType(project); } else if (calledFunction instanceof ITypeDefinition) { // The Date(...) function returns a String. if (!isNewExpression() && calledFunction.getQualifiedName().equals(IASLanguageConstants.Date)) return project.getBuiltinType(BuiltinType.STRING); // Call of a class or interface - a cast - so the Type of the expression is the called class // should only have 1 argument, but semantics will check that return (ITypeDefinition)calledFunction; } // If we are anything else (var, accessor, etc) // or unknown (didn't resolve), then the result of the // call is '*' as far as the compiler is concerned. return project.getBuiltinType(BuiltinType.ANY_TYPE); }
FunctionCallNode superCall = new FunctionCallNode(LanguageIdentifierNode.buildSuper()); constructorContents.addItem(superCall); FunctionCallNode newBytes = new FunctionCallNode(newToken, new IdentifierNode(byteArrayClassName)); FunctionCallNode byteArrayCall = new FunctionCallNode(new IdentifierNode("ByteArray")); ContainerNode args = byteArrayCall.getArgumentsNode(); args.addItem(newBytes); BinaryOperatorNodeBase assignmentBytes = BinaryOperatorNodeBase.create(assignToken, new IdentifierNode("bytes"), byteArrayCall);
/** * Copy constructor. * * @param other The node to copy. */ protected FunctionCallNode(FunctionCallNode other) { super(other); this.newKeywordNode = other.newKeywordNode != null ? new KeywordNode(other.newKeywordNode) : null; this.nameNode = other.nameNode != null ? other.nameNode.copy() : null; this.argumentsNode = new ContainerNode(other.argumentsNode.getChildCount()); for (IExpressionNode arg : other.getArgumentNodes()) { argumentsNode.addItem(((ExpressionNodeBase)arg).copy()); } }
@Override public boolean isCallToSuper() { return nameNode instanceof ILanguageIdentifierNode && nameNode.getAncestorOfType(ClassNode.class) != null && ((ILanguageIdentifierNode)nameNode).getKind() == LanguageIdentifierKind.SUPER && nameNode.getAncestorOfType(MemberAccessExpressionNode.class) == null && getAncestorOfType(FunctionNode.class) != null; } }
@Override public IASNode getChild(int i) { if (i > getChildCount()) return null; if (i == 0) { if (newKeywordNode != null) return newKeywordNode; return nameNode != null ? nameNode : argumentsNode; } else if (i == 1) { return newKeywordNode != null ? nameNode : argumentsNode; } else if (i == 2) { return argumentsNode; } return null; }
String fname = fcn.getFunctionName(); if (fname.equals("XML") || fname.equals("XMLList")) return true;
((FunctionCallNode)n).isNewExpression(); final boolean newFunctionCallAlreadyHasArgs = isNewExpression && ((FunctionCallNode)n).getArgumentsNode().getStart() != -1; n = new FunctionCallNode(n); if (newFunctionCallAlreadyHasArgs) { ((FunctionCallNode)n).setNewKeywordNode(oldNode.getNewKeywordNode()); oldNode.setNewKeywordNode(null); args = ((FunctionCallNode)n).getArgumentsNode(); args.startBefore(lpT); args.endAfter(lpT);
/** * Check if the node is for {@code super(this)} but not * {@code super(this).call()}. The incoming tree shape is: * * <pre> * MemberAccessExpressionID(FunctionCallID(SuperID(void), ContainerID(IdentifierID(void))), qname) * </pre> * * @return "0" if the node represents {@code super(this)}; * {@link Integer#MAX_VALUE} otherwise. */ public static int isSuperThisForFieldAccess(IASNode n) { // super(this).callSomething() is handled by another pattern that emits // "callsuper" instruction. if (n.getParent() instanceof FunctionCallNode) return Integer.MAX_VALUE; // The following unguarded casts are safe, because this is a cost // function and the pattern matcher has checked all the node IDs. final MemberAccessExpressionNode memberAccessNode = (MemberAccessExpressionNode)n; final FunctionCallNode callNode = (FunctionCallNode)memberAccessNode.getLeftOperandNode(); final IdentifierNode idNode = (IdentifierNode)callNode.getArgumentsNode().getChild(0); if (idNode.getName().equals(IASKeywordConstants.THIS)) return 1; else return Integer.MAX_VALUE; }
@Override public ITypeDefinition resolveType(ICompilerProject project) { IDefinition calledFunction = this.nameNode.resolve(project); if (calledFunction instanceof IFunctionDefinition && // call of an accessor is just like call of a var !(calledFunction instanceof IAccessorDefinition)) { // new foo() returns the * type if (getNewKeywordNode() != null) return project.getBuiltinType(BuiltinType.ANY_TYPE); else return ((IFunctionDefinition)calledFunction).resolveReturnType(project); } else if (calledFunction instanceof ITypeDefinition) { // The Date(...) function returns a String. if (!isNewExpression() && calledFunction.getQualifiedName().equals(IASLanguageConstants.Date)) return project.getBuiltinType(BuiltinType.STRING); // Call of a class or interface - a cast - so the Type of the expression is the called class // should only have 1 argument, but semantics will check that return (ITypeDefinition)calledFunction; } // If we are anything else (var, accessor, etc) // or unknown (didn't resolve), then the result of the // call is '*' as far as the compiler is concerned. return project.getBuiltinType(BuiltinType.ANY_TYPE); }
FunctionCallNode superCall = new FunctionCallNode(LanguageIdentifierNode.buildSuper()); constructorContents.addItem(superCall); FunctionCallNode newBytes = new FunctionCallNode(newToken, new IdentifierNode(byteArrayClassName)); FunctionCallNode byteArrayCall = new FunctionCallNode(new IdentifierNode("ByteArray")); ContainerNode args = byteArrayCall.getArgumentsNode(); args.addItem(newBytes); BinaryOperatorNodeBase assignmentBytes = BinaryOperatorNodeBase.create(assignToken, new IdentifierNode("bytes"), byteArrayCall);
/** * Copy constructor. * * @param other The node to copy. */ protected FunctionCallNode(FunctionCallNode other) { super(other); this.newKeywordNode = other.newKeywordNode != null ? new KeywordNode(other.newKeywordNode) : null; this.nameNode = other.nameNode != null ? other.nameNode.copy() : null; this.argumentsNode = new ContainerNode(other.argumentsNode.getChildCount()); for (IExpressionNode arg : other.getArgumentNodes()) { argumentsNode.addItem(((ExpressionNodeBase)arg).copy()); } }
@Override public boolean isCallToSuper() { return nameNode instanceof ILanguageIdentifierNode && nameNode.getAncestorOfType(ClassNode.class) != null && ((ILanguageIdentifierNode)nameNode).getKind() == LanguageIdentifierKind.SUPER && nameNode.getAncestorOfType(MemberAccessExpressionNode.class) == null && getAncestorOfType(FunctionNode.class) != null; } }
@Override public IASNode getChild(int i) { if (i > getChildCount()) return null; if (i == 0) { if (newKeywordNode != null) return newKeywordNode; return nameNode != null ? nameNode : argumentsNode; } else if (i == 1) { return newKeywordNode != null ? nameNode : argumentsNode; } else if (i == 2) { return argumentsNode; } return null; }
/** * Does the given node have an explicit stem reference, e.g., foo.bar? * @param iNode - the node of interest. * @return true if the node has an explicit stem (the foo in foo.bar). * @see #hasUnderlyingType which checks for explicit or implicit contexts for resolution. */ public static boolean hasExplicitStem(IASNode iNode) { return ( iNode instanceof MemberAccessExpressionNode ) || ( iNode instanceof FunctionCallNode && ((FunctionCallNode)iNode).getNameNode() instanceof MemberAccessExpressionNode ); }
if (left instanceof FunctionCallNode) // probably a cast IASNode child = ((FunctionCallNode)left).getArgumentsNode().getChild(0); if (child instanceof IdentifierNode) s = getSourceStringFromIdentifierNode((IdentifierNode)child); if (right instanceof FunctionCallNode) // probably a cast IASNode child = ((FunctionCallNode)right).getArgumentsNode().getChild(0); if (child instanceof IdentifierNode) s += getSourceStringFromIdentifierNode((IdentifierNode)child);