// Special procedures public bool isMain(bpl.Declaration decl) { return (decl != null && ( (decl is bpl.Implementation && (decl as bpl.Implementation).Name == entryFunc) || (decl is bpl.Procedure && (decl as bpl.Procedure).Name == entryFunc))); }
// mhp var info public bool isMhpVar(bpl.Declaration decl) { if (decl == null || !(decl is bpl.GlobalVariable)) { return(false); } var glbl = decl as bpl.GlobalVariable; if (getAttrParams(glbl.Attributes, mhpAttr) == null) { return(false); } return(true); }
// procedure attributes public bool isThreadEntry(bpl.Declaration decl) { if (!(decl is bpl.Procedure)) { return(false); } if (hasAttrKey(decl.Attributes, threadEntryAttr)) { return(true); } else { return(false); } }
public string readMhpVarProcName(bpl.Declaration decl) { if (!isMhpVar(decl)) { return(null); } var someNameIcantThinkUpRightNow = getAttrParams(decl.Attributes, mhpAttr); if (someNameIcantThinkUpRightNow.Count() > 0) { return(someNameIcantThinkUpRightNow[0] as string); } else { return(null); } }
public bool isOneInst(bpl.Declaration decl) { if (decl == null || !(decl is bpl.Constant)) { return(false); } var constant = decl as bpl.Constant; if (constant.Name == mhpOne) { return(true); } else { return(false); } }
public bool isSingleInstanceThread(bpl.Declaration decl) { if (!(decl is bpl.Procedure)) { return(false); } if (!isThreadEntry(decl)) { return(false); } if (hasAttrKey(decl.Attributes, singleInstAttr)) { return(true); } else { return(false); } }
void SortTopLevelDeclsWorker(TopLevelDecl tld, Declaration d, List<Type> referencedTypes, List<TopLevelDecl> topLevelTypes) { if (d is NewtypeDecl) { var nt = (NewtypeDecl)d; referencedTypes.Add(nt.BaseType); if (tld != null) { topLevelTypes.Add(tld); } } else if (d is DatatypeDecl) { var dt = (DatatypeDecl)d; foreach (var ctor in dt.Ctors) { foreach (Formal arg in ctor.Formals) { if (!arg.IsGhost) { referencedTypes.Add(arg.Type); } } } if (tld != null) { topLevelTypes.Add(tld); } } else if (d is ClassDecl) { var c = (ClassDecl)d; foreach (var cd in c.InheritedMembers) { if (!cd.IsGhost) { SortTopLevelDeclsWorker(null, cd, referencedTypes, topLevelTypes); } } foreach (MemberDecl member in c.Members) { if (!member.IsGhost) { SortTopLevelDeclsWorker(null, member, referencedTypes, topLevelTypes); } } if (tld != null) { topLevelTypes.Add(tld); } } else if (d is MemberDecl) { var m = (MemberDecl)d; if (m is Field) { var f = (Field)m; referencedTypes.Add(f.Type); } else if (m is Function) { var f = (Function)m; foreach (Formal p in f.Formals) { referencedTypes.Add(p.Type); } referencedTypes.Add(f.ResultType); } else if (m is Method) { var meth = (Method)m; foreach (Formal p in meth.Ins) { if (!p.IsGhost) { referencedTypes.Add(p.Type); } } foreach (Formal p in meth.Outs) { if (!p.IsGhost) { referencedTypes.Add(p.Type); } } } } }
protected virtual void ProcessDeclaration(Declaration decl) { Contract.Requires(decl != null); }
public override Declaration VisitDeclaration(Declaration node) { Contract.Ensures(Contract.Result<Declaration>() == node); return node; }
public virtual Declaration VisitDeclaration(Declaration node) { Contract.Requires(node != null); Contract.Ensures(Contract.Result<Declaration>() != null); return node; }
private int FindLocalVariableLayer(Declaration decl, Variable v, int enclosingProcLayerNum) { var layers = FindLayers(v.Attributes); if (layers.Count == 0) return int.MinValue; if (layers.Count > 1) { Error(decl, "Incorrect number of layers"); return int.MinValue; } if (layers[0] > enclosingProcLayerNum) { Error(decl, "Layer of local variable cannot be greater than the creation layer of enclosing procedure"); return int.MinValue; } return layers[0]; }
void UserDefinedType(out Declaration/*!*/ decl, QKeyValue kv) { Contract.Ensures(Contract.ValueAtReturn(out decl) != null); IToken/*!*/ id; List<IToken>/*!*/ paramTokens = new List<IToken> (); Bpl.Type/*!*/ body = dummyType; bool synonym = false; Ident(out id); if (la.kind == 1) { WhiteSpaceIdents(out paramTokens); } if (la.kind == 32) { Get(); Type(out body); synonym = true; } if (synonym) { List<TypeVariable>/*!*/ typeParams = new List<TypeVariable>(); foreach(Token/*!*/ t in paramTokens){ Contract.Assert(t != null); typeParams.Add(new TypeVariable(t, t.val));} decl = new TypeSynonymDecl(id, id.val, typeParams, body, kv); } else { decl = new TypeCtorDecl(id, id.val, paramTokens.Count, kv); } }
public bool isAtomicEndProc(bpl.Declaration decl) { return(decl != null && decl is bpl.Procedure && (decl as bpl.Procedure).Name == atomicEndProc); }
public bool isYieldProc(bpl.Declaration decl) { return((decl is bpl.Procedure) && ((decl as bpl.Procedure).Name == yieldProc)); }
public override Declaration VisitDeclaration(Declaration node) { //Contract.Requires(node != null); Contract.Ensures(Contract.Result<Declaration>() != null); return base.VisitDeclaration((Declaration)node.Clone()); }
/// <summary> /// If both "a" and "b" have an ":extern" attribute, returns either one. /// If one of "a" and "b" has an ":extern" attribute, returns that one. /// If neither of "a" and "b" has an ":extern" attribute, returns null. /// If a non-value value is returned, this method also adds the ":ignore" /// attribute to the declaration NOT returned. /// </summary> Declaration SelectNonExtern(Declaration a, Declaration b) { Contract.Requires(a != null); Contract.Requires(b != null); Contract.Ensures(Contract.Result<Declaration>() == null || Contract.Result<Declaration>() == a || Contract.Result<Declaration>() == b); Declaration ignore, keep; if (QKeyValue.FindBoolAttribute(a.Attributes, "extern")) { ignore = a; keep = b; } else if (QKeyValue.FindBoolAttribute(b.Attributes, "extern")) { ignore = b; keep = a; } else { return null; } // prepend :ignore attribute ignore.Attributes = new QKeyValue(ignore.tok, "ignore", new List<object/*!*/>(), ignore.Attributes); return keep; }
public void Error(MessageSource source, Declaration d, string msg, params object[] args) { Contract.Requires(d != null); Contract.Requires(msg != null); Error(source, d.tok, msg, args); }