public StringBuilder toLongString(int level) { String prefix = ""; for (int i = 0; i < level; i++) { prefix += " "; } StringBuilder text = new StringBuilder(prefix); Iterator<String> iNames = getNames().iterator(); text.append(iNames.next()); while (iNames.hasNext()) { text.append(", ").append(iNames.next()); } text.append("(") .append(getLocalVariables().size()) .append(", ") .append(getLocalMixins().size()); text.append(") {").append("\n"); for (IScope kid : getChilds()) { text.append(kid.toLongString(level + 1)); } text.append(prefix).append("}").append("\n"); return text; }
/** * Create a new instance of NativeNumber * * @param owningEnvironment The environment in which this native number was created */ public JSNumberConstructor(Environment owningEnvironment) { super(owningEnvironment); int fileIndex = FileContextManager.BUILT_IN_FILE_INDEX; int offset = Range.Empty.getStartingOffset(); // get global IScope global = owningEnvironment.getGlobal(); // put self into environment global.putPropertyValue( "Number", this, fileIndex, Property.DONT_DELETE | Property.DONT_ENUM); // $NON-NLS-1$ // set Number.[[prototype]] IObject function = global.getPropertyValue("Function", fileIndex, offset); // $NON-NLS-1$ IObject functionPrototype = function.getPropertyValue("prototype", fileIndex, offset); // $NON-NLS-1$ this.setPrototype(functionPrototype); // create public prototype object IObject prototype = owningEnvironment.createObject(fileIndex, Range.Empty); // store our public prototype this.putPropertyValue("prototype", prototype, fileIndex); // $NON-NLS-1$ }
/** * @param scope scope * @return innermost named element that contains (or is) the scope, obtained by skipping local * scopes and passing instead to enclosing scopes */ static INamedElement parentNamedElementOfScope(final IScope scope) { IScope ancestor = scope; while (!(ancestor instanceof INamedElement)) { if (ancestor == null) throw new RuntimeException("AST content"); ancestor = ancestor.parent(); } return (INamedElement) ancestor; }
// this method might be wasteful, we are looking for the same tree, so there should // be no need to restart search from top for each parent public boolean seesAllDataOf(IScope otherScope) { boolean isLocalImport = seesLocalDataOf(otherScope); IScope parent = otherScope.getParent(); while (isLocalImport && parent != null) { isLocalImport = seesLocalDataOf(parent); parent = parent.getParent(); } return isLocalImport; }
public void replaceChild(IScope parent, IScope child, List<IScope> replacements) { List<IScope> inList = parent.getChilds(); int indexOf = inList.indexOf(child); inList.remove(indexOf); inList.addAll(indexOf, replacements); for (IScope kid : replacements) { kid.setParent(parent); } }
public IScope childByOwners(ASTCssNode headNode, ASTCssNode... restNodes) { IScope head = getChildOwnerOf(headNode); if (head == null) return null; for (ASTCssNode node : restNodes) { head = head.getChildOwnerOf(node); if (head == null) return null; } return head; }
public boolean seesLocalDataOf(IScope otherScope) { if (getLocalScope().hasTheSameLocalData(otherScope.getLocalScope())) return true; if (!hasParent()) return false; return getParent().seesLocalDataOf(otherScope); }
public void setParentKeepConsistency(IScope parent) { if (getSurroundingScopes().hasParent()) { getParent().getChilds().remove(this); } setParent(parent); if (parent != null) parent.addChild(this); }
public IScope getChildOwnerOf(ASTCssNode body) { for (IScope kid : getChilds()) { if (kid.getOwner() == body) return kid; } return null; }
// for new-style (i.e., session) secrecy and channel goals public void buildGoalContext(ExpressionContext ctx, ITerm term) { Entity current = term.getScope().findFirstEntity(); LocationInfo loc = term.getLocation(); if (current == null || goal == null || !(goal.getOwner() instanceof Entity)) { // maybe due to disabled goal, which is warned for. if (goal != null) // should not get here! current .getErrorGatherer() .addError( loc, ErrorMessages.INTERNAL_ERROR_ANNOTATION_LOST, this.name, term.getRepresentation()); return; } Entity session = (Entity) goal.getOwner(); IScope root = session.findRoot(); if (goal instanceof SessionSecrecyGoal) { SessionSecrecyGoal secrGoal = (SessionSecrecyGoal) goal; handleSecrecy( session, current, knowers, secrGoal.getSetSymbol(), secrGoal.getSecrecyProtocolName(), ctx, term); } else { SessionChannelGoal chGoal = (SessionChannelGoal) goal; boolean undirectedAuth = chGoal.hasUndirectedAuthentication(); ITerm actor = current.getActorSymbol().term(); boolean senderIsActor = actor.equals(sender); boolean receiverIsActor = actor.equals(receiver); { if (sender != null && (receiver != null || undirectedAuth)) { if (chGoal.hasSecrecy()) { List<ITerm> knowers = new ArrayList<ITerm>(); knowers.add(sender); knowers.add(receiver); handleSecrecy( session, current, knowers, chGoal.getSetSymbol(), chGoal.getSecrecyProtocolName(), ctx, term); // retract secrecy on receive (i.e. add intruder to set of knowers): if (receiverIsActor) { ITerm retractSecr = root.findFunction(Prelude.ADD) .term( chGoal.getSetSymbol().term(session.getIDSymbol().term()), root.findConstant(Prelude.INTRUDER).term()); ctx.addSessionGoalTerm(retractSecr); } } if (chGoal.hasAuthentication() || chGoal.hasFreshness()) { List<ITerm> toAdd = new ArrayList<ITerm>(); ConstantSymbol cAuthProt = null; if (chGoal.hasAuthentication()) { cAuthProt = session.findRootEntity().findConstant(chGoal.getAuthenticationProtocolName()); } ConstantSymbol cFreshProt = null; if (chGoal.hasFreshness()) { cFreshProt = session.findRootEntity().findConstant(chGoal.getFreshnessProtocolName()); } if (senderIsActor) { // sender side if (chGoal.hasAuthentication()) { toAdd.add( root.findFunction(Prelude.WITNESS) .term( actor, chGoal.hasUndirectedAuthentication() ? root.findConstant(Prelude.INTRUDER).term() : receiver, cAuthProt.term(), term)); } /* if (chGoal.hasFreshness()) { toAdd.add(root.findFunction(Prelude.WITNESS).term(mappedSender.term(), <ceiver.term(), cFreshProt.term(), this)); }*/ } else { // receiver side if (chGoal.hasAuthentication()) { toAdd.add( root.findFunction(Prelude.REQUEST) .term(actor, sender, cAuthProt.term(), term, current.getIDSymbol().term())); } if (chGoal.hasFreshness()) { toAdd.add( root.findFunction(Prelude.REQUEST) .term( actor, sender, cFreshProt.term(), term, current.getIDSymbol().term())); } } for (ITerm t : toAdd) { ctx.addSessionGoalTerm(t); } } } } } }