@Override public IExpressionNode[] getConditionalExpressionNodes() { int childCount = conditionsStatementsNode.getChildCount(); ArrayList<IExpressionNode> retVal = new ArrayList<IExpressionNode>(3); for (int i = 0; i < childCount; i++) { IASNode child = conditionsStatementsNode.getChild(i); if (child instanceof IExpressionNode) retVal.add((IExpressionNode)child); } return retVal.toArray(new IExpressionNode[0]); }
/** * Find the iterator {@code VariableNode} in a {@code ForLoopNode}. * * <pre> * for (var it : String = "hello" in array) {...} * for each (var it : String = "hello" in array) {...} * </pre> * * @param for_loop_node "for" loop node. * @return {@code VariableNode} of the iterator variable. */ private static VariableNode findIteratorVariable(final ForLoopNode for_loop_node) { assert for_loop_node != null : "'for' loop node can't be null"; final IASNode conditionalStatement = for_loop_node.getConditionalsContainerNode().getChild(0); final BinaryOperatorInNode in_node = (BinaryOperatorInNode)conditionalStatement; final VariableExpressionNode var_expr_node = (VariableExpressionNode)in_node.getLeftOperandNode(); final VariableNode var_node = (VariableNode)var_expr_node.getChild(0); return var_node; }
@Override public IExpressionNode[] getConditionalExpressionNodes() { int childCount = conditionsStatementsNode.getChildCount(); ArrayList<IExpressionNode> retVal = new ArrayList<IExpressionNode>(3); for (int i = 0; i < childCount; i++) { IASNode child = conditionsStatementsNode.getChild(i); if (child instanceof IExpressionNode) retVal.add((IExpressionNode)child); } return retVal.toArray(new IExpressionNode[0]); }
/** * Find the iterator {@code VariableNode} in a {@code ForLoopNode}. * * <pre> * for (var it : String = "hello" in array) {...} * for each (var it : String = "hello" in array) {...} * </pre> * * @param for_loop_node "for" loop node. * @return {@code VariableNode} of the iterator variable. */ private static VariableNode findIteratorVariable(final ForLoopNode for_loop_node) { assert for_loop_node != null : "'for' loop node can't be null"; final IASNode conditionalStatement = for_loop_node.getConditionalsContainerNode().getChild(0); final BinaryOperatorInNode in_node = (BinaryOperatorInNode)conditionalStatement; final VariableExpressionNode var_expr_node = (VariableExpressionNode)in_node.getLeftOperandNode(); final VariableNode var_node = (VariableNode)var_expr_node.getChild(0); return var_node; }
@Override public IParameterNode[] getParameterNodes() { IParameterNode[] variables = {}; ContainerNode arguments = contentsPart.getParametersNode(); if (arguments != null) { int argumentscount = arguments.getChildCount(); variables = new IParameterNode[argumentscount]; for (int i = 0; i < argumentscount; i++) { IASNode argument = arguments.getChild(i); if (argument instanceof IParameterNode) variables[i] = (IParameterNode)argument; } } return variables; }
/** * 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 IExpressionNode[] getArgumentNodes() { ArrayList<IExpressionNode> retVal = new ArrayList<IExpressionNode>(); if (argumentsNode != null) { int childCount = argumentsNode.getChildCount(); for (int i = 0; i < childCount; i++) { IASNode child = argumentsNode.getChild(i); if (child instanceof IExpressionNode) { retVal.add((IExpressionNode)child); } } } return retVal.toArray(new IExpressionNode[0]); }
/** * 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 IExpressionNode[] getArgumentNodes() { ArrayList<IExpressionNode> retVal = new ArrayList<IExpressionNode>(); if (argumentsNode != null) { int childCount = argumentsNode.getChildCount(); for (int i = 0; i < childCount; i++) { IASNode child = argumentsNode.getChild(i); if (child instanceof IExpressionNode) { retVal.add((IExpressionNode)child); } } } return retVal.toArray(new IExpressionNode[0]); }
@Override public IParameterNode[] getParameterNodes() { IParameterNode[] variables = {}; ContainerNode arguments = contentsPart.getParametersNode(); if (arguments != null) { int argumentscount = arguments.getChildCount(); variables = new IParameterNode[argumentscount]; for (int i = 0; i < argumentscount; i++) { IASNode argument = arguments.getChild(i); if (argument instanceof IParameterNode) variables[i] = (IParameterNode)argument; } } return variables; }
@Override public String getValue(boolean rawValue) { StringBuilder builder = new StringBuilder(); int length = getContentsNode().getChildCount(); for (int i = 0; i < length; i++) { IASNode child = getContentsNode().getChild(i); if (child instanceof ILiteralNode) { builder.append(((ILiteralNode) child).getValue(rawValue)); } } return builder.toString(); }
@Override public String getValue(boolean rawValue) { StringBuilder builder = new StringBuilder(); int length = getContentsNode().getChildCount(); for (int i = 0; i < length; i++) { IASNode child = getContentsNode().getChild(i); if (child instanceof ILiteralNode) { builder.append(((ILiteralNode) child).getValue(rawValue)); } } return builder.toString(); }
@Override public String getValue(boolean rawValue) { StringBuilder builder = new StringBuilder(); ContainerNode contents = getContentsNode(); int childcount = contents.getChildCount(); for (int i = 0; i < childcount; i++) { IASNode child = contents.getChild(i); if (child instanceof ILiteralNode) builder.append(((ILiteralNode)child).getValue(rawValue)); else if (child instanceof IIdentifierNode) builder.append(((IIdentifierNode)child).getName()); if (i + 1 < (childcount)) builder.append(","); } return "[" + builder.toString() + "]"; } }
@Override public String getValue(boolean rawValue) { StringBuilder builder = new StringBuilder(); ContainerNode contents = getContentsNode(); int childcount = contents.getChildCount(); for (int i = 0; i < childcount; i++) { IASNode child = contents.getChild(i); if (child instanceof ILiteralNode) builder.append(((ILiteralNode)child).getValue(rawValue)); else if (child instanceof IIdentifierNode) builder.append(((IIdentifierNode)child).getName()); if (i + 1 < (childcount)) builder.append(","); } return "[" + builder.toString() + "]"; } }
/** * This method is for debugging and testing purposes only. * * @return XML literal text. */ public final String getText() { final StringBuilder result = new StringBuilder(); final ContainerNode contents = getContentsNode(); for (int i = 0; i < contents.getChildCount(); i++) { final IASNode element = contents.getChild(i); if (element instanceof LiteralNode) result.append(((LiteralNode)element).getValue()); else if (element instanceof IIdentifierNode) result.append("{").append(((IIdentifierNode)element).getName()).append("}"); else if (element instanceof IMemberAccessExpressionNode) result.append("{").append(((IMemberAccessExpressionNode)element).getDisplayString()).append("}"); } return result.toString(); } }
/** * This method is for debugging and testing purposes only. * * @return XML literal text. */ public final String getText() { final StringBuilder result = new StringBuilder(); final ContainerNode contents = getContentsNode(); for (int i = 0; i < contents.getChildCount(); i++) { final IASNode element = contents.getChild(i); if (element instanceof LiteralNode) result.append(((LiteralNode)element).getValue()); else if (element instanceof IIdentifierNode) result.append("{").append(((IIdentifierNode)element).getName()).append("}"); else if (element instanceof IMemberAccessExpressionNode) result.append("{").append(((IMemberAccessExpressionNode)element).getDisplayString()).append("}"); } return result.toString(); } }
public static void findQualifiedNamesInXMLLiteral(XMLLiteralNode node, ICompilerProject project, List<String> qualifiedNames) { int childCount = node.getContentsNode().getChildCount(); for (int i = 0; i < childCount; i++) { IASNode child = node.getContentsNode().getChild(i); if (child instanceof ILiteralNode) { ILiteralNode literalChild = (ILiteralNode) child; if (literalChild.getLiteralType() == ILiteralNode.LiteralType.XML) { findQualifiedNamesInXMLLiteralChild(literalChild, project, qualifiedNames); } } } }
public static void findQualifiedNamesInXMLLiteral(XMLLiteralNode node, ICompilerProject project, List<String> qualifiedNames) { int childCount = node.getContentsNode().getChildCount(); for (int i = 0; i < childCount; i++) { IASNode child = node.getContentsNode().getChild(i); if (child instanceof ILiteralNode) { ILiteralNode literalChild = (ILiteralNode) child; if (literalChild.getLiteralType() == ILiteralNode.LiteralType.XML) { findQualifiedNamesInXMLLiteralChild(literalChild, project, qualifiedNames); } } } }
/** * Check if the next attribute definition is gated with a configuration * condition variable. If it is, then return the evaluated result of the * condition. * * @param containerNode parent node * @return True if the attributed definition is enabled. */ protected final boolean isDefinitionEnabled(final ContainerNode containerNode) { assert containerNode != null : "Container node can't be null."; final int childCount = containerNode.getChildCount(); if (childCount > 0) { final IASNode lastChild = containerNode.getChild(childCount - 1); if (lastChild.getNodeID() == ASTNodeID.LiteralBooleanID) { // evaluate final boolean eval = Boolean.parseBoolean(((LiteralNode)lastChild).getValue()); // remove the configuration condition node containerNode.removeItem((NodeBase)lastChild); containerNode.setRemovedConditionalCompileNode(true); return eval; } } return true; }
/** * Check if the next attribute definition is gated with a configuration * condition variable. If it is, then return the evaluated result of the * condition. * * @param containerNode parent node * @return True if the attributed definition is enabled. */ protected final boolean isDefinitionEnabled(final ContainerNode containerNode) { assert containerNode != null : "Container node can't be null."; final int childCount = containerNode.getChildCount(); if (childCount > 0) { final IASNode lastChild = containerNode.getChild(childCount - 1); if (lastChild.getNodeID() == ASTNodeID.LiteralBooleanID) { // evaluate final boolean eval = Boolean.parseBoolean(((LiteralNode)lastChild).getValue()); // remove the configuration condition node containerNode.removeItem((NodeBase)lastChild); containerNode.setRemovedConditionalCompileNode(true); return eval; } } return true; }