Ejemplo n.º 1
0
        public override void Resolve(ResolutionContext rc)
        {
            //Contract.Requires(rc != null);
              if (Proc != null) {
            // already resolved
            return;
              }
              ResolveAttributes(Attributes, rc);
              Proc = rc.LookUpProcedure(callee) as Procedure;
              if (Proc == null) {
            rc.Error(this, "call to undeclared procedure: {0}", callee);
              }
              foreach (Expr e in Ins) {
            if (e != null) {
              e.Resolve(rc);
            }
              }
              HashSet<Variable> actualOuts = new HashSet<Variable>();
              foreach (IdentifierExpr ide in Outs) {
            if (ide != null) {
              ide.Resolve(rc);
              if (ide.Decl != null) {
            if (actualOuts.Contains(ide.Decl)) {
              rc.Error(this, "left-hand side of call command contains variable twice: {0}", ide.Name);
            } else {
              actualOuts.Add(ide.Decl);
            }
              }
            }
              }

              if (Proc == null)
            return;

              // first make sure that the right number of parameters is given
              // (a similar check is in CheckArgumentTypes, but we are not
              // able to call this method because it cannot cope with Ins/Outs
              // that are null)
              if (Ins.Count != Proc.InParams.Count) {
            rc.Error(this.tok,
                 "wrong number of arguments in call to {0}: {1}",
                 callee, Ins.Count);
            return;
              }
              if (Outs.Count != Proc.OutParams.Count) {
            rc.Error(this.tok,
                 "wrong number of result variables in call to {0}: {1}",
                 callee, Outs.Count);
            return;
              }
              if (IsAsync) {
            if (Proc.OutParams.Count > 0) {
              rc.Error(this.tok, "a procedure called asynchronously can have no output parameters");
              return;
            }
              }

              // Check that type parameters can be determined using the given
              // actual i/o arguments. This is done already during resolution
              // because CheckBoundVariableOccurrences needs a resolution
              // context
              List<Type>/*!*/ formalInTypes = new List<Type>();
              List<Type>/*!*/ formalOutTypes = new List<Type>();
              for (int i = 0; i < Ins.Count; ++i)
            if (Ins[i] != null)
              formalInTypes.Add(cce.NonNull(Proc.InParams[i]).TypedIdent.Type);
              for (int i = 0; i < Outs.Count; ++i)
            if (Outs[i] != null)
              formalOutTypes.Add(cce.NonNull(Proc.OutParams[i]).TypedIdent.Type);

              // we need to bind the type parameters for this
              // (this is expected by CheckBoundVariableOccurrences)
              int previousTypeBinderState = rc.TypeBinderState;
              try {
            foreach (TypeVariable/*!*/ v in Proc.TypeParameters) {
              Contract.Assert(v != null);
              rc.AddTypeBinder(v);
            }
            Type.CheckBoundVariableOccurrences(Proc.TypeParameters,
                                           formalInTypes, formalOutTypes,
                                           this.tok, "types of given arguments",
                                           rc);
              } finally {
            rc.TypeBinderState = previousTypeBinderState;
              }
        }
Ejemplo n.º 2
0
    public override void Resolve(ResolutionContext rc) {
      //Contract.Requires(rc != null);
      if (Proc != null) {
        // already resolved
        return;
      }
      DeclWithFormals dwf = rc.LookUpProcedure(cce.NonNull(this.Name));
      Proc = dwf as Procedure;
      if (dwf == null) {
        rc.Error(this, "implementation given for undeclared procedure: {0}", this.Name);
      } else if (Proc == null) {
        rc.Error(this, "implementations given for function, not procedure: {0}", this.Name);
      }

      int previousTypeBinderState = rc.TypeBinderState;
      try {
        RegisterTypeParameters(rc);

        rc.PushVarContext();
        RegisterFormals(InParams, rc);
        RegisterFormals(OutParams, rc);

        foreach (Variable/*!*/ v in LocVars) {
          Contract.Assert(v != null);
          v.Register(rc);
          v.Resolve(rc);
        }
        foreach (Variable/*!*/ v in LocVars) {
          Contract.Assert(v != null);
          v.ResolveWhere(rc);
        }

        rc.PushProcedureContext();
        foreach (Block b in Blocks) {
          b.Register(rc);
        }

        ResolveAttributes(rc);

        rc.StateMode = ResolutionContext.State.Two;
        foreach (Block b in Blocks) {
          b.Resolve(rc);
        }
        rc.StateMode = ResolutionContext.State.Single;

        rc.PopProcedureContext();
        rc.PopVarContext();

        Type.CheckBoundVariableOccurrences(TypeParameters,
                                           new List<Type>(InParams.Select(Item => Item.TypedIdent.Type).ToArray()),
                                           new List<Type>(OutParams.Select(Item => Item.TypedIdent.Type).ToArray()),
                                           this.tok, "implementation arguments",
                                           rc);
      } finally {
        rc.TypeBinderState = previousTypeBinderState;
      }
      SortTypeParams();
    }