jif.extension

## Class CallHelper

- java.lang.Object
- - jif.extension.CallHelper

-     public class CallHelper
      extends java.lang.Object

  This is a tool to label-check method calls. This class should be used by creating an instance of it, and then calling the method `checkCall(LabelChecker)`. After the call to that method, the remaining methods (which are getter methods) may be called.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.util.List<Label>` | `actualArgLabels` Labels of the actual arguments.
    `protected java.util.List<polyglot.ast.Expr>` | `actualArgs` Copy of the list of the `Expr` s that are the arguments to the procedure call.
    `protected java.util.List<Label>` | `actualParamLabels` Labels of the actual parameters.
    `protected boolean` | `callChecked`
    `protected polyglot.types.ReferenceType` | `calleeContainer`
    `protected boolean` | `overrideChecker`
    `protected JifMethodInstance` | `overridingMethod` Method instance of the overriding (subclasses') method.
    `protected JifProcedureInstance` | `pi` The procedure being called.
    `protected polyglot.util.Position` | `position` The position of the procedure call
    `protected polyglot.ast.Expr` | `receiverExpr`
    `protected Label` | `receiverLabel` Label of the reference to the object on which the procedure is being called.
    `protected polyglot.types.Type` | `returnType` The return type of the procedure, if there is one.
    `protected PathMap` | `X` The PathMap for the procedure call.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `` | `CallHelper(Label receiverLabel, polyglot.ast.Receiver receiver, polyglot.types.ReferenceType calleeContainer, JifProcedureInstance pi, java.util.List<polyglot.ast.Expr> actualArgs, polyglot.util.Position position)`
    `protected` | `CallHelper(Label receiverLabel, polyglot.ast.Receiver receiver, polyglot.types.ReferenceType calleeContainer, JifProcedureInstance pi, java.util.List<polyglot.ast.Expr> actualArgs, polyglot.util.Position position, boolean overrideChecker)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `bindVarLabels(LabelChecker lc, VarLabel receiverVarLabel, java.util.List<? extends Label> actualArgVarLabels, java.util.List<? extends Label> actualParamVarLabels)` Bind the given var labels to the appropriate labels that have been calculated during the call checking.
    `<N extends polyglot.ast.ProcedureCall> N` | `checkCall(LabelChecker lc, java.util.List<polyglot.types.Type> throwTypes, N call, boolean targetMayBeNull)` Check method calls.
    `void` | `checkOverride(LabelChecker lc)` this.pi is a Jif method instance that this.overridingMethod is attempting to override.
    `protected void` | `constrainArg(LabelChecker lc, int index, polyglot.ast.Expr Ej, polyglot.types.Type formalType)` Add constraints to ensure that the labels of the actual arguments are less than the upper bounds of the formal arguments.
    `protected void` | `constrainFinalActualArgs(JifTypeSystem jts)` Make sure that the actual arg for any formal arg that appears in the signature is final.
    `protected PathMap` | `excPathMap(LabelChecker lc, Label returnLabel, Label pcPriorToInvoke, java.util.List<polyglot.types.Type> throwTypes)`
    `protected static java.util.List<ArgLabel>` | `getArgLabelsFromFormalTypes(java.util.List<? extends polyglot.types.Type> formalTypes, JifTypeSystem jts, polyglot.util.Position pos)`
    `Label` | `instantiate(JifContext A, Label L)`
    `<P extends ActsForParam> P` | `instantiate(JifContext A, P param)` replaces any signature ArgLabels in p with the appropriate label, and replaces any signature ArgPrincipal with the appropriate prinicipal.
    `Principal` | `instantiate(JifContext A, Principal p)`
    `java.util.Set<Principal>` | `instantiate(JifContext A, java.util.Set<Principal> s)`
    `polyglot.types.Type` | `instantiate(JifContext A, polyglot.types.Type t)`
    `protected PathMap` | `labelCheckAndConstrainArgs(LabelChecker lc, PathMap Xjoin)` Label check the arguments.
    `protected PathMap` | `labelCheckAndConstrainParams(LabelChecker lc, java.util.List<polyglot.types.Type> throwTypes)`
    `java.util.List<polyglot.ast.Expr>` | `labelCheckedArgs()`
    `static CallHelper` | `OverrideHelper(JifMethodInstance overridden, JifMethodInstance overriding, LabelChecker lc)`
    `protected static void` | `report(int obscurity, java.lang.String s)`
    `protected Label` | `resolvePCBound(LabelChecker lc)`
    `protected Label` | `resolveReturnLabel(LabelChecker lc)` Returns the instantiated return label.
    `protected Label` | `resolveReturnValueLabel(LabelChecker lc, Label returnLabel)` Returns the instantiated return value label joined with returnLabel.
    `polyglot.types.Type` | `returnType()`
    `protected void` | `satisfiesConstraints(JifProcedureInstance jpi, LabelChecker lc, boolean performInstantiations)` Check if the caller has sufficient authority, and label constraints are satisfied.
    `protected static boolean` | `shouldReport(int obscurity)`
    `protected void` | `updateForNextArg(LabelChecker lc, JifContext A, PathMap Xprev)` Utility method to abstract away passing along label information in the context between arguments during checking.
    `PathMap` | `X()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### receiverLabel

          protected final Label receiverLabel

      Label of the reference to the object on which the procedure is being called.

    - #### receiverExpr

          protected final polyglot.ast.Expr receiverExpr

    - #### calleeContainer

          protected final polyglot.types.ReferenceType calleeContainer

    - #### actualArgs

          protected final java.util.List<polyglot.ast.Expr> actualArgs

      Copy of the list of the `Expr` s that are the arguments to the procedure call. As we label check the argument expressions, we replace the elements of this list with the label checked versions of the argument expressions.

    - #### pi

          protected final JifProcedureInstance pi

      The procedure being called. Also the MethodInstance of the overridden method, when this class is used for overriding checking.

    - #### position

          protected final polyglot.util.Position position

      The position of the procedure call

    - #### actualArgLabels

          protected java.util.List<Label> actualArgLabels

      Labels of the actual arguments.

    - #### actualParamLabels

          protected java.util.List<Label> actualParamLabels

      Labels of the actual parameters.

    - #### X

          protected PathMap X

      The PathMap for the procedure call.

    - #### returnType

          protected polyglot.types.Type returnType

      The return type of the procedure, if there is one.

    - #### callChecked

          protected boolean callChecked

    - #### overrideChecker

          protected final boolean overrideChecker

    - #### overridingMethod

          protected JifMethodInstance overridingMethod

      Method instance of the overriding (subclasses') method. Used only for override checking.

  - ### Constructor Detail

    - #### CallHelper

          public CallHelper(Label receiverLabel,
                            polyglot.ast.Receiver receiver,
                            polyglot.types.ReferenceType calleeContainer,
                            JifProcedureInstance pi,
                            java.util.List<polyglot.ast.Expr> actualArgs,
                            polyglot.util.Position position)

    - #### CallHelper

          protected CallHelper(Label receiverLabel,
                               polyglot.ast.Receiver receiver,
                               polyglot.types.ReferenceType calleeContainer,
                               JifProcedureInstance pi,
                               java.util.List<polyglot.ast.Expr> actualArgs,
                               polyglot.util.Position position,
                               boolean overrideChecker)

  - ### Method Detail

    - #### shouldReport

          protected static boolean shouldReport(int obscurity)

    - #### report

          protected static void report(int obscurity,
                                       java.lang.String s)

    - #### OverrideHelper

          public static CallHelper OverrideHelper(JifMethodInstance overridden,
                                                  JifMethodInstance overriding,
                                                  LabelChecker lc)

    - #### returnType

          public polyglot.types.Type returnType()

    - #### labelCheckedArgs

          public java.util.List<polyglot.ast.Expr> labelCheckedArgs()

    - #### X

          public PathMap X()

    - #### labelCheckAndConstrainParams

          protected PathMap labelCheckAndConstrainParams(LabelChecker lc,
                                                         java.util.List<polyglot.types.Type> throwTypes)
                                                  throws polyglot.types.SemanticException

      Throws:
        `polyglot.types.SemanticException`

    - #### labelCheckAndConstrainArgs

          protected PathMap labelCheckAndConstrainArgs(LabelChecker lc,
                                                       PathMap Xjoin)
                                                throws polyglot.types.SemanticException

      Label check the arguments. Also initializes the array `argLabels`, that is the labels of the actual arguments.
      Parameters:
        `Xjoin` - The pathmap for the call so far, that is, up to the point just before the evaluation of the actual arguments.
      Returns:
        The PathMap for the evaluation of all actual arguments, that is, join_j xj, for all actual arguments xj.
      Throws:
        `polyglot.types.SemanticException`

    - #### updateForNextArg

          protected void updateForNextArg(LabelChecker lc,
                                          JifContext A,
                                          PathMap Xprev)

      Utility method to abstract away passing along label information in the context between arguments during checking.

    - #### constrainArg

          protected void constrainArg(LabelChecker lc,
                                      int index,
                                      polyglot.ast.Expr Ej,
                                      polyglot.types.Type formalType)
                               throws polyglot.types.SemanticException

      Add constraints to ensure that the labels of the actual arguments are less than the upper bounds of the formal arguments.
      Parameters:
        `index` - the ith arg
        `Ej` - the expression of the ith actual arg
        `formalType` - the type of ith formal arg.
      Throws:
        `polyglot.types.SemanticException`

    - #### constrainFinalActualArgs

          protected void constrainFinalActualArgs(JifTypeSystem jts)
                                           throws polyglot.types.SemanticException

      Make sure that the actual arg for any formal arg that appears in the signature is final.
      Throws:
        `polyglot.types.SemanticException`

    - #### resolvePCBound

          protected Label resolvePCBound(LabelChecker lc)
                                  throws polyglot.types.SemanticException

      Throws:
        `polyglot.types.SemanticException`

    - #### resolveReturnLabel

          protected Label resolveReturnLabel(LabelChecker lc)
                                      throws polyglot.types.SemanticException

      Returns the instantiated return label.
      Throws:
        `polyglot.types.SemanticException`

    - #### resolveReturnValueLabel

          protected Label resolveReturnValueLabel(LabelChecker lc,
                                                  Label returnLabel)
                                           throws polyglot.types.SemanticException

      Returns the instantiated return value label joined with returnLabel.
      Throws:
        `polyglot.types.SemanticException`

    - #### excPathMap

          protected PathMap excPathMap(LabelChecker lc,
                                       Label returnLabel,
                                       Label pcPriorToInvoke,
                                       java.util.List<polyglot.types.Type> throwTypes)
                                throws polyglot.types.SemanticException

      Throws:
        `polyglot.types.SemanticException`

    - #### checkCall

          public <N extends polyglot.ast.ProcedureCall> N checkCall(LabelChecker lc,
                                                                    java.util.List<polyglot.types.Type> throwTypes,
                                                                    N call,
                                                                    boolean targetMayBeNull)
                                                             throws polyglot.types.SemanticException

      Check method calls. (Thesis, Figure 4.29)
      Throws:
        `polyglot.types.SemanticException`

    - #### satisfiesConstraints

          protected void satisfiesConstraints(JifProcedureInstance jpi,
                                              LabelChecker lc,
                                              boolean performInstantiations)
                                       throws polyglot.types.SemanticException

      Check if the caller has sufficient authority, and label constraints are satisfied. Thesis, Figure 4.29. This method is called both when checking calls, and when checking overrides. When checking overrides, since we are passed the overriding method (as opposed to the overridden method) we do not perform instantiations of principals and labels from jpi.
      Throws:
        `polyglot.types.SemanticException`

    - #### bindVarLabels

          public void bindVarLabels(LabelChecker lc,
                                    VarLabel receiverVarLabel,
                                    java.util.List<? extends Label> actualArgVarLabels,
                                    java.util.List<? extends Label> actualParamVarLabels)
                             throws polyglot.types.SemanticException

      Bind the given var labels to the appropriate labels that have been calculated during the call checking.
      Parameters:
        `lc` - the LabelChecker
        `receiverVarLabel` - the VarLabel used to stand in for the label of the receiver
        `actualArgVarLabels` - a list of VarLabels that were used to stand in for the labels of the actual arguments
        `actualParamVarLabels` - a list of VarLabels that were used to stand in for the labels of the actual parameters
      Throws:
        `polyglot.types.SemanticException`

    - #### getArgLabelsFromFormalTypes

          protected static java.util.List<ArgLabel> getArgLabelsFromFormalTypes(java.util.List<? extends polyglot.types.Type> formalTypes,
                                                                                JifTypeSystem jts,
                                                                                polyglot.util.Position pos)
                                                                         throws polyglot.types.SemanticException

      Throws:
        `polyglot.types.SemanticException`

    - #### instantiate

          public Label instantiate(JifContext A,
                                   Label L)
                            throws polyglot.types.SemanticException

      Throws:
        `polyglot.types.SemanticException`

    - #### instantiate

          public java.util.Set<Principal> instantiate(JifContext A,
                                                      java.util.Set<Principal> s)
                                               throws polyglot.types.SemanticException

      Throws:
        `polyglot.types.SemanticException`

    - #### instantiate

          public <P extends ActsForParam> P instantiate(JifContext A,
                                                        P param)
                                                 throws polyglot.types.SemanticException

      replaces any signature ArgLabels in p with the appropriate label, and replaces any signature ArgPrincipal with the appropriate prinicipal.
      Throws:
        `polyglot.types.SemanticException`

    - #### instantiate

          public Principal instantiate(JifContext A,
                                       Principal p)
                                throws polyglot.types.SemanticException

      Throws:
        `polyglot.types.SemanticException`

    - #### instantiate

          public polyglot.types.Type instantiate(JifContext A,
                                                 polyglot.types.Type t)
                                          throws polyglot.types.SemanticException

      Throws:
        `polyglot.types.SemanticException`

    - #### checkOverride

          public void checkOverride(LabelChecker lc)
                             throws polyglot.types.SemanticException

      this.pi is a Jif method instance that this.overridingMethod is attempting to override. Previous type checks have made sure that things like abstractness, access flags, throw sets, etc. are ok. We need to check that the labels conform.
      Throws:
        `polyglot.types.SemanticException`