Class BaseValidationLogic
- java.lang.Object
-
- it.unive.lisa.program.language.validation.BaseValidationLogic
-
- All Implemented Interfaces:
ProgramValidationLogic
public class BaseValidationLogic extends java.lang.Object implements ProgramValidationLogic
A simple implementation ofProgramValidationLogic
, providing the minimum reasoning for considering aProgram
valid for LiSA. Each validation method can be overridden by subclasses to define language-specific validation logic.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ABSTRACT_METHODS
Error message format forAbstractCodeMember
s in non-AbstractClassUnit
s.static java.lang.String
ABSTRACT_NON_INSTANCE
Error message format forAbstractCodeMember
that is not instance.static java.lang.String
ABSTRACT_SEALED_UNIT
Error message format for sealedAbstractClassUnit
s.static java.lang.String
CANNOT_OVERRIDE
Error message format for the overriding of a non-overridableCodeMember
.static java.lang.String
CONST_INSTANCE_GLOBAL
Error message format for aConstantGlobal
being an instance global.static java.lang.String
DUPLICATE_MEMBER
Error message format for duplicatedCodeMember
s in the sameUnit
.static java.lang.String
EXIT_WITH_FOLLOWERS
Error message format for terminatingStatement
s with followers.static java.lang.String
GLOBAL_INSTANCE_MISMATCH
Error message format for aGlobal
not matching its instance flag.static java.lang.String
INHERIT_FROM_SEALED
Error message format for inheritance from a sealedCompilationUnit
.static java.lang.String
INTERFACE_WITH_GLOBALS
Error message format forGlobal
s insideInterfaceUnit
s.static java.lang.String
INVALID_CFSTRUCTURE
Error message format for invalidControlFlowStructure
s.static java.lang.String
INVALID_NODE_LIST
Error message format for invalidNodeList
s.static java.lang.String
MEMBER_MISMATCH
Error message format for aCodeMember
not matching its own signature.static java.lang.String
MISSING_OVERRIDE
Error message format for missing override of anAbstractCodeMember
.static java.lang.String
MULTIPLE_OVERRIDES
Error message format for multiple overrides of the sameCodeMember
inside the sameCompilationUnit
.static java.lang.String
NO_FOLLOWERS
Error message format forStatement
s with no followers.java.util.Set<java.lang.String>
processedUnits
The set ofCompilationUnit
s, represented by their names, that have been already processed byvalidateAndFinalize(CompilationUnit)
.static java.lang.String
UNKNOWN_ENTRYPOINTS
Error message format for entrypoints not defined inside theProgram
.
-
Constructor Summary
Constructors Constructor Description BaseValidationLogic()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
validate(CodeMember member, boolean instance)
Validates the givenCodeMember
, checking that no other code member exists in its containingUnit
with the same signature, according toCodeMemberDescriptor.matchesSignature(CodeMemberDescriptor)
.void
validate(Global global, boolean isInstance)
Validates the givenGlobal
.void
validateAndFinalize(AbstractClassUnit unit)
Validates the givenAbstractClassUnit
.void
validateAndFinalize(ClassUnit unit)
Validates the givenClassUnit
.void
validateAndFinalize(CodeUnit unit)
Validates the givenCodeUnit
.void
validateAndFinalize(CompilationUnit unit)
Validates the givenCompilationUnit
.void
validateAndFinalize(InterfaceUnit unit)
Validates the givenInterfaceUnit
.void
validateAndFinalize(Program program)
Validates the givenProgram
, ensuring its consistency.void
validateAndFinalize(Unit unit)
Validates the given unit, ensuring its consistency.
-
-
-
Field Detail
-
DUPLICATE_MEMBER
public static final java.lang.String DUPLICATE_MEMBER
Error message format for duplicatedCodeMember
s in the sameUnit
.- See Also:
- Constant Field Values
-
INVALID_NODE_LIST
public static final java.lang.String INVALID_NODE_LIST
Error message format for invalidNodeList
s.- See Also:
- Constant Field Values
-
INVALID_CFSTRUCTURE
public static final java.lang.String INVALID_CFSTRUCTURE
Error message format for invalidControlFlowStructure
s.- See Also:
- Constant Field Values
-
EXIT_WITH_FOLLOWERS
public static final java.lang.String EXIT_WITH_FOLLOWERS
Error message format for terminatingStatement
s with followers.- See Also:
- Constant Field Values
-
NO_FOLLOWERS
public static final java.lang.String NO_FOLLOWERS
Error message format forStatement
s with no followers.- See Also:
- Constant Field Values
-
UNKNOWN_ENTRYPOINTS
public static final java.lang.String UNKNOWN_ENTRYPOINTS
Error message format for entrypoints not defined inside theProgram
.- See Also:
- Constant Field Values
-
INTERFACE_WITH_GLOBALS
public static final java.lang.String INTERFACE_WITH_GLOBALS
Error message format forGlobal
s insideInterfaceUnit
s.- See Also:
- Constant Field Values
-
ABSTRACT_SEALED_UNIT
public static final java.lang.String ABSTRACT_SEALED_UNIT
Error message format for sealedAbstractClassUnit
s.- See Also:
- Constant Field Values
-
ABSTRACT_METHODS
public static final java.lang.String ABSTRACT_METHODS
Error message format forAbstractCodeMember
s in non-AbstractClassUnit
s.- See Also:
- Constant Field Values
-
INHERIT_FROM_SEALED
public static final java.lang.String INHERIT_FROM_SEALED
Error message format for inheritance from a sealedCompilationUnit
.- See Also:
- Constant Field Values
-
MISSING_OVERRIDE
public static final java.lang.String MISSING_OVERRIDE
Error message format for missing override of anAbstractCodeMember
.- See Also:
- Constant Field Values
-
CANNOT_OVERRIDE
public static final java.lang.String CANNOT_OVERRIDE
Error message format for the overriding of a non-overridableCodeMember
.- See Also:
- Constant Field Values
-
MULTIPLE_OVERRIDES
public static final java.lang.String MULTIPLE_OVERRIDES
Error message format for multiple overrides of the sameCodeMember
inside the sameCompilationUnit
.- See Also:
- Constant Field Values
-
ABSTRACT_NON_INSTANCE
public static final java.lang.String ABSTRACT_NON_INSTANCE
Error message format forAbstractCodeMember
that is not instance.- See Also:
- Constant Field Values
-
MEMBER_MISMATCH
public static final java.lang.String MEMBER_MISMATCH
Error message format for aCodeMember
not matching its own signature.- See Also:
- Constant Field Values
-
GLOBAL_INSTANCE_MISMATCH
public static final java.lang.String GLOBAL_INSTANCE_MISMATCH
Error message format for aGlobal
not matching its instance flag.- See Also:
- Constant Field Values
-
CONST_INSTANCE_GLOBAL
public static final java.lang.String CONST_INSTANCE_GLOBAL
Error message format for aConstantGlobal
being an instance global.- See Also:
- Constant Field Values
-
processedUnits
public final java.util.Set<java.lang.String> processedUnits
The set ofCompilationUnit
s, represented by their names, that have been already processed byvalidateAndFinalize(CompilationUnit)
. This is used to avoid duplicate validation of the same unit in multiple inheritance chains.
-
-
Method Detail
-
validateAndFinalize
public void validateAndFinalize(Program program) throws ProgramValidationException
Validates the givenProgram
, ensuring its consistency. This identifies erroneous situations (e.g., code members with the same signature) that can crash the analysis. During validation, the program is also finalized by populating additional data structures (e.g., computing the instances of allCompilationUnit
s defined in the program).
Validating a program simply causes the validation of all theUnit
s andCodeMember
s defined inside it, and ensures that all entrypoints (Program.getEntryPoints()
) are defined.- Specified by:
validateAndFinalize
in interfaceProgramValidationLogic
- Parameters:
program
- the program to validate- Throws:
ProgramValidationException
- if the program has an invalid structure
-
validateAndFinalize
public void validateAndFinalize(Unit unit) throws ProgramValidationException
Validates the given unit, ensuring its consistency. This ensures that all of itsCodeMember
s are valid throughvalidate(CodeMember, boolean)
. Further validation logic is deferred to this method's overloads accepting more specific types of units (e.g.,validateAndFinalize(ClassUnit)
).- Parameters:
unit
- the unit to validate- Throws:
ProgramValidationException
- if the unit has an invalid structure
-
validate
public void validate(Global global, boolean isInstance) throws ProgramValidationException
Validates the givenGlobal
. This method checks thatConstantGlobal
s are not instance ones, and thenGlobal.isInstance()
agrees withisInstance
.- Parameters:
global
- the global to validateisInstance
- whether or not the given global is part of the instance variables of its container- Throws:
ProgramValidationException
- if the global has an invalid structure
-
validateAndFinalize
public void validateAndFinalize(CodeUnit unit) throws ProgramValidationException
Validates the givenCodeUnit
. This method checks that no instanceGlobal
s are defined in the unit, and then delegates validation tovalidateAndFinalize(CompilationUnit)
.- Parameters:
unit
- the unit to validate- Throws:
ProgramValidationException
- if the unit has an invalid structure
-
validateAndFinalize
public void validateAndFinalize(ClassUnit unit) throws ProgramValidationException
Validates the givenClassUnit
. This method checks that noAbstractCodeMember
is defined in the unit, and then delegates validation tovalidateAndFinalize(CompilationUnit)
.- Parameters:
unit
- the unit to validate- Throws:
ProgramValidationException
- if the unit has an invalid structure
-
validateAndFinalize
public void validateAndFinalize(AbstractClassUnit unit) throws ProgramValidationException
Validates the givenAbstractClassUnit
. This method checks the unit is not sealed (CompilationUnit.isSealed()
), and then delegates validation tovalidateAndFinalize(CompilationUnit)
.- Parameters:
unit
- the unit to validate- Throws:
ProgramValidationException
- if the unit has an invalid structure
-
validateAndFinalize
public void validateAndFinalize(InterfaceUnit unit) throws ProgramValidationException
Validates the givenInterfaceUnit
. This method checks that no instanceGlobal
s are defined in the unit, and then delegates validation tovalidateAndFinalize(CompilationUnit)
.- Parameters:
unit
- the unit to validate- Throws:
ProgramValidationException
- if the unit has an invalid structure
-
validateAndFinalize
public void validateAndFinalize(CompilationUnit unit) throws ProgramValidationException
Validates the givenCompilationUnit
. This causes the validation of all its super units transitively and the population of the set of instances (CompilationUnit.getInstances()
) of each element in its hierarchy. Moreover, all instanceCodeMember
s are validated throughvalidate(CodeMember, boolean)
. These are also linked to other ones in the hierarchy, populating the collectionsCodeMemberDescriptor.overriddenBy()
andCodeMemberDescriptor.overrides()
and raising errors ifAbstractCodeMember
s do not have an implementation in instantiable (Unit.canBeInstantiated()
) units. Lastly, annotations are propagated along the inheritance hierarchy.- Parameters:
unit
- the unit to validate- Throws:
ProgramValidationException
- if the unit has an invalid structure
-
validate
public void validate(CodeMember member, boolean instance) throws ProgramValidationException
Validates the givenCodeMember
, checking that no other code member exists in its containingUnit
with the same signature, according toCodeMemberDescriptor.matchesSignature(CodeMemberDescriptor)
. This avoids ambiguous call resolution. Moreover, this ensures that allCFG
s are valid, according toCFG.validate()
.- Parameters:
member
- the code member to validateinstance
- iftrue
, duplicates will be searched in instance members instead- Throws:
ProgramValidationException
- if the member has an invalid structure
-
-