Class SemanticCfgGuidedVisitor<OtherInfo, ControlFlow, Ast, Dfg, Config>

This visitor extends on the DataflowAwareCfgGuidedVisitor by dispatching visitors for separate function calls as well, providing more information! In a way, this is the mixin of syntactic and dataflow guided visitation.

Overwrite the functions starting with on to implement your logic. In general, there is just one special case that you need to be aware of:

In the context of a function call, flowR may be unsure to which origin the call relates! Consider the following example:

if(u) foo <- library else foo <- rm
foo(x)

Obtaining the origins of the call to foo will return both built-in functions library and rm. The general semantic visitor cannot decide on how to combine these cases, and it is up to your overload of SemanticCfgGuidedVisitor#onDispatchFunctionCallOrigins|onDispatchFunctionCallOrigins to decide how to handle this.

Use BasicCfgGuidedVisitor#start to start the traversal.

Type Parameters

Hierarchy (View Summary)

Hierarchy-Diagram

UML class diagram of SemanticCfgGuidedVisitor

Constructors

Properties

config: Config
visited: Map<NodeId, number>

Methods

  • Protected

    This event triggers for every assignment call, i.e., for every call to <- or = that assigns a value to a variable.

    For example, this triggers for <- in x <- 42 or assign in assign("x", 42). This also triggers for the data.table assign := active within subsetting calls, e.g., DT[, x := 42].

    Please be aware that replacements (e.g. assignments with a function call on the target side) like names(x) <- 3 are subject to SemanticCfgGuidedVisitor#onReplacementCall|onReplacementCall instead.

    Parameters

    Returns void

  • Protected

    This event triggers for every function call that is not handled by a specific overload, and hence may be a function that targets a user-defined function. In a way, these are functions that are named, but flowR does not specifically care about them (currently) wrt. to their dataflow impact.

    Use SemanticCfgGuidedVisitor#getOrigins|getOrigins to get the origins of the call.

    For example, this triggers for foo(x) in

    foo <- function(x) { x + 1 }
    foo(x)

    This explicitly will not trigger for scenarios in which the function has no name (i.e., if it is anonymous). For such cases, you may rely on the SemanticCfgGuidedVisitor#onUnnamedCall|onUnnamedCall event. The main reason for this separation is part of flowR's handling of these functions, as anonymous calls cannot be resolved using the active environment.

    Parameters

    Returns void

  • Protected

    This event triggers for every call to a function that replaces a value in a container, such as names(x) <- 3.

    This is different from SemanticCfgGuidedVisitor#onAssignmentCall|onAssignmentCall in that it does not assign a value to a variable, but rather replaces a value in a container.

    For example, this triggers for names in names(x) <- 3, but not for x <- 3.

    More specifically, this relates to the corresponding BuiltInProcessorMapper handler.

    Parameters

    Returns void

  • Called for every constant symbol value in the program.

    For example, foo in library(foo) or a in l$a. This most likely happens as part of non-standard-evaluation, i.e., the symbol is not evaluated to a value, but used as a symbol in and of itself.

    Please note, that due to its special behaviors, NULL is handled in SemanticCfgGuidedVisitor#onNullConstant|onNullConstant and not here.

    Parameters

    Returns void

  • Protected

    This event triggers for every anonymous call within the program.

    For example, (function(x) { x + 1 })(42) or the second call in a()().

    This is separate from SemanticCfgGuidedVisitor#onDefaultFunctionCall|onDefaultFunctionCall which is used for named function calls that do not trigger any of these events. The main differentiation for these calls is that you may not infer their semantics from any name alone and probably have to rely on SemanticCfgGuidedVisitor#getOrigins|getOrigins to get more information.

    Parameters

    Returns void