Protected
getGet the control flow vertex for the given node id or fail if it does not exist.
Protected
getGet the dataflow graph vertex for the given id
Protected
getA helper function to get the normalized AST node for the given id or fail if it does not exist.
Protected
getProtected
onProtected
This event triggers for every subsetting call, i.e., for every call to [[
, [
, or $
.
Protected
onProtected
This event triggers for every call to any of the *apply
functions.
For example, lapply
in lapply(1:10, function(x) { x + 1 })
.
More specifically, this relates to the corresponding BuiltInProcessorMapper handler.
Protected
onProtected
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.
Protected
onProtected
onProtected
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.
Protected
onProtected
This function is responsible for dispatching the appropriate event based on a given dataflow vertex. The default serves as a backend for the event functions, but you may overwrite and extend this function at will.
onDispatchFunctionCallOrigins for the aggregation in case the function call target is ambiguous.
Protected
onProtected
Given a function call that has multiple targets (e.g., two potential built-in definitions). This function is responsible for calling onDispatchFunctionCallOrigin for each of the origins, and aggregating their results (which is just additive by default). If you want to change the behavior in case of multiple potential function definition targets, simply overwrite this function with the logic you desire.
Protected
onProtected
onProtected
This event triggers for every call to the eval
function.
For example, eval
in eval(parse(text = "x + 1"))
.
More specifically, this relates to the corresponding BuiltInProcessorMapper handler.
Protected
onProtected
This event triggers for every expression list - implicit or explicit, but not for the root program (see SemanticCfgGuidedVisitor#onProgram|onProgram
for that).
For example, this triggers for the expression list created by {
and }
in ìf (TRUE) { x <- 1; y <- 2; }
. But also for the implicit
expression list x <- x + 1
in for(x in 1:10) x <- x + 1
.
Protected
onProtected
onProtected
This event triggers for every call to the for
loop function, which is used to implement the for
loop control flow.
For example, this triggers for for
in for(i in 1:10) { print(i) }
.
More specifically, this relates to the corresponding BuiltInProcessorMapper handler.
Protected
onCalled for every anonymous function definition.
For example, function(x) { x + 1 }
in lapply(1:10, function(x) { x + 1 })
.
Protected
onProtected
This event triggers for every call to the get
function, which is used to access variables in the global environment.
For example, get
in get("x")
.
Please be aware, that with flowR resolving the get
during the dataflow analysis,
this may very well trigger a SemanticCfgGuidedVisitor#onVariableUse|onVariableUse
event as well.
Protected
onProtected
This event triggers for every call to the if
function, which is used to implement the if-then-else
control flow.
Protected
onProtected
This event triggers for every call to a function which loads a library.
For example, library
in library(dplyr)
.
More specifically, this relates to the corresponding BuiltInProcessorMapper handler.
Protected
onProtected
This event triggers for every call that (to the knowledge of flowr) constructs a (new) list.
For example, this triggers for list
in list(1, 2, 3)
.
More specifically, this relates to the corresponding BuiltInProcessorMapper handler.
Protected
onCalled for every constant logical value in the program.
For example, TRUE
in if(TRUE) { ... }
.
Protected
onProtected
onCalled for every occurrence of a NULL
in the program.
Protected
onCalled for every constant number value in the program.
For example, 42
in print(42)
.
Protected
onProtected
This event triggers for every call to R's pipe operator, i.e., for every call to |>
.
Protected
onProtected
This event is called for the root program node, i.e., the program that is being analyzed.
Protected
onProtected
This event triggers for every call to the quote
function, which is used to quote expressions.
For example, quote
in quote(x + 1)
.
More specifically, this relates to the corresponding BuiltInProcessorMapper handler.
Protected
onProtected
This event triggers for every call to the repeat
loop function, which is used to implement the repeat
loop control flow.
For example, this triggers for repeat
in repeat { i <- i + 1; if(i >= 10) break }
.
More specifically, this relates to the corresponding BuiltInProcessorMapper handler.
Protected
onProtected
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.
Protected
onProtected
This event triggers for every call to the rm
function, which is used to remove variables from the environment.
For example, rm
in rm(x)
.
Protected
onProtected
This event triggers for every call to the source
function.
For example, source
in source("script.R")
.
By default, this does not provide the resolved source file. Yet you can access the DataflowGraph to ask for sourced files.
More specifically, this relates to the corresponding BuiltInProcessorMapper handler.
Protected
onProtected
This event triggers for every call to a special binary operator, i.e., every binary function call that starts and ends with a %
sign.
For example, this triggers for%in%
in x %in% y
.
More specifically, this relates to the corresponding BuiltInProcessorMapper handler.
Protected
onProtected
onCalled for every constant string value in the program.
For example, "Hello World"
in print("Hello World")
.
Protected
onProtected
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.
Protected
onCalled for every variable that is written within the program. You can use getOrigins to get the origins of the variable.
For example, x
in x <- 42
or x
in assign("x", 42)
.
See SemanticCfgGuidedVisitor#onAssignmentCall for the assignment call. This event handler also provides you with information on the source.
Protected
onCalled for every variable that is read within the program. You can use getOrigins to get the origins of the variable.
For example, x
in print(x)
.
Protected
onProtected
This event triggers for every call that (to the knowledge of flowr) constructs a (new) vector.
For example, this triggers for c
in c(1, 2, 3)
.
More specifically, this relates to the corresponding BuiltInProcessorMapper handler.
Protected
onProtected
onProtected
This event triggers for every call to the while
loop function, which is used to implement the while
loop control flow.
For example, this triggers for while
in while(i < 10) { i <- i + 1 }
.
More specifically, this relates to the corresponding BuiltInProcessorMapper handler.
Start the visiting process.
Protected
startProtected
visitProtected
See DataflowAwareCfgGuidedVisitor#visitFunctionCall for the base implementation.
This function is called for every function call in the program and dispatches the appropriate event.
You probably do not have to overwrite it and just use SemanticCfgGuidedVisitor#onUnnamedCall|onUnnamedCall
for anonymous calls,
or SemanticCfgGuidedVisitor#onDispatchFunctionCallOrigins|onDispatchFunctionCallOrigins
for named calls (or just overwrite
the events you are interested in directly).
Protected
visitProtected
See DataflowAwareCfgGuidedVisitor#visitFunctionDefinition for the base implementation.
This function is called for every function definition in the program and dispatches the appropriate event.
You probably do not have to overwrite it and just use SemanticCfgGuidedVisitor#onFunctionDefinition|onFunctionDefinition
instead.
Protected
visitcall this function to indicate that a node is to be considered visited.
true
if the node was not visited before, false
otherwise
Protected
visitProtected
See DataflowAwareCfgGuidedVisitor#visitUnknown for the base implementation.
This function is called for every unknown vertex in the program.
It dispatches the appropriate event based on the type of the vertex.
In case you have to overwrite this function please make sure to still call this implementation to get a correctly working SemanticCfgGuidedVisitor#onProgram|onProgram
.
Protected
visitSee DataflowAwareCfgGuidedVisitor#visitValue for the base implementation. This now dispatches the value to the appropriate event handler based on its type.
Protected
visitProtected
See DataflowAwareCfgGuidedVisitor#visitVariableDefinition for the base implementation.
This function is called for every variable definition in the program and dispatches the appropriate event.
You probably do not have to overwrite it and just use SemanticCfgGuidedVisitor#onVariableDefinition|onVariableDefinition
instead.
Protected
visitProtected
See DataflowAwareCfgGuidedVisitor#visitVariableUse for the base implementation.
This function is called for every use of a variable in the program and dispatches the appropriate event.
You probably do not have to overwrite it and just use SemanticCfgGuidedVisitor#onVariableUse|onVariableUse
instead.
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:
Obtaining the origins of the call to
foo
will return both built-in functionslibrary
andrm
. 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.