accrue.analysis.defuse

## Class DefUseAnalysisUtil

- java.lang.Object
- - accrue.analysis.interprocanalysis.AnalysisUtil<A>
  - - accrue.analysis.interprocvarcontext.AnalysisUtilVarContext<A,T>
    - - accrue.analysis.interprocvarcontext.AnalysisUtilVarContextDataFlow<VarContext<DefUseAbsVal>,DefUseAbsVal>
      - - accrue.analysis.defuse.DefUseAnalysisUtil

-     public class DefUseAnalysisUtil
      extends AnalysisUtilVarContextDataFlow<VarContext<DefUseAbsVal>,DefUseAbsVal>

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `DefUseAnalysisUtil.Mode`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected DefUseAnalysisUtil.Mode` | `mode`
    `static java.lang.String` | `STRING_CONTENTS`
    `protected boolean` | `trackStrings`
    `protected polyglot.types.TypeSystem` | `ts`

    - ### Fields inherited from class accrue.analysis.interprocvarcontext.AnalysisUtilVarContext

      `trackErrors`

    - ### Fields inherited from class accrue.analysis.interprocanalysis.AnalysisUtil

      `extInfo, instanceInitializersChecked, workQueue`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefUseAnalysisUtil(WorkQueue<VarContext<DefUseAbsVal>> wq, AnalysisUnit currentAnalysisUnit, AccrueExtensionInfo extInfo)`
    `DefUseAnalysisUtil(WorkQueue<VarContext<DefUseAbsVal>> wq, AnalysisUnit currentAnalysisUnit, AccrueExtensionInfo extInfo, DefUseAnalysisUtil.Mode mode, boolean trackStrings)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected java.util.Set<AbstractLocation>` | `abstractLocations(DefUseAbsVal arrayDFI, polyglot.ast.ArrayAccess aa)`
    `protected java.util.Set<AbstractLocation>` | `abstractLocations(DefUseAbsVal targetDFI, polyglot.ast.Field f)`
    `protected java.util.Set<AbstractLocation>` | `abstractLocationsImplicitTarget(DefUseAbsVal targetDFI, polyglot.types.FieldInstance fi)`
    `FinalVarContext<DefUseAbsVal>` | `analyze(polyglot.ast.CodeNode n, VarContext<DefUseAbsVal> input)` Analyze the given code with the given current analysis results
    `FinalVarContext<DefUseAbsVal>` | `analyzeInitializersForDataFlow(VarContext<DefUseAbsVal> before)` Analyze the initializers for the current analysis unit given the current analysis results
    `DefUseAbsVal` | `bottomAbstractValue()`
    `FinalVarContext<DefUseAbsVal>` | `callNonVirtual(polyglot.types.ProcedureInstance pi, AnalysisContext calleeContext, HContext receiver, DefUseAbsVal receiverAbsVal, VarContext<DefUseAbsVal> input, DataFlowNodeIdentifier callSite, boolean canTerminateNormally)` Process a call to a non-virtual call to `pi` with `VarContext` `input`.
    `VarContext<DefUseAbsVal>` | `createInitContext()` Create an initial variable context
    `protected FinalVarContext<DefUseAbsVal>` | `getAnalysisResultsFromWorkQueue(AnalysisUnit callee, VarContext<DefUseAbsVal> beforeCall, DataFlowNodeIdentifier callSite)` Get the analysis results for the given callee and variable context.
    `<T> java.util.Set<T>` | `getCallResults(java.lang.String analysisKey, polyglot.ast.ProcedureCall pcall)` Return analysis results for a procedure call.
    `protected java.util.Set<polyglot.types.ProcedureInstance>` | `getCallTargets(polyglot.ast.Call n)`
    `protected <T> java.util.Set<T>` | `getNativeCallResults(java.lang.String analysisKey, polyglot.ast.ProcedureCall n, polyglot.types.ProcedureInstance pi, HContext o)` Returns analysis results for a native call target.
    `protected <T> java.util.Set<T>` | `getNonVirtualCallResults(java.lang.String analysisKey, polyglot.ast.ProcedureCall n, polyglot.types.ProcedureInstance pi, HContext o)` Returns analysis results for a specific target.
    `protected java.util.Set<polyglot.types.ClassType>` | `getReceiverTypes(polyglot.ast.Call n)`
    `protected FinalVarContext<DefUseAbsVal>` | `guessAnalysisForMissingCode(polyglot.types.ProcedureInstance pi, AnalysisContext calleeContext, HContext receiver, VarContext<DefUseAbsVal> input, DefUseAbsVal receiverAbsVal, java.util.List<DefUseAbsVal> argAbsVals, java.util.Set<ExitMap.Key> expectedExits, DataFlowNodeIdentifier callSite)` Get analysis results for procedures for which the source code is missing.
    `protected FinalVarContext<DefUseAbsVal>` | `guessAnalysisForMissingReceiver(polyglot.types.ProcedureInstance pi, VarContext<DefUseAbsVal> input, DefUseAbsVal receiverAbsVal, java.util.List<DefUseAbsVal> argAbsVals, java.util.Set<ExitMap.Key> expectedExits, DataFlowNodeIdentifier callSiteNode)` Subclasses should override as a stop gap measure if the receiver is missing, i.e., if the points to set of the receiver expression is empty.
    `protected boolean` | `hasReferenceVariable(AnalysisContext context, polyglot.ast.Expr e)`
    `protected boolean` | `hasReferenceVariable(AnalysisContext context, polyglot.ast.Formal f)`
    `protected boolean` | `mayBeNull(DefUseAbsVal exprDFI, polyglot.ast.Expr e, polyglot.visit.FlowGraph.Peer<VarContext<DefUseAbsVal>> peer)`
    `protected boolean` | `mayThrowClassCastException(DefUseAbsVal exprDFI, polyglot.ast.Cast cast, polyglot.visit.FlowGraph.Peer<VarContext<DefUseAbsVal>> peer)`
    `DefUseAnalysisUtil.Mode` | `mode()`
    `protected java.util.Set<HContext>` | `pointsTo(DefUseAbsVal exprDFI, polyglot.ast.Expr e)`
    `protected java.util.Set<AbstractLocation>` | `stringLocations(DefUseAbsVal stringDFI, polyglot.ast.Expr stringExpr)`
    `boolean` | `trackStrings()`

    - ### Methods inherited from class accrue.analysis.interprocvarcontext.AnalysisUtilVarContextDataFlow

      `call, call, call, callFromNew, constructorCall, constructorCallFromConstructor, getAnalysisResultsFromWorkQueue, makeFinalVarContext, mergeCallResults, prepareCalleeContext`

    - ### Methods inherited from class accrue.analysis.interprocvarcontext.AnalysisUtilVarContext

      `addLocations, analysisName, computeExpectedExits, createFinalVarContext, emptyFinalVarContext, getAnalysisForMissingReceiver, getLocationAbsVal, getSignatureForMissingCode, guessAnalysisForMissingCode, handleRecursiveCall, preCallNonVirtual, recordRead, recordReads, recordWrite, recordWrites, signatureAnalysisNames`

    - ### Methods inherited from class accrue.analysis.interprocanalysis.AnalysisUtil

      `abstractLocations, abstractLocations, abstractLocations, abstractLocations, abstractLocations, abstractLocations, abstractLocations, abstractLocations, abstractLocations, abstractLocationsForArray, abstractLocationsForArray, abstractLocationsForArray, abstractLocationsImplicitTarget, analyzeInitializers, analyzeStaticInitializers, createExitMap, currentAnalysisUnit, currentClass, currentContext, extensionInfo, instanceInitializers, leq, maybeRecursiveCall, pointsTo, pointsTo, pointsTo, pointsTo, pointsTo, pointsTo, pointsTo, pointsTo, pointsTo, pointsToGraph, pointsToThis, process, recordMissingCode, typeSystem, upperBound, workQueue`

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

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

- - ### Field Detail

    - #### ts

          protected polyglot.types.TypeSystem ts

    - #### mode

          protected final DefUseAnalysisUtil.Mode mode

    - #### trackStrings

          protected final boolean trackStrings

    - #### STRING_CONTENTS

          public static final java.lang.String STRING_CONTENTS

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### DefUseAnalysisUtil

          public DefUseAnalysisUtil(WorkQueue<VarContext<DefUseAbsVal>> wq,
                            AnalysisUnit currentAnalysisUnit,
                            AccrueExtensionInfo extInfo)

    - #### DefUseAnalysisUtil

          public DefUseAnalysisUtil(WorkQueue<VarContext<DefUseAbsVal>> wq,
                            AnalysisUnit currentAnalysisUnit,
                            AccrueExtensionInfo extInfo,
                            DefUseAnalysisUtil.Mode mode,
                            boolean trackStrings)

  - ### Method Detail

    - #### mode

          public DefUseAnalysisUtil.Mode mode()

    - #### analyze

          public FinalVarContext<DefUseAbsVal> analyze(polyglot.ast.CodeNode n,
                                              VarContext<DefUseAbsVal> input)
                                                throws polyglot.types.SemanticException

      Description copied from class: `AnalysisUtil`
      Analyze the given code with the given current analysis results
      Specified by:
        `analyze` in class `AnalysisUtil<VarContext<DefUseAbsVal>>`
      Parameters:
        `n` - Code to analyze
        `input` - analysis result before analyzing the given code
      Returns:
        Map from exit condition to analysis result
      Throws:
        `polyglot.types.SemanticException` - thrown if the analysis fails

    - #### createInitContext

          public VarContext<DefUseAbsVal> createInitContext()

      Description copied from class: `AnalysisUtilVarContext`
      Create an initial variable context
      Overrides:
        `createInitContext` in class `AnalysisUtilVarContext<VarContext<DefUseAbsVal>,DefUseAbsVal>`
      Returns:
        initial variable context

    - #### getCallTargets

          protected java.util.Set<polyglot.types.ProcedureInstance> getCallTargets(polyglot.ast.Call n)

    - #### getReceiverTypes

          protected java.util.Set<polyglot.types.ClassType> getReceiverTypes(polyglot.ast.Call n)

    - #### getNonVirtualCallResults

          protected <T> java.util.Set<T> getNonVirtualCallResults(java.lang.String analysisKey,
                                                      polyglot.ast.ProcedureCall n,
                                                      polyglot.types.ProcedureInstance pi,
                                                      HContext o)

      Returns analysis results for a specific target.

    - #### getNativeCallResults

          protected <T> java.util.Set<T> getNativeCallResults(java.lang.String analysisKey,
                                                  polyglot.ast.ProcedureCall n,
                                                  polyglot.types.ProcedureInstance pi,
                                                  HContext o)

      Returns analysis results for a native call target. Native analysis results are recorded on the call site, but use the AnalysisContext of the callee.

    - #### getCallResults

          public <T> java.util.Set<T> getCallResults(java.lang.String analysisKey,
                                            polyglot.ast.ProcedureCall pcall)

      Return analysis results for a procedure call. For virtual calls, returns the union of results for each potential call target.

    - #### callNonVirtual

          public FinalVarContext<DefUseAbsVal> callNonVirtual(polyglot.types.ProcedureInstance pi,
                                                     AnalysisContext calleeContext,
                                                     HContext receiver,
                                                     DefUseAbsVal receiverAbsVal,
                                                     VarContext<DefUseAbsVal> input,
                                                     DataFlowNodeIdentifier callSite,
                                                     boolean canTerminateNormally)
                                                       throws polyglot.types.SemanticException

      Description copied from class: `AnalysisUtilVarContextDataFlow`
      Process a call to a non-virtual call to `pi` with `VarContext` `input`.
      Overrides:
        `callNonVirtual` in class `AnalysisUtilVarContextDataFlow<VarContext<DefUseAbsVal>,DefUseAbsVal>`
      Parameters:
        `pi` - call to analyze
        `calleeContext` - procedure analysis context
        `receiver` - abstract heap object for the callee
        `input` - variable context before analyzing the method
        `callSite` - the call site for the procedure call
        `canTerminateNormally` - true if the called procedure can terminate normally
      Returns:
        new map of variables to their values after the analysis
      Throws:
        `polyglot.types.SemanticException` - if analysis fails

    - #### mayBeNull

          protected boolean mayBeNull(DefUseAbsVal exprDFI,
                          polyglot.ast.Expr e,
                          polyglot.visit.FlowGraph.Peer<VarContext<DefUseAbsVal>> peer)

    - #### mayThrowClassCastException

          protected boolean mayThrowClassCastException(DefUseAbsVal exprDFI,
                                           polyglot.ast.Cast cast,
                                           polyglot.visit.FlowGraph.Peer<VarContext<DefUseAbsVal>> peer)

    - #### abstractLocations

          protected java.util.Set<AbstractLocation> abstractLocations(DefUseAbsVal targetDFI,
                                                          polyglot.ast.Field f)

    - #### abstractLocationsImplicitTarget

          protected java.util.Set<AbstractLocation> abstractLocationsImplicitTarget(DefUseAbsVal targetDFI,
                                                                        polyglot.types.FieldInstance fi)

    - #### abstractLocations

          protected java.util.Set<AbstractLocation> abstractLocations(DefUseAbsVal arrayDFI,
                                                          polyglot.ast.ArrayAccess aa)

    - #### stringLocations

          protected java.util.Set<AbstractLocation> stringLocations(DefUseAbsVal stringDFI,
                                                        polyglot.ast.Expr stringExpr)

    - #### hasReferenceVariable

          protected boolean hasReferenceVariable(AnalysisContext context,
                                     polyglot.ast.Expr e)

    - #### hasReferenceVariable

          protected boolean hasReferenceVariable(AnalysisContext context,
                                     polyglot.ast.Formal f)

    - #### pointsTo

          protected java.util.Set<HContext> pointsTo(DefUseAbsVal exprDFI,
                                         polyglot.ast.Expr e)

    - #### getAnalysisResultsFromWorkQueue

          protected FinalVarContext<DefUseAbsVal> getAnalysisResultsFromWorkQueue(AnalysisUnit callee,
                                                                      VarContext<DefUseAbsVal> beforeCall,
                                                                      DataFlowNodeIdentifier callSite)
                                                                           throws polyglot.types.SemanticException

      Description copied from class: `AnalysisUtilVarContextDataFlow`
      Get the analysis results for the given callee and variable context.
      Specified by:
        `getAnalysisResultsFromWorkQueue` in class `AnalysisUtilVarContextDataFlow<VarContext<DefUseAbsVal>,DefUseAbsVal>`
      Parameters:
        `callee` - Code for a callee that is to be analyzed
        `beforeCall` - variable context before the call to the callee
      Returns:
        new variable context after performing the analysis
      Throws:
        `polyglot.types.SemanticException` - thrown for an analysis error

    - #### bottomAbstractValue

          public DefUseAbsVal bottomAbstractValue()

      Specified by:
        `bottomAbstractValue` in class `AnalysisUtilVarContext<VarContext<DefUseAbsVal>,DefUseAbsVal>`
      Returns:
        The bottom value in the abstract value lattice

    - #### guessAnalysisForMissingReceiver

          protected FinalVarContext<DefUseAbsVal> guessAnalysisForMissingReceiver(polyglot.types.ProcedureInstance pi,
                                                                      VarContext<DefUseAbsVal> input,
                                                                      DefUseAbsVal receiverAbsVal,
                                                                      java.util.List<DefUseAbsVal> argAbsVals,
                                                                      java.util.Set<ExitMap.Key> expectedExits,
                                                                      DataFlowNodeIdentifier callSiteNode)

      Description copied from class: `AnalysisUtilVarContext`
      Subclasses should override as a stop gap measure if the receiver is missing, i.e., if the points to set of the receiver expression is empty.
      Specified by:
        `guessAnalysisForMissingReceiver` in class `AnalysisUtilVarContext<VarContext<DefUseAbsVal>,DefUseAbsVal>`
      Parameters:
        `pi` - missing procedure
        `input` - variable context before analysis
        `receiverAbsVal` - abstract value for the receiver
        `argAbsVals` - list of abstract values for the procedure arguments
        `expectedExits` - set of expected exit keys
      Returns:
        New variable context updated from the input during analysis

    - #### guessAnalysisForMissingCode

          protected FinalVarContext<DefUseAbsVal> guessAnalysisForMissingCode(polyglot.types.ProcedureInstance pi,
                                                                  AnalysisContext calleeContext,
                                                                  HContext receiver,
                                                                  VarContext<DefUseAbsVal> input,
                                                                  DefUseAbsVal receiverAbsVal,
                                                                  java.util.List<DefUseAbsVal> argAbsVals,
                                                                  java.util.Set<ExitMap.Key> expectedExits,
                                                                  DataFlowNodeIdentifier callSite)

      Description copied from class: `AnalysisUtilVarContextDataFlow`
      Get analysis results for procedures for which the source code is missing.
      Overrides:
        `guessAnalysisForMissingCode` in class `AnalysisUtilVarContextDataFlow<VarContext<DefUseAbsVal>,DefUseAbsVal>`
      Parameters:
        `pi` - procedure instance for which the code is missing
        `calleeContext` - context for the procedure missing source code
        `receiver` - Abstract heap object for the receiver of the missing procedure
        `input` - context before analyzing the missing procedure
        `receiverAbsVal` - abstract value for the receiver of the missing procedure
        `argAbsVals` - abstract values for the arguments to the missing procedure
        `expectedExits` - expected exit keys for the missing procedure (for many analyses the `FinalVarContext` must have an entry for each exit key)
        `callSite` - AST node and analysis context for the call site
      Returns:
        `FinalVarContext` estimating the results of analyzing the missing code

    - #### analyzeInitializersForDataFlow

          public FinalVarContext<DefUseAbsVal> analyzeInitializersForDataFlow(VarContext<DefUseAbsVal> before)
                                                                       throws polyglot.types.SemanticException

      Description copied from class: `AnalysisUtilVarContextDataFlow`
      Analyze the initializers for the current analysis unit given the current analysis results
      Specified by:
        `analyzeInitializersForDataFlow` in class `AnalysisUtilVarContextDataFlow<VarContext<DefUseAbsVal>,DefUseAbsVal>`
      Returns:
        Map from exit condition to analysis result
      Throws:
        `polyglot.types.SemanticException` - thrown if the analysis fails

    - #### trackStrings

          public boolean trackStrings()