public override void Visit(ExprDotName e) { MemberSelectExpr mse = null; if (e.ResolvedExpression is MemberSelectExpr) { mse = e.ResolvedExpression as MemberSelectExpr; } var nav = new SymbolNavigator(); var definingItem = nav.TopDown(RootNode, mse?.Member.tok); var declaration = FindDeclaration(e.SuffixName, definingItem); CreateSymbol( name: e.SuffixName, kind: null, type: e.Type, positionAsToken: e.tok, bodyStartPosAsToken: null, bodyEndPosAsToken: null, isDeclaration: false, declarationSymbol: declaration, addUsageAtDeclaration: true, canHaveChildren: false, canBeUsed: false ); }
public string GenerateString(ExprDotName expression) { var left = GenerateString(expression.Lhs); var dot = "."; var self = expression.tok.val; return(left + dot + self); }
public string GenerateConditionString(ExprDotName expression, IDictionary <string, string> rename) { var left = GenerateConditionString(expression.Lhs, rename); var dot = "."; var self = expression.tok.val; return(left + dot + self); }
public override void Visit(ExprDotName expressionDotName) { _cancellationToken.ThrowIfCancellationRequested(); base.Visit(expressionDotName); if (_typeResolver.TryGetTypeSymbol(expressionDotName.Lhs, out var leftHandSideType)) { RegisterDesignator(leftHandSideType, expressionDotName, expressionDotName.tok, expressionDotName.SuffixName); } }
public static string GetSignature(ExprDotName dotName) { return(dotName.SuffixName); }
public virtual void Visit(ExprDotName expressionDotName) { Visit(expressionDotName.Lhs); }
void TypeAndToken(out IToken tok, out Type ty) { Contract.Ensures(Contract.ValueAtReturn(out tok)!=null); Contract.Ensures(Contract.ValueAtReturn(out ty) != null); tok = Token.NoToken; ty = new BoolType(); /*keep compiler happy*/ List<Type> gt; List<Type> tupleArgTypes = null; switch (la.kind) { case 6: { Get(); tok = t; break; } case 7: { Get(); tok = t; ty = new CharType(); break; } case 9: { Get(); tok = t; ty = new NatType(); break; } case 8: { Get(); tok = t; ty = new IntType(); break; } case 10: { Get(); tok = t; ty = new RealType(); break; } case 11: { Get(); tok = t; ty = new ObjectType(); break; } case 13: { Get(); tok = t; gt = new List<Type>(); if (la.kind == 52) { GenericInstantiation(gt); } if (gt.Count > 1) { SemErr("set type expects only one type argument"); } ty = new SetType(true, gt.Count == 1 ? gt[0] : null); break; } case 14: { Get(); tok = t; gt = new List<Type>(); if (la.kind == 52) { GenericInstantiation(gt); } if (gt.Count > 1) { SemErr("set type expects only one type argument"); } ty = new SetType(false, gt.Count == 1 ? gt[0] : null); break; } case 15: { Get(); tok = t; gt = new List<Type>(); if (la.kind == 52) { GenericInstantiation(gt); } if (gt.Count > 1) { SemErr("multiset type expects only one type argument"); } ty = new MultiSetType(gt.Count == 1 ? gt[0] : null); break; } case 16: { Get(); tok = t; gt = new List<Type>(); if (la.kind == 52) { GenericInstantiation(gt); } if (gt.Count > 1) { SemErr("seq type expects only one type argument"); } ty = new SeqType(gt.Count == 1 ? gt[0] : null); break; } case 12: { Get(); tok = t; ty = new UserDefinedType(tok, tok.val, null); break; } case 17: { Get(); tok = t; gt = new List<Type>(); if (la.kind == 52) { GenericInstantiation(gt); } if (gt.Count == 0) { ty = new MapType(true, null, null); } else if (gt.Count != 2) { SemErr("map type expects two type arguments"); ty = new MapType(true, gt[0], gt.Count == 1 ? new InferredTypeProxy() : gt[1]); } else { ty = new MapType(true, gt[0], gt[1]); } break; } case 18: { Get(); tok = t; gt = new List<Type>(); if (la.kind == 52) { GenericInstantiation(gt); } if (gt.Count == 0) { ty = new MapType(false, null, null); } else if (gt.Count != 2) { SemErr("imap type expects two type arguments"); ty = new MapType(false, gt[0], gt.Count == 1 ? new InferredTypeProxy() : gt[1]); } else { ty = new MapType(false, gt[0], gt[1]); } break; } case 5: { Get(); tok = t; gt = null; if (la.kind == 52) { gt = new List<Type>(); GenericInstantiation(gt); } int dims = tok.val.Length == 5 ? 1 : int.Parse(tok.val.Substring(5)); ty = theBuiltIns.ArrayType(tok, dims, gt, true); break; } case 50: { Get(); tok = t; tupleArgTypes = new List<Type>(); if (StartOf(3)) { Type(out ty); tupleArgTypes.Add(ty); while (la.kind == 22) { Get(); Type(out ty); tupleArgTypes.Add(ty); } } Expect(51); if (tupleArgTypes.Count == 1) { // just return the type 'ty' } else { var dims = tupleArgTypes.Count; var tmp = theBuiltIns.TupleType(tok, dims, true); // make sure the tuple type exists ty = new UserDefinedType(tok, BuiltIns.TupleTypeName(dims), dims == 0 ? null : tupleArgTypes); } break; } case 1: { Expression e; tok = t; NameSegmentForTypeName(out e); tok = t; while (la.kind == 27) { Get(); Expect(1); tok = t; List<Type> typeArgs = null; if (la.kind == 52) { typeArgs = new List<Type>(); GenericInstantiation(typeArgs); } e = new ExprDotName(tok, e, tok.val, typeArgs); } ty = new UserDefinedType(e.tok, e); break; } default: SynErr(164); break; } if (la.kind == 30) { Type t2; Get(); tok = t; Type(out t2); if (tupleArgTypes != null) { gt = tupleArgTypes; } else { gt = new List<Type>{ ty }; } ty = new ArrowType(tok, gt, t2); theBuiltIns.CreateArrowTypeDecl(gt.Count); } }
void Suffix(ref Expression e) { Contract.Requires(e != null); Contract.Ensures(e!=null); IToken id, x; Expression e0 = null; Expression e1 = null; Expression ee; bool anyDots = false; List<Expression> multipleLengths = null; bool takeRest = false; // takeRest is relevant only if multipleLengths is non-null List<Expression> multipleIndices = null; if (la.kind == 27) { DotSuffix(out id, out x); if (x != null) { // process id as a Suffix in its own right e = new ExprDotName(id, e, id.val, null); id = x; // move to the next Suffix } IToken openParen = null; List<Type> typeArgs = null; List<Expression> args = null; if (IsGenericInstantiation()) { typeArgs = new List<Type>(); GenericInstantiation(typeArgs); } else if (la.kind == 106) { HashCall(id, out openParen, out typeArgs, out args); } else if (StartOf(30)) { } else SynErr(225); e = new ExprDotName(id, e, id.val, typeArgs); if (openParen != null) { e = new ApplySuffix(openParen, e, args); } } else if (la.kind == 48) { Get(); x = t; if (StartOf(7)) { Expression(out ee, true, true); e0 = ee; if (la.kind == 137) { Get(); anyDots = true; if (StartOf(7)) { Expression(out ee, true, true); e1 = ee; } } else if (la.kind == 95) { Get(); Expression(out ee, true, true); e1 = ee; } else if (la.kind == 21) { Get(); multipleLengths = new List<Expression>(); multipleLengths.Add(e0); // account for the Expression read before the colon takeRest = true; if (StartOf(7)) { Expression(out ee, true, true); multipleLengths.Add(ee); takeRest = false; while (IsNonFinalColon()) { Expect(21); Expression(out ee, true, true); multipleLengths.Add(ee); } if (la.kind == 21) { Get(); takeRest = true; } } } else if (la.kind == 22 || la.kind == 49) { while (la.kind == 22) { Get(); Expression(out ee, true, true); if (multipleIndices == null) { multipleIndices = new List<Expression>(); multipleIndices.Add(e0); } multipleIndices.Add(ee); } } else SynErr(226); } else if (la.kind == 137) { Get(); anyDots = true; if (StartOf(7)) { Expression(out ee, true, true); e1 = ee; } } else SynErr(227); if (multipleIndices != null) { e = new MultiSelectExpr(x, e, multipleIndices); // make sure an array class with this dimensionality exists var tmp = theBuiltIns.ArrayType(multipleIndices.Count, new IntType(), true); } else { if (!anyDots && e0 == null) { /* a parsing error occurred */ e0 = dummyExpr; } Contract.Assert(anyDots || e0 != null); if (anyDots) { //Contract.Assert(e0 != null || e1 != null); e = new SeqSelectExpr(x, false, e, e0, e1); } else if (multipleLengths != null) { Expression prev = null; List<Expression> seqs = new List<Expression>(); foreach (var len in multipleLengths) { var end = prev == null ? len : new BinaryExpr(x, BinaryExpr.Opcode.Add, prev, len); seqs.Add(new SeqSelectExpr(x, false, e, prev, end)); prev = end; } if (takeRest) { seqs.Add(new SeqSelectExpr(x, false, e, prev, null)); } e = new SeqDisplayExpr(x, seqs); } else if (e1 == null) { Contract.Assert(e0 != null); e = new SeqSelectExpr(x, true, e, e0, null); } else { Contract.Assert(e0 != null); e = new SeqUpdateExpr(x, e, e0, e1); } } Expect(49); } else if (la.kind == 50) { Get(); IToken openParen = t; var args = new List<Expression>(); if (StartOf(7)) { Expressions(args); } Expect(51); e = new ApplySuffix(openParen, e, args); } else SynErr(228); }
internal bool IsEAtmoicCall(ExprDotName aps) { return(EAtomic.EAtomic.IsEAtomicSig(Util.GetSignature(aps))); }
public override void Leave(ExprDotName e) { }
public override void Visit(ExprDotName e) { }
public override AssignmentRhs CloneRHS(AssignmentRhs rhs) { var r = rhs as ExprRhs; if (r != null && r.Expr is ApplySuffix) { var apply = (ApplySuffix)r.Expr; var mse = apply.Lhs.Resolved as MemberSelectExpr; if (mse != null && mse.Member is FixpointLemma && ModuleDefinition.InSameSCC(context, (FixpointLemma)mse.Member)) { // we're looking at a recursive call to a fixpoint lemma Contract.Assert(apply.Lhs is NameSegment || apply.Lhs is ExprDotName); // this is the only way a call statement can have been parsed // clone "apply.Lhs", changing the inductive/co lemma to the prefix lemma; then clone "apply", adding in the extra argument Expression lhsClone; if (apply.Lhs is NameSegment) { var lhs = (NameSegment)apply.Lhs; lhsClone = new NameSegment(Tok(lhs.tok), lhs.Name + "#", lhs.OptTypeArguments == null ? null : lhs.OptTypeArguments.ConvertAll(CloneType)); } else { var lhs = (ExprDotName)apply.Lhs; lhsClone = new ExprDotName(Tok(lhs.tok), CloneExpr(lhs.Lhs), lhs.SuffixName + "#", lhs.OptTypeArguments == null ? null : lhs.OptTypeArguments.ConvertAll(CloneType)); } var args = new List<Expression>(); args.Add(k); apply.Args.ForEach(arg => args.Add(CloneExpr(arg))); var applyClone = new ApplySuffix(Tok(apply.tok), lhsClone, args); var c = new ExprRhs(applyClone); reporter.Info(MessageSource.Cloner, apply.Lhs.tok, mse.Member.Name + suffix); return c; } } return base.CloneRHS(rhs); }
void TypeAndToken(out IToken tok, out Type ty, bool inExpressionContext) { Contract.Ensures(Contract.ValueAtReturn(out tok)!=null); Contract.Ensures(Contract.ValueAtReturn(out ty) != null); tok = Token.NoToken; ty = new BoolType(); /*keep compiler happy*/ List<Type> gt; List<Type> tupleArgTypes = null; switch (la.kind) { case 7: { Get(); tok = t; break; } case 8: { Get(); tok = t; ty = new CharType(); break; } case 9: { Get(); tok = t; ty = new IntType(); break; } case 10: { Get(); tok = t; ty = new UserDefinedType(tok, tok.val, null); break; } case 11: { Get(); tok = t; ty = new RealType(); break; } case 6: { Get(); tok = t; int w = StringToInt(tok.val.Substring(2), 0, "bitvectors that wide"); ty = new BitvectorType(w); break; } case 12: { Get(); tok = t; ty = new ObjectType(); break; } case 14: { Get(); tok = t; OptGenericInstantiation(out gt, inExpressionContext); if (gt != null && gt.Count > 1) { SemErr("set type expects only one type argument"); } ty = new SetType(true, gt != null ?gt[0] : null); break; } case 15: { Get(); tok = t; OptGenericInstantiation(out gt, inExpressionContext); if (gt != null && gt.Count > 1) { SemErr("set type expects only one type argument"); } ty = new SetType(false, gt != null ? gt[0] : null); break; } case 16: { Get(); tok = t; OptGenericInstantiation(out gt, inExpressionContext); if (gt != null && gt.Count > 1) { SemErr("multiset type expects only one type argument"); } ty = new MultiSetType(gt != null ? gt[0] : null); break; } case 17: { Get(); tok = t; OptGenericInstantiation(out gt, inExpressionContext); if (gt != null && gt.Count > 1) { SemErr("seq type expects only one type argument"); } ty = new SeqType(gt != null ? gt[0] : null); break; } case 13: { Get(); tok = t; ty = new UserDefinedType(tok, tok.val, null); break; } case 18: { Get(); tok = t; OptGenericInstantiation(out gt, inExpressionContext); if (gt == null) { ty = new MapType(true, null, null); } else if (gt.Count != 2) { SemErr("map type expects two type arguments"); ty = new MapType(true, gt[0], gt.Count == 1 ? new InferredTypeProxy() : gt[1]); } else { ty = new MapType(true, gt[0], gt[1]); } break; } case 19: { Get(); tok = t; OptGenericInstantiation(out gt, inExpressionContext); if (gt == null) { ty = new MapType(false, null, null); } else if (gt.Count != 2) { SemErr("imap type expects two type arguments"); ty = new MapType(false, gt[0], gt.Count == 1 ? new InferredTypeProxy() : gt[1]); } else { ty = new MapType(false, gt[0], gt[1]); } break; } case 5: { Get(); tok = t; OptGenericInstantiation(out gt, inExpressionContext); int dims = StringToInt(tok.val.Substring(5), 1, "arrays of that many dimensions"); ty = theBuiltIns.ArrayType(tok, dims, gt, true); break; } case 54: { Get(); tok = t; tupleArgTypes = new List<Type>(); if (StartOf(6)) { Type(out ty); tupleArgTypes.Add(ty); while (la.kind == 23) { Get(); Type(out ty); tupleArgTypes.Add(ty); } } Expect(55); if (tupleArgTypes.Count == 1) { // just return the type 'ty' } else { var dims = tupleArgTypes.Count; var tmp = theBuiltIns.TupleType(tok, dims, true); // make sure the tuple type exists ty = new UserDefinedType(tok, BuiltIns.TupleTypeName(dims), dims == 0 ? null : tupleArgTypes); } break; } case 1: { Expression e; NameSegmentForTypeName(out e, inExpressionContext); tok = t; while (la.kind == 28) { Get(); Expect(1); tok = t; List<Type> typeArgs; OptGenericInstantiation(out typeArgs, inExpressionContext); e = new ExprDotName(tok, e, tok.val, typeArgs); } ty = new UserDefinedType(e.tok, e); break; } default: SynErr(182); break; } if (IsArrow()) { Expect(32); tok = t; Type t2; Type(out t2); if (tupleArgTypes != null) { gt = tupleArgTypes; } else { gt = new List<Type>{ ty }; } ty = new ArrowType(tok, gt, t2); theBuiltIns.CreateArrowTypeDecl(gt.Count); } }