@Override public String toString() { StringBuffer buf = new StringBuffer(); buf.append("[UnitGroup "); buf.append(id); buf.append(" :type "); buf.append(type); buf.append(" :ownerId "); buf.append(ownerId); buf.append(" (:required"); for (Argument arg : unitTypeReqs) { buf.append(" "); buf.append(arg.getName()); buf.append(" "); buf.append(arg.getValue()); } buf.append(") (:actual"); if (!isEmpty()) { for (Map.Entry<String, Integer> entry : getRepresentative().getUnitTypes().entrySet()) { buf.append(" "); buf.append(entry.getKey()); buf.append(" "); buf.append(entry.getValue()); } } buf.append(")]"); return buf.toString(); }
private void remapRegister(RegAllocContext context, Instruction instr, Argument arg) { // If Argument2() is mapped to a variable if (instr.getMapRegToValue().containsKey(arg.getName())) { String strVar = instr.getMapRegToValue().get(arg.getName()); // Re-write argument 2 with re-mapped register if (!strVar.isEmpty()) { String strRemapReg = context.variableLocs.get(strVar); if (null != strRemapReg && 0 != strRemapReg.compareTo("m")) { arg.setName(strRemapReg); arg.setOrigName(strRemapReg); } } } }
@Override public boolean equals(Object o) { if ((o instanceof Argument) == false) return false; Argument p = (Argument) o; return this.name.equals(p.getName()); }
public Argument getArgument(String name) { int nArgs = size(); for (int n = 0; n < nArgs; n++) { Argument arg = getArgument(n); String argName = arg.getName(); if (argName == null) continue; if (argName.equals(name) == true) return arg; } return null; }
/** @deprecated */ public void set(ArgumentList inArgList) { int nInArgs = inArgList.size(); for (int n = 0; n < nInArgs; n++) { Argument inArg = inArgList.getArgument(n); String inArgName = inArg.getName(); Argument arg = getArgument(inArgName); if (arg == null) continue; arg.setValue(inArg.getValue()); } }
void updateArgumentList(TreeNode parentNode, Action action) { ArgumentList argList = action.getArgumentList(); int nArguments = argList.size(); for (int n = 0; n < nArguments; n++) { Argument arg = argList.getArgument(n); String argName = arg.getName() + "(" + arg.getDirection() + ")"; TreeNode argNode = new TreeNode(argName); argNode.setUserData(arg); parentNode.add(argNode); } }
@Override public String toString() { return "Scenario [id=" + id + ", image.name=" + image.getName() + ", policyA.name=" + policyA.getName() + ", argumentA.name=" + argumentA.getName() + "]"; }
public void print() { Debug.message("Action : " + getName()); ArgumentList argList = getArgumentList(); int nArgs = argList.size(); for (int n = 0; n < nArgs; n++) { Argument arg = argList.getArgument(n); String name = arg.getName(); String value = arg.getValue(); String dir = arg.getDirection(); Debug.message(" [" + n + "] = " + dir + ", " + name + ", " + value); } }
/** * Set all the Argument which are Output Argoument to the given value in the argument list * * @param outArgList */ public void setResArgs(ArgumentList outArgList) { int nArgs = size(); for (int n = 0; n < nArgs; n++) { Argument arg = getArgument(n); if (arg.isOutDirection()) { String argName = arg.getName(); Argument outArg = outArgList.getArgument(argName); if (outArg == null) throw new IllegalArgumentException("Argument \"" + argName + "\" missing."); arg.setValue(outArg.getValue()); } } }
// Updates this block's Phi Function public void updatePhiFunction(Argument arg, Symbol sym) { for (int i = 0; i < getPhiFunctions().size(); i++) { PhiFunction phiFunc = getPhiFunctions().get(i); if (0 == phiFunc.getVariable().getName().compareTo(arg.getOrigName())) { __debugPrintln("Updating Phi Func: " + arg.getOrigName() + " to " + sym.getIntegerValue()); phiFunc.updateVariable(arg.getName(), new Symbol(sym)); break; } } }
public boolean visit(MethodDeclaration method) throws Exception { methodGlobalVars.add(new HashSet<String>()); ASTNode parentDeclaration = null; if (!declarations.empty()) { parentDeclaration = declarations.peek(); } // In case we are entering a nested element - just add to the deferred // list // and get out of the nested element visiting process if (parentDeclaration instanceof MethodDeclaration) { if (fLastNamespace == null) { deferredDeclarations.add(method); } else { deferredNamespacedDeclarations.add(method); } return false; } if (parentDeclaration instanceof InterfaceDeclaration) { method.setModifier(Modifiers.AccAbstract); } method.setModifiers(markAsDeprecated(method.getModifiers(), method)); declarations.push(method); for (PHPSourceElementRequestorExtension visitor : extensions) { visitor.visit(method); } boolean visit = visitMethodDeclaration(method); if (visit) { // Process method argument (local variable) declarations: List<Argument> arguments = method.getArguments(); for (Argument arg : arguments) { ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo(); info.name = arg.getName(); info.modifiers = Modifiers.AccPublic; info.nameSourceStart = arg.getNameStart(); info.nameSourceEnd = arg.getNameEnd() - 1; info.declarationStart = arg.sourceStart(); fRequestor.enterField(info); fRequestor.exitField(arg.sourceEnd() - 1); } } return visit; }
/** Do group units meet group requirements? */ public boolean meetsUnitReqs() { if (unitTypeReqs.isEmpty()) { // a group with no requirements always meets requirements. return true; } else if (units.isEmpty()) { // if there are requirments and no units, then group can't meet reqs. return false; } // the above tests are there because // an empty group has no representative (null representative). GroupRepresentative rep = getRepresentative(); for (Argument req : unitTypeReqs) { if (!rep.contains(req.getName(), req.getValue())) { return false; } } return true; }
@Override protected final int run(Argument[] arguments) { ArrayList<Argument> others = new ArrayList<>(); for (Argument argument : arguments) { if (argument.getName().equalsIgnoreCase("-Release")) { // 释放资源命令 try { if (argument.isInputed()) { this.writeResources(this.getResourceSign(argument), this.getReleaseFolder(argument)); } } catch (Exception e) { this.print(e); return RETURN_VALUE_IO_EXCEPTION; } continue; // 已处理,则不再传入子命令 } others.add(argument); } return this.go(others.toArray(new Argument[] {})); }
private String[] processParameterTypes(MethodDeclaration methodDeclaration) { List<?> args = methodDeclaration.getArguments(); PHPDocBlock docBlock = ((PHPMethodDeclaration) methodDeclaration).getPHPDoc(); String[] parameterType = new String[args.size()]; for (int a = 0; a < args.size(); a++) { Argument arg = (Argument) args.get(a); if (arg instanceof FormalParameter) { SimpleReference type = ((FormalParameter) arg).getParameterType(); if (type != null) { parameterType[a] = type.getName(); } else if (docBlock != null) { for (PHPDocTag tag : docBlock.getTags(PHPDocTag.PARAM)) { if (tag.isValidParamTag() && tag.getVariableReference().getName().equals(arg.getName())) { parameterType[a] = tag.getSingleTypeReference().getName(); break; } } } } } return parameterType; }
private boolean visitMethodDeclaration(MethodDeclaration method) throws Exception { this.fNodes.push(method); List<?> args = method.getArguments(); String[] parameter = new String[args.size()]; String[] initializers = new String[args.size()]; for (int a = 0; a < args.size(); a++) { Argument arg = (Argument) args.get(a); parameter[a] = arg.getName(); if (arg.getInitialization() != null) { if (arg.getInitialization() instanceof Literal) { Literal scalar = (Literal) arg.getInitialization(); initializers[a] = scalar.getValue(); } else { initializers[a] = DEFAULT_VALUE; } } } ISourceElementRequestor.MethodInfo mi = new ISourceElementRequestor.MethodInfo(); mi.parameterNames = parameter; mi.name = method.getName(); mi.modifiers = method.getModifiers(); mi.nameSourceStart = method.getNameStart(); mi.nameSourceEnd = method.getNameEnd() - 1; mi.declarationStart = method.sourceStart(); mi.parameterInitializers = initializers; modifyMethodInfo(method, mi); fInfoStack.push(mi); this.fRequestor.enterMethod(mi); this.fInMethod = true; this.fCurrentMethod = method; return true; }
/** * Update the ports to match the arguments. If an Argument has no corresponding port, a Port is * added. If a Port does not have a corresponding Argument, then the Port is removed. If a input * and/or output nature of a Port does not match the Argument with the same name, then the Port is * adjusted. * * @exception IllegalActionException If there is a problem updating the ports. */ public void updatePorts() throws IllegalActionException { Iterator arguments = this.argumentsList().iterator(); TypedIOPort port; while (arguments.hasNext()) { Argument argument = (Argument) arguments.next(); port = (TypedIOPort) this.getPort(argument.getName()); if (port == null) { MoMLChangeRequest request = null; try { if (argument.isReturn()) { request = new MoMLChangeRequest( this, this, "<port name=\"" + argument.getName() + "\" class=\"ptolemy.actor.TypedIOPort\">\n" + " <property name=\"output\"/>\n" + "</port>"); } else if (argument.isInput() && argument.isOutput()) { request = new MoMLChangeRequest( this, this, "<port name=\"" + argument.getName() + "in" + "\" class=\"ptolemy.actor.TypedIOPort\">\n" + " <property name=\"input\"/>\n" + "</port>\n" + "<port name=\"" + argument.getName() + "out" + "\" class=\"ptolemy.actor.TypedIOPort\">\n" + " <property name=\"output\"/>\n" + "</port>"); } else { request = new MoMLChangeRequest( this, this, "<port name=\"" + argument.getName() + "\" class=\"ptolemy.actor.TypedIOPort\">\n" + (argument.isInput() ? " <property name=\"input\"/>\n" : "") + (argument.isOutput() ? " <property name=\"output\"/>\n" : "") + "</port>"); } request.setUndoable(true); requestChange(request); } catch (Throwable throwable) { throw new IllegalActionException( this, throwable, "MoMLChangeRequest for \"" + argument.getName() + "\" failed. Request was:\n" + request); } } else { // We have a preexisting port, synchronized the // arguments and the ports. if (argument.isReturn()) { if (port.isInput()) { MoMLChangeRequest request = new MoMLChangeRequest( this, this, "<port name=\"" + argument.getName() + "\" class=\"ptolemy.actor.TypedIOPort\">\n" + " <deleteProperty name=\"input\"/>\n" + (port.isOutput() ? "" : " <property name=\"output\"/>\n") + "</port>"); request.setUndoable(true); requestChange(request); } if (!port.isOutput()) { MoMLChangeRequest request = new MoMLChangeRequest( this, this, "<port name=\"" + argument.getName() + "\" class=\"ptolemy.actor.TypedIOPort\">\n" + " <property name=\"output\"/>\n" + "</port>"); request.setUndoable(true); requestChange(request); } } else /*if (port.isInput() != argument.isInput() || port.isOutput() != argument.isOutput())*/ { MoMLChangeRequest request = new MoMLChangeRequest( this, this, "<port name=\"" + argument.getName() + "\" class=\"ptolemy.actor.TypedIOPort\">\n" + (port.isInput() ? (argument.isInput() ? "" : "<deleteProperty name=\"input\"/>\n") : (argument.isInput() ? "<property name=\"input\"/>\n" : "")) + (port.isOutput() ? (argument.isOutput() ? "" : "<deleteProperty name=\"output\"/>\n") : (argument.isOutput() ? "<property name=\"output\"/>\n" : "")) + "</port>"); request.setUndoable(true); requestChange(request); } } } // Remove any ports that do not have arguments. Iterator ports = portList().iterator(); while (ports.hasNext()) { port = (TypedIOPort) ports.next(); Argument argument = (Argument) _argumentsList.get(port.getName()); if (argument == null) { MoMLChangeRequest request = new MoMLChangeRequest(this, this, "<deletePort name=\"" + port.getName() + "\"/>"); request.setUndoable(true); requestChange(request); } } }
/** * For each Argument, a port of the same name is created, belonging to this argument. * * @exception IllegalActionException If there is a problem creating the ports. */ public void createPorts() throws IllegalActionException { Iterator arguments = this.argumentsList().iterator(); TypedIOPort port; while (arguments.hasNext()) { Argument argument = (Argument) arguments.next(); port = (TypedIOPort) this.getPort(argument.getName()); if (port == null) { if (argument.isReturn()) { try { MoMLChangeRequest request = new MoMLChangeRequest( this, this, "<port name=\"" + argument.getName() + "\" class=\"ptolemy.actor.TypedIOPort\">\n" + " <property name=\"output\"/>\n" + "</port>"); request.setUndoable(true); requestChange(request); } catch (Exception ex) { throw new IllegalActionException( this, ex, "Unable to construct port " + "port for argument \"" + argument.getName() + "\""); } } else if (argument.isInput() && argument.isOutput()) { try { MoMLChangeRequest request = new MoMLChangeRequest( this, this, "<group>\n" + " <port name=\"" + argument.getName() + "in" + "\" class=\"ptolemy.actor.TypedIOPort\">\n" + " <property name=\"input\"/>\n" + " </port>\n" + " <port name=\"" + argument.getName() + "out" + "\" class=\"ptolemy.actor.TypedIOPort\">\n" + " <property name=\"output\"/>\n" + " </port>\n" + "</group>"); request.setUndoable(true); requestChange(request); } catch (Exception ex) { throw new IllegalActionException( this, ex, "Unable to construct " + "input or output " + "port for argument \"" + argument.getName() + "\""); } } else { try { MoMLChangeRequest request = new MoMLChangeRequest( this, this, "<port name=\"" + argument.getName() + "\" class=\"ptolemy.actor.TypedIOPort\">\n" + (argument.isInput() ? " <property name=\"input\"/>\n" : "") + (argument.isOutput() ? " <property name=\"output\"/>\n" : "") + "</port>"); request.setUndoable(true); requestChange(request); } catch (Exception ex) { throw new IllegalActionException( this, ex, "Unable to construct " + "port for argument \"" + argument.getName() + "\""); } } } else { // synchronized the arguments and the ports if (argument.isReturn()) { MoMLChangeRequest request = new MoMLChangeRequest( this, this, "<port name=\"" + argument.getName() + "\" class=\"ptolemy.actor.TypedIOPort\"\n" + " <property name=\"output\"/>\n" + "</port>"); request.setUndoable(true); requestChange(request); } else { MoMLChangeRequest request = new MoMLChangeRequest( this, this, "<port name=\"" + argument.getName() + "\" class=\"ptolemy.actor.TypedIOPort\"\n" + " <property name=\"input\"/>\n" + "</port>"); request.setUndoable(true); requestChange(request); } } port = (TypedIOPort) this.getPort(argument.getName()); if (port != null) { port.setTypeEquals(BaseType.GENERAL); } } }
/* Register a new Argument handler for a desired parameter */ public void registerArgument(Argument argument) { parameters.put(argument.getName().toLowerCase(), argument); }
@SuppressWarnings("unchecked") public boolean visit(MethodDeclaration method) throws Exception { fNodes.push(method); methodGlobalVars.add(new HashSet<String>()); int modifiers = method.getModifiers(); PHPDocBlock doc = null; if (method instanceof IPHPDocAwareDeclaration) { IPHPDocAwareDeclaration declaration = (IPHPDocAwareDeclaration) method; doc = declaration.getPHPDoc(); } Declaration parentDeclaration = null; if (!declarations.empty()) { parentDeclaration = declarations.peek(); } declarations.push(method); // In case we are entering a nested element - just add to the deferred // list // and get out of the nested element visiting process if (parentDeclaration instanceof MethodDeclaration) { if (fCurrentNamespace == null) { deferredDeclarations.add(method); } else { deferredNamespacedDeclarations.add(method); } return visitGeneral(method); } if (parentDeclaration instanceof InterfaceDeclaration) { method.setModifier(Modifiers.AccAbstract); } String methodName = method.getName(); // Determine whether this method represents constructor: if (methodName.equalsIgnoreCase(CONSTRUCTOR_NAME) || (parentDeclaration instanceof ClassDeclaration && methodName.equalsIgnoreCase(((ClassDeclaration) parentDeclaration).getName()))) { modifiers |= IPHPModifiers.Constructor; } if (parentDeclaration == null || (parentDeclaration instanceof TypeDeclaration && parentDeclaration == fCurrentNamespace)) { modifiers |= Modifiers.AccGlobal; } if (!Flags.isPrivate(modifiers) && !Flags.isProtected(modifiers) && !Flags.isPublic(modifiers)) { modifiers |= Modifiers.AccPublic; } modifiers = markAsDeprecated(modifiers, method); StringBuilder metadata = new StringBuilder(); if (fCurrentQualifier != null) { metadata.append(fCurrentQualifierCounts.get(fCurrentQualifier)); metadata.append(";"); // $NON-NLS-1$ } List<Argument> arguments = method.getArguments(); if (arguments != null) { Iterator<Argument> i = arguments.iterator(); while (i.hasNext()) { Argument arg = (Argument) i.next(); String type = NULL_VALUE; if (arg instanceof FormalParameter) { FormalParameter fp = (FormalParameter) arg; if (fp.getParameterType() != null) { if (fp.getParameterType().getName() != null) { type = fp.getParameterType().getName(); } } } if (type == NULL_VALUE && doc != null) { type = getParamType(doc, arg.getName(), type); } metadata.append(type); metadata.append(PARAMETER_SEPERATOR); metadata.append(arg.getName()); metadata.append(PARAMETER_SEPERATOR); String defaultValue = NULL_VALUE; if (arg.getInitialization() != null) { if (arg.getInitialization() instanceof Literal) { Literal scalar = (Literal) arg.getInitialization(); defaultValue = scalar.getValue(); } else { defaultValue = DEFAULT_VALUE; } } metadata.append(defaultValue); if (i.hasNext()) { metadata.append(","); // $NON-NLS-1$ } } } // Add method declaration: modifyDeclaration( method, new DeclarationInfo( IModelElement.METHOD, modifiers, method.sourceStart(), method.sourceEnd() - method.sourceStart(), method.getNameStart(), method.getNameEnd() - method.getNameStart(), methodName, metadata.length() == 0 ? null : metadata.toString(), encodeDocInfo(method), fCurrentQualifier, fCurrentParent)); for (PhpIndexingVisitorExtension visitor : extensions) { visitor.visit(method); } return visitGeneral(method); }
public boolean visit(LambdaFunctionDeclaration lambdaMethod) throws Exception { fNodes.push(lambdaMethod); methodGlobalVars.add(new HashSet<String>()); // Declaration parentDeclaration = null; // if (!declarations.empty() // && declarations.peek() instanceof MethodDeclaration) { // parentDeclaration = declarations.peek(); // // In case we are entering a nested element - just add to the // // deferred list and get out of the nested element visiting process // deferredDeclarations.add(lambdaMethod); // return visitGeneral(lambdaMethod); // } Collection<FormalParameter> arguments = lambdaMethod.getArguments(); StringBuilder metadata = new StringBuilder(); String[] parameters; if (arguments != null) { parameters = new String[arguments.size()]; Iterator<FormalParameter> i = arguments.iterator(); int indx = 0; while (i.hasNext()) { Argument arg = (Argument) i.next(); metadata.append(arg.getName()); parameters[indx] = arg.getName(); indx++; if (i.hasNext()) { metadata.append(","); // $NON-NLS-1$ } } } else { parameters = new String[0]; } // Add method declaration: for (PHPSourceElementRequestorExtension visitor : extensions) { visitor.visit(lambdaMethod); } ISourceElementRequestor.MethodInfo mi = new ISourceElementRequestor.MethodInfo(); mi.parameterNames = parameters; mi.name = PHPCoreConstants.ANONYMOUS; mi.modifiers = Modifiers.AccPublic; if (lambdaMethod.isStatic()) { mi.modifiers |= Modifiers.AccStatic; } mi.nameSourceStart = lambdaMethod.sourceStart(); mi.nameSourceEnd = lambdaMethod.sourceEnd(); mi.declarationStart = mi.nameSourceStart; mi.isConstructor = false; fInfoStack.push(mi); this.fRequestor.enterMethod(mi); this.fInMethod = true; for (Argument arg : arguments) { ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo(); info.name = arg.getName(); info.modifiers = Modifiers.AccPublic; info.nameSourceStart = arg.getNameStart(); info.nameSourceEnd = arg.getNameEnd() - 1; info.declarationStart = arg.sourceStart(); fRequestor.enterField(info); fRequestor.exitField(arg.sourceEnd() - 1); } return true; }
public boolean calculateLiveIN() { boolean bChanges = false; mapRegistersToVariables(); // The last lastLive set is a copy of liveOUT LiveSet lastLive = new LiveSet(getLiveOut()); for (int i = getLines().getNumItems() - 1; i >= 0; i--) { Line line = getLines().getItemAtIndex(i); // Copy the last live set line.getLiveSet().copy(lastLive); if (Line.Type.INSTRUCTION == line.getType()) { Instruction instr = (Instruction) line; Argument arg2 = instr.getArgument2(); // If this is a SW instruction, then remove the // target variable from the live set if (0 == instr.getInstruction().compareTo("sw")) { // Remove the mapping to the variable line.getLiveSet().remove(arg2.getName()); // See if Argument1 is mapped to a variable if (instr.getMapRegToValue().containsKey(instr.getArgument1().getName())) { String strVal = instr.getMapRegToValue().get(instr.getArgument1().getName()); // Mark the variable as live line.getLiveSet().add(strVal); } } // If this is a LW instruction, then add the loaded // variable to the live set else if (0 == instr.getInstruction().compareTo("lw") || 0 == instr.getInstruction().compareTo("li")) { line.getLiveSet().add(arg2.getName()); } else if (!instr.getIsJump() && 0 != instr.getInstruction().compareTo("syscall") && 0 != instr.getInstruction().compareTo("move") && 0 != instr.getInstruction().compareTo("li")) { // See if Argument2 is mapped to a variable if (instr.getMapRegToValue().containsKey(instr.getArgument2().getName())) { String strVal = instr.getMapRegToValue().get(instr.getArgument2().getName()); // Mark the variable as live line.getLiveSet().add(strVal); } // See if Argument3 is mapped to a variable if (instr.getMapRegToValue().containsKey(instr.getArgument3().getName())) { String strVal = instr.getMapRegToValue().get(instr.getArgument3().getName()); // Mark the variable as live line.getLiveSet().add(strVal); } } else if (0 == instr.getInstruction().compareTo("move")) { // See if Argument2 is mapped to a variable if (instr.getMapRegToValue().containsKey(instr.getArgument2().getName())) { String strVal = instr.getMapRegToValue().get(instr.getArgument2().getName()); // Mark the variable as live line.getLiveSet().add(strVal); } } } lastLive = line.getLiveSet(); } getLiveIn().copy(lastLive); return bChanges; }