Class VarInfo
- Object
-
- VarInfo
-
- All Implemented Interfaces:
Serializable
,Cloneable
@Interned public final class VarInfo extends Object implements Cloneable, Serializable
Represents information about a particular variable for a program point. This object doesn't hold the value of the variable at a particular step of the program point, but can get the value it holds when given a ValueTuple using the getValue() method. VarInfo also includes info about the variable's name, its declared type, its file representation type, its internal type, and its comparability.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
VarInfo.IndexComparator
Compare names by index.static class
VarInfo.LangFlags
static class
VarInfo.Pair
Class used to contain a pair of VarInfos and their sample count.static class
VarInfo.RefType
static class
VarInfo.VarFlags
static class
VarInfo.VarKind
-
Field Summary
Fields Modifier and Type Field Description int
arr_dims
Number of array dimensions (0 or 1).VarInfoAux
aux
Auxiliary info.boolean
canBeMissing
True if a missing/nonsensical value was ever observed for this variable.VarComparability
comparability
Comparability info.static Logger
debugMissing
Debug missing vals.@MonotonicNonNull Derivation
derived
Whether and how derived.@Nullable VarInfo
derivedParamCached
Cached value for getDerivedParam().static boolean
dkconfig_constant_fields_simplify
If true, the treat static constants (such as MapQuick.GeoPoint.FACTOR) as fields within an object rather than as a single name.static boolean
dkconfig_declared_type_comparability
If true, then variables are only considered comparable if they are declared with the same type.@Nullable VarInfo
enclosing_var
For documentation, seeget_enclosing_var()
.Equality
equalitySet
Which equality group this belongs to.ProglangType
file_rep_type
Type as written in the data trace file -- i.e., it is the source variable type mapped into the set of basic types recognized by Daikon.@MonotonicNonNull List<VarInfo>
function_args
The arguments that were used to create this function application.boolean
is_static_constant
Invariants:
is_static_constant == (value_index == -1);
is_static_constant == (static_constant_value !@MonotonicNonNull Boolean
isDerivedParamCached
Cached value for isDerivedParam().EnumSet<VarInfo.LangFlags>
lang_flags
List<VarParent>
parents
Parent program points in ppt hierarchy (optional)@Nullable VarInfo
postState
non-null if this is an orig() variable.PptTopLevel
ppt
The program point this variable is in.@Nullable VarInfo.RefType
ref_type
@Nullable String
relative_name
The relative name of this variable with respect to its enclosing variable.ProglangType
rep_type
Type as internally stored by Daikon.ProglangType
type
Type as declared in the target program.int
value_index
The index in a ValueTuple (more generally, in a list of values).EnumSet<VarInfo.VarFlags>
var_flags
VarInfo.VarKind
var_kind
FileIO.VarDefinition
vardef
int
varinfo_index
The index in lists of VarInfo objects.
-
Constructor Summary
Constructors Constructor Description VarInfo(FileIO.VarDefinition vardef)
Create VarInfo from VarDefinition.VarInfo(VarInfo vi)
Create a VarInfo with the same values as vi.VarInfo(String name, ProglangType type, ProglangType file_rep_type, VarComparability comparability, boolean is_static_constant, @Nullable @Interned Object static_constant_value, VarInfoAux aux)
Create the specified VarInfo.VarInfo(String name, ProglangType type, ProglangType file_rep_type, VarComparability comparability, VarInfoAux aux)
Create the specified non-static VarInfo.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
apply_subscript(String subscript)
Adds a subscript (or sequence) to an array variable.static String
apply_subscript(String sequence, String subscript)
Adds a subscript (or subsequence) to an array name.static VarInfo[]
arrayclone_simple(VarInfo[] a_old)
Given an array of VarInfo objects, return an array of clones, where references to the originals have been modified into references to the new ones (so that the new set is self-consistent).static boolean
assertionsEnabled()
VarInfo
canonicalRep()
Canonical representative that's equal to this variable.void
checkRep()
Throws an exception if this object is malformed.void
checkRepNoPpt()
Throws an exception if this object is malformed.boolean
comparableByType(VarInfo var2)
Without using comparability info, check that this is comparable to var2.boolean
comparableNWay(VarInfo var2)
Without using comparability info, check that this is comparable to var2.static boolean
compare_vars(VarInfo vari, int vari_shift, VarInfo varj, int varj_shift, boolean test_lessequal)
Given two variables I and J, indicate whether it is necessarily the case that i≤j or i≥j.boolean
compatible(VarInfo var2)
Two variables are "compatible" if their declared types are castable and their comparabilities are comparable.int
complexity()
Returns a rough indication of the complexity of the variable.Object
constantValue()
Returns the static constant value of this variable.@Nullable Invariant
createGuardingPredicate(boolean install)
Create a guarding predicate for this VarInfo, that is, an invariant that ensures that this object is available for access to variables that reference it, such as fields.String[]
csharp_array_split()
Splits an array variable into the array and field portions.String
csharp_collection_string()
If the variable is an array, returns a valid C# 'Select' statement representing the array.String
csharp_name()
Returns the name of this variable as a valid C# Code Contract.String
csharp_name(@Nullable String index)
Returns the name of this variable as a valid C# Code Contract.String
dbc_name()
Returns the name in DBC format.int
derivedDepth()
returns the depth of derivationList<Derivation>
derivees()
Return all derived variables that build off this one.boolean
eltsCompatible(VarInfo sclvar)
Return true if this sequence variable's element type is compatible with the scalar variable.String
esc_name()
Returns the name of this variable in ESC format.String
esc_name(@Nullable String index)
Returns the name of this variable in ESC format.static String[]
esc_quantify(boolean elementwise, VarInfo... vars)
Quantifies over the specified array variables in ESC format.static String[]
esc_quantify(VarInfo... vars)
Quantifies over the specified array variables in ESC format.@Nullable PptTopLevel
find_object_ppt(PptMap all_ppts)
Looks for an OBJECT ppt that corresponds to the type of this variable.static String
fix_csharp_type_name(String type)
Transforms a Daikon type representation into a valid C# type.int
get_add_amount()
Returns the integer offset if this variable is an addition such as a+2.List<VarInfo>
get_all_constituent_vars()
Returns a list of all of the basic (non-derived) variables that are used to make up this variable.List<VarInfo>
get_all_enclosing_vars()
Returns a list of all of the variables that enclose this one.List<String>
get_all_simple_names()
Returns a list of all of the simple names that make up this variable. this includes each field and function name in the variable.VarInfo
get_array_var()
For array variables, returns the variable that is a simple array.VarInfo
get_base_array()
Returns the VarInfo that represents the base array of this array.@Nullable VarInfo
get_base_array_hashcode()
Returns the VarInfo that represents the hashcode of the base array of this array.@Nullable VarInfo
get_enclosing_var()
Returns the variable that encloses this one.VarInfo
get_equalitySet_leader()
Returns the leader in the variable's equality set.int
get_equalitySet_size()
Returns the number of elements in the variable's equality set.Set<VarInfo>
get_equalitySet_vars()
Returns the vars_info in the variable's equality set.Quantify.Term
get_length()
Returns the length of this array.Quantify.Term
get_lower_bound()
Returns the lower bound of the array or slice.static String
get_simplify_free_index(VarInfo... vars)
Get a fresh variable name that doesn't appear in the given variable in simplify format.static String[]
get_simplify_free_indices(VarInfo... vars)
Get a 2 fresh variable names that doesn't appear in the given variable in simplify format.String
get_simplify_selectNth(String simplify_index_name, boolean free, int index_off)
Return a string in simplify format that will seclect the (index_base + index_off)-th element of the sequence specified by this variable.String
get_simplify_selectNth_lower(int index_off)
Return a string in simplify format that will seclect the index_off element in a sequence that has a lower bound.@Nullable String
get_simplify_size_name()
Returns the name of the size variable that correponds to this array variable in simplify format.String @Nullable []
get_simplify_slice_bounds()
Returns the upper and lower bounds of the slice in simplify format.Quantify.Term
get_upper_bound()
Returns the upper bound of the array or slice.String
get_value_info()
ValueSet
get_value_set()
Return the set of values that have been seen so far for this variable.VarInfoName
get_VarInfoName()
Temporary to let things compile now that name is private.@Nullable VarInfo
getDerivedParam()
Return a VarInfo that has two properties: this is a derivation of it, and it is a parameter variable.double[]
getDoubleArrayValue(ValueTuple vt)
Return the value of a double[] variable.double
getDoubleValue(ValueTuple vt)
Return the value of a double variable.List<VarInfo>
getGuardingList()
Finds a list of variables that must be guarded for this VarInfo to be guaranteed to not be missing.int
getIndexValue(ValueTuple vt)
Return the value of this long variable (as an integer)long[]
getIntArrayValue(ValueTuple vt)
Return the value of an long[] variable.long
getIntValue(ValueTuple vt)
Return the value of this long variable (as a long)int
getModified(ValueTuple vt)
Convenience methods that return information from the ValueTuple.String[]
getStringArrayValue(ValueTuple vt)
Reteurn the value of a String[] array variable.String
getStringValue(ValueTuple vt)
Return the value of a String variable.@Interned Object
getValue(ValueTuple vt)
Get the value of this variable from a particular sample (ValueTuple).@Nullable @Interned Object
getValueOrNull(ValueTuple vt)
Use of this method is discouraged.boolean
has_same_parent(VarInfo other)
Returns whether or not two variables have the same enclosing variable.boolean
has_typeof()
Returns whether or not this variable represents the type of a variable (eg, a.getClass().getName()).boolean
includes_simple_name(String varname)
Returns true if this variable contains a simple variable whose name is varname.boolean
indexCompatible(VarInfo sclvar)
Return true if this sequence's first index type is compatible with the scalar variable.boolean
is_add()
Returns whether or not this variable has an integer offset (eg, a+2)boolean
is_array()
Returns true if this variable is an array.boolean
is_assignable_var()
Returns true if this variable can be assigned to.boolean
is_direct_array()
Returns whether or not this variable is an actual array as opposed to an array that is created over fields/methods of an array.boolean
is_direct_non_slice_array()
Returns whether or not this variable is an actual array as opposed to an array that is created over fields/methods of an array or a slice.boolean
is_field()
Returns wehther or not this variable is a field.boolean
is_prestate_version(VarInfo vi)
Returns true if vi is the prestate version of this.boolean
is_reference()
Return true if this is a pointer or reference to another object.boolean
is_size()
Returns whether this is a size of an array or a prestate thereof.boolean
is_this()
Returns whether or not this variable is the 'this' variable.boolean
is_typeof()
Returns whether or not this variable represents the type of a variable (eg, a.getClass().getName()).boolean
isArray()
Returns true if this is an array or a slice.boolean
isCanonical()
Whether this VarInfo is the leader of its equality set.boolean
isClosure()
boolean
isDerived()
Returns true if this variable is a derived variable.boolean
isDerivedParam()
Returns true if this is a param according to aux info, or this is a front end derivation such that one of its bases is a param.boolean
isDerivedParamAndUninteresting()
Returns true if a given VarInfo is a parameter or derived from one in such a way that changes to it wouldn't be visible to the method's caller.@Nullable VarInfo
isDerivedSequenceMember()
Returns the VarInfo for the sequence from which this was derived, or null if this wasn't derived from a sequence.boolean
isDerivedSequenceMinMaxSum()
@Nullable VarInfo
isDerivedSubSequenceOf()
Return the original sequence variable from which this derived sequence was derived.boolean
isEqualTo(VarInfo other)
Check if two VarInfos are truly (non guarded) equal to each other right now.boolean
isIndex()
Returns true if the type in the original program is integer.boolean
isMissing(ValueTuple vt)
boolean
isMissingFlow(ValueTuple vt)
boolean
isMissingNonsensical(ValueTuple vt)
boolean
isModified(ValueTuple vt)
boolean
isParam()
Returns whether or not this variable is a parameter.boolean
isPointer()
Return true if invariants about this quantity are really properties of a pointer, but derived variables can refer to properties of the thing pointed to.boolean
isPrestate()
Returns true if this is an "orig()" variable.boolean
isPrestateDerived()
Returns true if this variable is derived from prestate variables.boolean
isSlice()
Returns true if this is a slice.boolean
isStaticConstant()
Returns whether or not this variable is a static constant.boolean
isThis()
Returns whether or not this variable is the 'this' variable.boolean
isUnmodified(ValueTuple vt)
boolean
isValidEscExpression()
Returns false if this variable expression is not legal ESC syntax, except for any necessary quantifications (subscripting).String
java_name()
Returns the name in Java format.String
jml_name()
Returns the name of this variable in JML format.String
jml_name(@Nullable String index)
Returns the name of this variable in JML format.static VarInfo
make_function(String function_name, VarInfo... vars)
Create a VarInfo that is a function over one or more other variables.static VarInfo
make_scalar_seq_func(String func_name, @Nullable ProglangType type, VarInfo seq, int shift)
static VarInfo
make_scalar_str_func(String func_name, ProglangType type, VarInfo str)
static VarInfo
make_subscript(VarInfo seq, @Nullable VarInfo index, int index_shift)
Creates a VarInfo that is an index into a sequence.static VarInfo
make_subsequence(VarInfo seq, @Nullable VarInfo begin, int begin_shift, @Nullable VarInfo end, int end_shift)
Creates a VarInfo that is a subsequence that begins at begin and ends at end with the specified shifts.boolean
missingOutOfBounds()
Returns whether or not we have encountered to date any missing values due to array indices being out of bounds.@Interned String
name()
returns the interned name of the variableString
name_using(OutputFormat format)
Returns the name of this variable in the specified format.String
old_var_name()
Returns the old style variable name for this name.static String
old_var_names(String name)
Converts a variable name or expression to the old style of names.static VarInfo
origVarInfo(VarInfo vi)
Create the prestate, or "orig()", version of the variable.@Nullable VarInfoName
otherStateEquivalent(boolean post)
Return some variable in the other state (pre-state if this is post-state, or vice versa) that equals this one, or null if no equal variable exists.@Interned String
prestate_name()
Return the name of this variable in its prestate (orig).@Nullable VarInfoName
preStateEquivalent()
void
relate_var()
Finishes defining the variable by relating it to other variables.String
replace_this(VarInfo arg)
Replaces all instances of 'this' in the variable with the name of arg.String
repr()
Returns a complete string description of the variable.@Nullable VarInfo
sequenceSize()
Returns the variable (if any) that represents the size of this sequence.void
set_is_param()
Set this variable as a parameter.void
set_is_param(boolean set)
Set whether or not this variable is a parameter.void
setup_derived_base(VarInfo base, @Nullable VarInfo... others)
Setup information normally specified in the declaration record for derived variables where one of the variables is the base of the derivation.void
setup_derived_function(String name, VarInfo... bases)
Setup information normally specified in the declaration record for derived variables where the new variable is the result of applying a function to the other variables.void
simplify_expression()
Change the name of this VarInfo by side effect into a more simplified form, which is easier to read on display.String
simplify_name()
Returns the name of this variable in simplify format.String
simplify_name(@Nullable String index)
Returns the name of this variable in simplify format.static String[]
simplify_quantify(VarInfo... vars)
static String[]
simplify_quantify(EnumSet<Quantify.QuantFlags> flags, VarInfo... vars)
Quantifies over the specified array variables in Simplify format.String
simplifyFixedupName()
String
simplifyFixup(String str)
A wrapper around VarInfoName.simplify_name() that also uses VarInfo information to guess whether "obj" should logically be treated as just the hash code of "obj", rather than the whole object.String @Nullable []
simplifyNameAndBounds()
Returns a string array with 3 elements.@Interned String
str_name()
Returns the original name of the variable from the program point declaration.String
toString()
Returns the name of the variable.void
trimToSize()
Trims the collections used by this VarInfo.void
update_after_moving_to_new_ppt()
Updates any references to other variables that should be within this ppt by looking them up within the ppt.void
var_check()
Rough check to ensure that the variable name and derivation match up.
-
-
-
Field Detail
-
dkconfig_declared_type_comparability
public static boolean dkconfig_declared_type_comparability
If true, then variables are only considered comparable if they are declared with the same type. For example, java.util.List is not comparable to java.util.ArrayList and float is not comparable to double. This may miss valid invariants, but significant time can be saved and many variables with different declared types are not comparable (e.g., java.util.Date and java.util.ArrayList).
-
dkconfig_constant_fields_simplify
public static boolean dkconfig_constant_fields_simplify
If true, the treat static constants (such as MapQuick.GeoPoint.FACTOR) as fields within an object rather than as a single name. Not correct, but used to obtain compatibility with VarInfoName.
-
debugMissing
public static final Logger debugMissing
Debug missing vals.
-
ppt
public PptTopLevel ppt
The program point this variable is in. Is null until set byPptTopLevel.init_vars()
andPptTopLevel.addVarInfos(daikon.VarInfo[])
.
-
type
public ProglangType type
Type as declared in the target program. This is seldom used within Daikon as these types vary with program language and the like. It's here more for information than anything else.
-
file_rep_type
public ProglangType file_rep_type
Type as written in the data trace file -- i.e., it is the source variable type mapped into the set of basic types recognized by Daikon. In particular, it includes boolean and hashcode (pointer). This is the type that is normally used when determining if an invariant is applicable to a variable. For example, the less-than invariant is not applicable to booleans or hashcodes, but is applicable to integers (of various sizes) and floats. (In the variable name, "rep" stands for "representation".)
-
rep_type
public ProglangType rep_type
Type as internally stored by Daikon. It contains less information than file_rep_type (for example, boolean and hashcode are both stored as integers). (In the variable name, "rep" stands for "representation".)- See Also:
ProglangType.fileTypeToRepType()
-
comparability
public VarComparability comparability
Comparability info.
-
aux
public VarInfoAux aux
Auxiliary info.
-
varinfo_index
public int varinfo_index
The index in lists of VarInfo objects.
-
value_index
public int value_index
The index in a ValueTuple (more generally, in a list of values). It can differ from varinfo_index due to constants (and possibly other factors). It is -1 iff is_static_constant or not yet set.
-
is_static_constant
public boolean is_static_constant
Invariants:
is_static_constant == (value_index == -1);
is_static_constant == (static_constant_value != null).
-
derived
public @MonotonicNonNull Derivation derived
Whether and how derived. Null if this is not derived.
-
ref_type
public @Nullable VarInfo.RefType ref_type
-
var_kind
public VarInfo.VarKind var_kind
-
var_flags
public EnumSet<VarInfo.VarFlags> var_flags
-
lang_flags
public EnumSet<VarInfo.LangFlags> lang_flags
-
vardef
public FileIO.VarDefinition vardef
-
enclosing_var
public @Nullable VarInfo enclosing_var
For documentation, seeget_enclosing_var()
. Null if no variable encloses this one -- that is, this is not a field of another variable, nor a "method call" like tostring or class.
-
arr_dims
public int arr_dims
Number of array dimensions (0 or 1).
-
function_args
public @MonotonicNonNull List<VarInfo> function_args
The arguments that were used to create this function application. Null if this variable is not a function application.
-
relative_name
public @Nullable String relative_name
The relative name of this variable with respect to its enclosing variable. Field name for fields, method name for instance methods.
-
canBeMissing
public boolean canBeMissing
True if a missing/nonsensical value was ever observed for this variable. This starts out false and is set dynamically, while reading the trace file.
-
equalitySet
public Equality equalitySet
Which equality group this belongs to. Replaces equal_to. Never null after this is put inside equalitySet.
-
postState
public @Nullable VarInfo postState
non-null if this is an orig() variable.Do not test equality! Only use its .name slot.
-
derivedParamCached
public @Nullable VarInfo derivedParamCached
Cached value for getDerivedParam().
-
isDerivedParamCached
public @MonotonicNonNull Boolean isDerivedParamCached
Cached value for isDerivedParam().
-
-
Constructor Detail
-
VarInfo
public VarInfo(FileIO.VarDefinition vardef)
Create VarInfo from VarDefinition.This does not create a fully initialized VarInfo. For example, its ppt and enclosing_var fields are not yet set. Callers need to do some work to complete the construction of the VarInfo.
-
VarInfo
public VarInfo(String name, ProglangType type, ProglangType file_rep_type, VarComparability comparability, boolean is_static_constant, @Nullable @Interned Object static_constant_value, VarInfoAux aux)
Create the specified VarInfo.
-
VarInfo
public VarInfo(String name, ProglangType type, ProglangType file_rep_type, VarComparability comparability, VarInfoAux aux)
Create the specified non-static VarInfo.
-
-
Method Detail
-
name
@Pure public @Interned String name(@GuardSatisfied VarInfo this)
returns the interned name of the variable
-
str_name
public @Interned String str_name()
Returns the original name of the variable from the program point declaration.
-
missingOutOfBounds
public boolean missingOutOfBounds()
Returns whether or not we have encountered to date any missing values due to array indices being out of bounds. This can happen with both subscripts and subsequences. Note that this becomes true as we are running, it cannot be set in advance without a first pass.This is used as we are processing data to destroy any invariants that use this variable.
- See Also:
Derivation.missingOutOfBounds()
-
checkRep
public void checkRep()
Throws an exception if this object is malformed. Requires that the VarInfo has been installed into a program point (theppt
field is set).- Throws:
RuntimeException
- if representation invariant on this is broken
-
checkRepNoPpt
public void checkRepNoPpt()
Throws an exception if this object is malformed.Does not require the
ppt
field to be set; can be called on VarInfos that have not been installed into a program point.- Throws:
RuntimeException
- if representation invariant on this is broken
-
relate_var
public void relate_var()
Finishes defining the variable by relating it to other variables. This cannot be done when creating the variable because the other variables it is related to, may not yet exist. Variables are related to their enclosing variables (for fields, arrays, and functions) and to their parent variables in the PptHierarchy. RuntimeExceptions are thrown if any related variables do not exist.
-
setup_derived_function
public void setup_derived_function(String name, VarInfo... bases)
Setup information normally specified in the declaration record for derived variables where the new variable is the result of applying a function to the other variables. Much of the information is inferred from (arbitrarily) the first argument to the function.The parent_ppt field is set if each VarInfo in the derivation has the same parent. The parent_variable field is set if there is a parent_ppt and one or more of the bases has a non-default parent variable. The parent variable name is formed as function_name(arg1,arg2,...) where arg1, arg2, etc are the parent variable names of each of the arguments.
-
setup_derived_base
public void setup_derived_base(VarInfo base, @Nullable VarInfo... others)
Setup information normally specified in the declaration record for derived variables where one of the variables is the base of the derivation. In general this information is inferred from the base variable of the derived variables. Note that parent_ppt is set if each VarInfo in the derivation has the same parent, but parent_variable is not set. This has to be set based on the particular derivation.
-
origVarInfo
public static VarInfo origVarInfo(VarInfo vi)
Create the prestate, or "orig()", version of the variable. Note that the returned value is not completely initialized. The caller is still responsible for setting some fields of it, such as enclosing_var.
-
arrayclone_simple
public static VarInfo[] arrayclone_simple(VarInfo[] a_old)
Given an array of VarInfo objects, return an array of clones, where references to the originals have been modified into references to the new ones (so that the new set is self-consistent). The originals should not be modified by this operation.
-
trimToSize
public void trimToSize()
Trims the collections used by this VarInfo.
-
toString
@SideEffectFree public String toString(@GuardSatisfied VarInfo this)
Returns the name of the variable.
-
repr
public String repr(@UnknownSignedness VarInfo this)
Returns a complete string description of the variable.- Returns:
- a complete string description of the variable
-
isStaticConstant
@EnsuresNonNullIf(result=true, expression={"constantValue()","static_constant_value"}) @Pure public boolean isStaticConstant()
Returns whether or not this variable is a static constant.
-
constantValue
public Object constantValue()
Returns the static constant value of this variable. The variable must be a static constant. The result is non-null.
-
isPrestate
@EnsuresNonNullIf(result=true, expression="postState") @Pure public boolean isPrestate()
Returns true if this is an "orig()" variable.
-
isPrestateDerived
@Pure public boolean isPrestateDerived()
Returns true if this variable is derived from prestate variables.
-
isDerived
@EnsuresNonNullIf(result=true, expression="this.derived") @Pure public boolean isDerived()
Returns true if this variable is a derived variable.
-
derivedDepth
public int derivedDepth()
returns the depth of derivation
-
derivees
public List<Derivation> derivees(@UnknownSignedness VarInfo this)
Return all derived variables that build off this one.- Returns:
- all derived variables that build off this one
-
get_all_constituent_vars
public List<VarInfo> get_all_constituent_vars()
Returns a list of all of the basic (non-derived) variables that are used to make up this variable. If this variable is not derived, it is just this variable. Otherwise it is all of the the bases of this derivation.
-
get_all_simple_names
public List<String> get_all_simple_names()
Returns a list of all of the simple names that make up this variable. this includes each field and function name in the variable. If this variable is derived it includes the simple names from each of its bases. For example, 'this.item.a' would return a list with 'this', 'item', and 'a' and 'this.theArray[i]' would return 'this', 'theArray' and 'i'.
-
isClosure
@Pure public boolean isClosure()
-
isDerivedParam
@EnsuresNonNullIf(result=true, expression="getDerivedParam()") @Pure public boolean isDerivedParam()
Returns true if this is a param according to aux info, or this is a front end derivation such that one of its bases is a param. To figure this out, what we do is get all the param variables at this's program point. Then we search in this's name to see if the name contains any of the variables. We have to do this because we only have name info, and we assume that x and x.a are related from the names alone.Effects: Sets isDerivedParamCached and derivedParamCached to values the first time this method is called. Subsequent calls use these cached values.
-
getDerivedParam
@Pure public @Nullable VarInfo getDerivedParam()
Return a VarInfo that has two properties: this is a derivation of it, and it is a parameter variable. If this is a parameter, then this is returned. For example, "this" is always a parameter. The return value of getDerivedParam for "this.a" (which is not a parameter) is "this".Effects: Sets isDerivedParamCached and derivedParamCached to values the first time this method is called. Subsequent calls use these cached values.
- Returns:
- null if the above condition doesn't hold
-
isDerivedParamAndUninteresting
@Pure public boolean isDerivedParamAndUninteresting()
Returns true if a given VarInfo is a parameter or derived from one in such a way that changes to it wouldn't be visible to the method's caller. There are 3 such cases:- The variable is a pass-by-value parameter "p".
- The variable is of the form "p.prop" where "prop" is an immutable property of an object, like its type, or (for a Java array) its size.
- The variable is of the form "p.prop", and "p" has been modified to point to a different object. We assume "p" has been modified if we don't have an invariant "orig(p) == p".
-
getModified
@Pure public int getModified(ValueTuple vt)
Convenience methods that return information from the ValueTuple.
-
isUnmodified
@Pure public boolean isUnmodified(ValueTuple vt)
-
isModified
@Pure public boolean isModified(ValueTuple vt)
-
isMissingNonsensical
@Pure public boolean isMissingNonsensical(ValueTuple vt)
-
isMissingFlow
@Pure public boolean isMissingFlow(ValueTuple vt)
-
isMissing
@Pure public boolean isMissing(ValueTuple vt)
-
getValue
public @Interned Object getValue(ValueTuple vt)
Get the value of this variable from a particular sample (ValueTuple).- Parameters:
vt
- the ValueTuple from which to extract the value
-
getValueOrNull
public @Nullable @Interned Object getValueOrNull(ValueTuple vt)
Use of this method is discouraged.
-
getIndexValue
public int getIndexValue(ValueTuple vt)
Return the value of this long variable (as an integer)
-
getIntValue
public long getIntValue(ValueTuple vt)
Return the value of this long variable (as a long)
-
getIntArrayValue
public long[] getIntArrayValue(ValueTuple vt)
Return the value of an long[] variable.
-
getDoubleValue
public double getDoubleValue(ValueTuple vt)
Return the value of a double variable.
-
getDoubleArrayValue
public double[] getDoubleArrayValue(ValueTuple vt)
Return the value of a double[] variable.
-
getStringValue
public String getStringValue(ValueTuple vt)
Return the value of a String variable.
-
getStringArrayValue
public String[] getStringArrayValue(ValueTuple vt)
Reteurn the value of a String[] array variable.
-
isCanonical
@Pure public boolean isCanonical(@UnknownSignedness VarInfo this)
Whether this VarInfo is the leader of its equality set.- Returns:
- true if this VarInfo is the leader of its equality set
-
canonicalRep
@Pure public VarInfo canonicalRep()
Canonical representative that's equal to this variable.
-
is_reference
@Pure public boolean is_reference()
Return true if this is a pointer or reference to another object.
-
isDerivedSequenceMember
public @Nullable VarInfo isDerivedSequenceMember()
Returns the VarInfo for the sequence from which this was derived, or null if this wasn't derived from a sequence. Only works for scalars.
-
isDerivedSequenceMinMaxSum
@Pure public boolean isDerivedSequenceMinMaxSum()
-
isDerivedSubSequenceOf
public @Nullable VarInfo isDerivedSubSequenceOf()
Return the original sequence variable from which this derived sequence was derived. Only works for sequences.
-
sequenceSize
public @Nullable VarInfo sequenceSize()
Returns the variable (if any) that represents the size of this sequence.
-
isIndex
@Pure public boolean isIndex()
Returns true if the type in the original program is integer. Should perhaps check Daikon.check_program_types and behave differently depending on that.
-
is_array
@Pure public boolean is_array()
Returns true if this variable is an array.- Returns:
- true if this variable is an array
-
isValidEscExpression
@Pure public boolean isValidEscExpression()
Returns false if this variable expression is not legal ESC syntax, except for any necessary quantifications (subscripting). We err on the side of returning true, for now.- Returns:
- false if this variable expression is not legal ESC syntax, except for any necessary quantifications (subscripting)
-
isPointer
@Pure public boolean isPointer()
Return true if invariants about this quantity are really properties of a pointer, but derived variables can refer to properties of the thing pointed to. This distinction is important when making logical statements about the object, because in the presence of side effects, the pointed-to object can change even when the pointer doesn't. For instance, we might have "obj == orig(obj)", but "obj.color != orig(obj.color)". In such a case, isPointer() would be true of obj, and for some forms of output we'd need to translate "obj == orig(obj)" into something like "location(obj) == location(orig(obj))".
-
simplifyFixup
public String simplifyFixup(String str)
A wrapper around VarInfoName.simplify_name() that also uses VarInfo information to guess whether "obj" should logically be treated as just the hash code of "obj", rather than the whole object.
-
simplifyFixedupName
public String simplifyFixedupName()
-
compare_vars
public static boolean compare_vars(VarInfo vari, int vari_shift, VarInfo varj, int varj_shift, boolean test_lessequal)
Given two variables I and J, indicate whether it is necessarily the case that i≤j or i≥j. The variables also each have a shift, so the test can really be something like (i+1)≤(j-1). The test is one of:- i + i_shift ≤ j + j_shift (if test_lessequal)
- i + i_shift ≥ j + j_shift (if !test_lessequal)
-
preStateEquivalent
public @Nullable VarInfoName preStateEquivalent()
-
otherStateEquivalent
public @Nullable VarInfoName otherStateEquivalent(boolean post)
Return some variable in the other state (pre-state if this is post-state, or vice versa) that equals this one, or null if no equal variable exists.
-
isEqualTo
@Pure public boolean isEqualTo(VarInfo other)
Check if two VarInfos are truly (non guarded) equal to each other right now.
-
assertionsEnabled
public static boolean assertionsEnabled()
-
simplify_expression
public void simplify_expression()
Change the name of this VarInfo by side effect into a more simplified form, which is easier to read on display. Don't call this during processing, as I think the system assumes that names don't change over time (?).
-
compatible
public boolean compatible(VarInfo var2)
Two variables are "compatible" if their declared types are castable and their comparabilities are comparable. This is a reflexive relationship, because it calls ProglangType.comparableOrSuperclassEitherWay. However, it is not transitive because it might not hold for two children of a superclass, even though it would for each child and the superclass.
-
eltsCompatible
public boolean eltsCompatible(VarInfo sclvar)
Return true if this sequence variable's element type is compatible with the scalar variable.
-
comparableByType
public boolean comparableByType(VarInfo var2)
Without using comparability info, check that this is comparable to var2. This is a reflexive relationship, because it calls ProglangType.comparableOrSuperclassEitherWay. However, it is not transitive because it might not hold for two children of a superclass, even though it would for each child and the superclass. Does not check comparabilities.
-
comparableNWay
public boolean comparableNWay(VarInfo var2)
Without using comparability info, check that this is comparable to var2. This is a reflexive and transitive relationship. Does not check comparabilities.- Parameters:
var2
- the variable to test comparability with- Returns:
- true if this is comparable to var2
-
indexCompatible
public boolean indexCompatible(VarInfo sclvar)
Return true if this sequence's first index type is compatible with the scalar variable.
-
createGuardingPredicate
public @Nullable Invariant createGuardingPredicate(boolean install)
Create a guarding predicate for this VarInfo, that is, an invariant that ensures that this object is available for access to variables that reference it, such as fields. (The invariant is placed in the appropriate slice.) Returns null if no guarding is needed.
-
getGuardingList
public List<VarInfo> getGuardingList()
Finds a list of variables that must be guarded for this VarInfo to be guaranteed to not be missing. This list never includes "this", as it can never be null. The variables are returned in the order in which their guarding prefixes are supposed to print.For example, if this VarInfo is "a.b.c", then the guarding list consists of the variables "a" and "a.b". If "a" is null or "a.b" is null, then "a.b.c" is missing (does not exist).
-
get_all_enclosing_vars
public List<VarInfo> get_all_enclosing_vars()
Returns a list of all of the variables that enclose this one. If this is derived, this includes all of the enclosing variables of all of the bases.
-
find_object_ppt
public @Nullable PptTopLevel find_object_ppt(PptMap all_ppts)
Looks for an OBJECT ppt that corresponds to the type of this variable. Returns null if such a point is not found.- Parameters:
all_ppts
- map of all program points
-
get_value_set
public ValueSet get_value_set()
Return the set of values that have been seen so far for this variable.
-
get_value_info
public String get_value_info()
-
get_equalitySet_size
public int get_equalitySet_size()
Returns the number of elements in the variable's equality set. Returns 1 if the equality optimization is turned off.
-
get_equalitySet_vars
public Set<VarInfo> get_equalitySet_vars()
Returns the vars_info in the variable's equality set. Returns a set with just itself if the equality optimization is turned off.
-
get_equalitySet_leader
public VarInfo get_equalitySet_leader()
Returns the leader in the variable's equality set. Returns itself if the equality optimization is turned off.
-
isParam
@Pure public boolean isParam()
Returns whether or not this variable is a parameter.
-
set_is_param
public void set_is_param()
Set this variable as a parameter.
-
set_is_param
public void set_is_param(boolean set)
Set whether or not this variable is a parameter.
-
apply_subscript
public String apply_subscript(String subscript)
Adds a subscript (or sequence) to an array variable. This should really just just substitute for '..', but the dots are currently removed for back compatability.
-
apply_subscript
public static String apply_subscript(String sequence, String subscript)
Adds a subscript (or subsequence) to an array name. This should really just substitute for '..', but the dots are currently removed for back compatibility.
-
get_array_var
public VarInfo get_array_var()
For array variables, returns the variable that is a simple array. If this variable is a slice, it returns the array variable that is being sliced. If this variable is a simple array itself, returns this.
-
get_base_array
@Pure public VarInfo get_base_array()
Returns the VarInfo that represents the base array of this array. For example, if the array is a[].b.c, returns a[].
-
get_base_array_hashcode
@Pure public @Nullable VarInfo get_base_array_hashcode()
Returns the VarInfo that represents the hashcode of the base array of this array. For example, if the array is a[].b.c, returns a. Returns null if there is no such variable.
-
get_lower_bound
public Quantify.Term get_lower_bound()
Returns the lower bound of the array or slice.
-
get_upper_bound
public Quantify.Term get_upper_bound()
Returns the upper bound of the array or slice.
-
get_length
public Quantify.Term get_length()
Returns the length of this array. The array can be an array or a list. It cannot be a slice.
-
update_after_moving_to_new_ppt
public void update_after_moving_to_new_ppt()
Updates any references to other variables that should be within this ppt by looking them up within the ppt. Necessary if a variable is moved to a different program point or if cloned variable is placed in a new program point (such as is done when combined exits are created).
-
get_VarInfoName
public VarInfoName get_VarInfoName()
Temporary to let things compile now that name is private. Eventually this should be removed.
-
fix_csharp_type_name
public static String fix_csharp_type_name(String type)
Transforms a Daikon type representation into a valid C# type.
-
csharp_collection_string
public String csharp_collection_string()
If the variable is an array, returns a valid C# 'Select' statement representing the array. For example, this.Array[].field would become this.Array.Select(x ⇒ x.field)If the variable is not an array, csharp_name() is returned.
-
csharp_array_split
public String[] csharp_array_split()
Splits an array variable into the array and field portions. For example, if the variable this.Array[].field thenresult[0] = this.Array[] result[1] = field
If the variable is not an array thenresult[0] = csharp_name() result[1] = ""
(there is no splitting).
-
name_using
public String name_using(OutputFormat format)
Returns the name of this variable in the specified format.
-
csharp_name
@SideEffectFree public String csharp_name()
Returns the name of this variable as a valid C# Code Contract.
-
csharp_name
@SideEffectFree public String csharp_name(@Nullable String index)
Returns the name of this variable as a valid C# Code Contract.- Parameters:
index
- an an array index. Must be null for a non-array variable.- Returns:
- the name of this variable as a valid C# Code Contract
-
esc_name
@SideEffectFree public String esc_name(@Nullable String index)
Returns the name of this variable in ESC format. If an index is specified, it is used as an array index. It is an error to specify an index on a non-array variable.
-
jml_name
public String jml_name(@Nullable String index)
Returns the name of this variable in JML format.- Parameters:
index
- an array index. Must be null for a non-array variable.- Returns:
- the name of this variable in JML format
-
simplify_name
@SideEffectFree public String simplify_name()
Returns the name of this variable in simplify format.
-
simplify_name
public String simplify_name(@Nullable String index)
Returns the name of this variable in simplify format. If an index is specified, it is used as an array index. It is an error to specify an index on a non-array variable.
-
prestate_name
@SideEffectFree public @Interned String prestate_name()
Return the name of this variable in its prestate (orig).
-
get_simplify_size_name
public @Nullable String get_simplify_size_name()
Returns the name of the size variable that correponds to this array variable in simplify format. Returns null if this variable is not an array or the size name can't be constructed for other reasons. Note that isArray seems to distinguish between actual arrays and other sequences (such as java.util.list). Simplify uses (it seems) the same length approach for both, so we don't check isArray().
-
includes_simple_name
public boolean includes_simple_name(String varname)
Returns true if this variable contains a simple variable whose name is varname.
-
esc_quantify
public static String[] esc_quantify(VarInfo... vars)
Quantifies over the specified array variables in ESC format. Returns an array with 2 more elements than the argument. Element 0 is the quantification, Element 1 is the indexed form of variable 1, Element 2 is the indexed form of variable 3, and Element 4 is syntax such as close parentheses.
-
esc_quantify
public static String[] esc_quantify(boolean elementwise, VarInfo... vars)
Quantifies over the specified array variables in ESC format. Returns an array with 2 more elements than the argument. Element 0 is the quantification, Element 1 is the indexed form of variable 1, Element 2 is the indexed form of variable 3, and Element 4 is syntax such as close parentheses.
-
simplifyNameAndBounds
public String @Nullable [] simplifyNameAndBounds()
Returns a string array with 3 elements. The first element is the sequence, the second element is the lower bound, and the third element is the upper bound. Returns null if this is not a direct array or slice.
-
get_simplify_slice_bounds
public String @Nullable [] get_simplify_slice_bounds()
Returns the upper and lower bounds of the slice in simplify format. The implementation is somewhat different that simplifyNameAndBounds (I don't know why).
-
get_simplify_selectNth
public String get_simplify_selectNth(String simplify_index_name, boolean free, int index_off)
Return a string in simplify format that will seclect the (index_base + index_off)-th element of the sequence specified by this variable.- Parameters:
simplify_index_name
- name of the index. If free is false, this must be a number or null (null implies an index of 0).free
- true of simplify_index_name is variable nameindex_off
- offset from the index
-
get_simplify_selectNth_lower
public String get_simplify_selectNth_lower(int index_off)
Return a string in simplify format that will seclect the index_off element in a sequence that has a lower bound.- Parameters:
index_off
- offset from the index
-
get_simplify_free_index
public static String get_simplify_free_index(VarInfo... vars)
Get a fresh variable name that doesn't appear in the given variable in simplify format.
-
get_simplify_free_indices
public static String[] get_simplify_free_indices(VarInfo... vars)
Get a 2 fresh variable names that doesn't appear in the given variable in simplify format.
-
simplify_quantify
public static String[] simplify_quantify(EnumSet<Quantify.QuantFlags> flags, VarInfo... vars)
Quantifies over the specified array variables in Simplify format. Returns a string array that contains the quantification, indexed form of each variable, optionally the index itself, and the closer.If elementwise is true, include the additional contraint that the indices (there must be exactly two in this case) refer to corresponding positions. If adjacent is true, include the additional constraint that the second index be one more than the first. If distinct is true, include the constraint that the two indices are different. If includeIndex is true, return additional strings, after the roots but before the closer, with the names of the index variables.
-
simplify_quantify
public static String[] simplify_quantify(VarInfo... vars)
- See Also:
simplify_quantify(EnumSet, VarInfo[])
-
complexity
public int complexity()
Returns a rough indication of the complexity of the variable. Higher numbers indicate more complexity.
-
is_assignable_var
@Pure public boolean is_assignable_var()
Returns true if this variable can be assigned to. Currently this is presumed true of all variable except the special variable for the type of a variable and the size of a sequence. It should include pure functions as well.
-
is_typeof
@Pure public boolean is_typeof()
Returns whether or not this variable represents the type of a variable (eg, a.getClass().getName()). Note that this will miss prestate variables such as 'orig(a.getClass().getName())'.
-
has_typeof
public boolean has_typeof()
Returns whether or not this variable represents the type of a variable (eg, a.getClass().getName()). This version finds prestate variables such as 'org(a.getClass().getName())'.
-
is_this
@Pure public boolean is_this()
Returns whether or not this variable is the 'this' variable.
-
isThis
@Pure public boolean isThis()
Returns whether or not this variable is the 'this' variable. True for both normal and prestate versions of the variable.
-
is_size
@Pure public boolean is_size()
Returns whether this is a size of an array or a prestate thereof.
-
is_field
@Pure public boolean is_field()
Returns wehther or not this variable is a field.
-
is_add
@Pure public boolean is_add()
Returns whether or not this variable has an integer offset (eg, a+2)
-
get_add_amount
public int get_add_amount()
Returns the integer offset if this variable is an addition such as a+2. Throws an exception of this variable is not an addition.- See Also:
is_add()
-
is_direct_array
@Pure public boolean is_direct_array()
Returns whether or not this variable is an actual array as opposed to an array that is created over fields/methods of an array. For example, 'a[]' is a direct array, but 'a[].b' is not.
-
is_direct_non_slice_array
@Pure public boolean is_direct_non_slice_array()
Returns whether or not this variable is an actual array as opposed to an array that is created over fields/methods of an array or a slice. For example, 'a[]' is a direct array, but 'a[].b' and 'a[i..]' are not.
-
has_same_parent
public boolean has_same_parent(VarInfo other)
Returns whether or not two variables have the same enclosing variable. If either variable is not a field, returns false.
-
get_enclosing_var
public @Nullable VarInfo get_enclosing_var()
Returns the variable that encloses this one. For example if this variable is 'x.a.b', the enclosing variable is 'x.a'.
-
replace_this
public String replace_this(VarInfo arg)
Replaces all instances of 'this' in the variable with the name of arg. Used to match up enter/exit variables with object variables.
-
make_subsequence
public static VarInfo make_subsequence(VarInfo seq, @Nullable VarInfo begin, int begin_shift, @Nullable VarInfo end, int end_shift)
Creates a VarInfo that is a subsequence that begins at begin and ends at end with the specified shifts. The begin or the end can be null, but a non-zero shift is only allowed with non-null variables.
-
make_subscript
public static VarInfo make_subscript(VarInfo seq, @Nullable VarInfo index, int index_shift)
Creates a VarInfo that is an index into a sequence. The type, file_rep_type, etc are taken from the element type of the sequence.
-
make_function
public static VarInfo make_function(String function_name, VarInfo... vars)
Create a VarInfo that is a function over one or more other variables. The type, rep_type, etc. of the new function are taken from the first variable.
-
make_scalar_seq_func
public static VarInfo make_scalar_seq_func(String func_name, @Nullable ProglangType type, VarInfo seq, int shift)
-
make_scalar_str_func
public static VarInfo make_scalar_str_func(String func_name, ProglangType type, VarInfo str)
-
is_prestate_version
@Pure public boolean is_prestate_version(VarInfo vi)
Returns true if vi is the prestate version of this. If this is a derived variable, vi must be the same derivation using prestate versions of each base variable.
-
isArray
@Pure public boolean isArray()
Returns true if this is an array or a slice.
-
isSlice
@Pure public boolean isSlice()
Returns true if this is a slice.
-
old_var_names
public static String old_var_names(String name)
Converts a variable name or expression to the old style of names.
-
old_var_name
public String old_var_name()
Returns the old style variable name for this name.
-
var_check
public void var_check()
Rough check to ensure that the variable name and derivation match up.
-
-