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 aProgramvalid 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.StringABSTRACT_METHODSError message format forAbstractCodeMembers in non-AbstractClassUnits.static java.lang.StringABSTRACT_NON_INSTANCEError message format forAbstractCodeMemberthat is not instance.static java.lang.StringABSTRACT_SEALED_UNITError message format for sealedAbstractClassUnits.static java.lang.StringCANNOT_OVERRIDEError message format for the overriding of a non-overridableCodeMember.static java.lang.StringDUPLICATE_MEMBERError message format for duplicatedCodeMembers in the sameUnit.static java.lang.StringEXIT_WITH_FOLLOWERSError message format for terminatingStatements with followers.static java.lang.StringINHERIT_FROM_SEALEDError message format for inheritance from a sealedCompilationUnit.static java.lang.StringINTERFACE_WITH_GLOBALSError message format forGlobals insideInterfaceUnits.static java.lang.StringINVALID_CFSTRUCTUREError message format for invalidControlFlowStructures.static java.lang.StringINVALID_NODE_LISTError message format for invalidNodeLists.static java.lang.StringMEMBER_MISMATCHError message format for aCodeMembernot matching its own signature.static java.lang.StringMISSING_OVERRIDEError message format for missing override of anAbstractCodeMember.static java.lang.StringMULTIPLE_OVERRIDESError message format for multiple overrides of the sameCodeMemberinside the sameCompilationUnit.static java.lang.StringNO_FOLLOWERSError message format forStatements with no followers.java.util.Set<java.lang.String>processedUnitsThe set ofCompilationUnits, represented by their names, that have been already processed byvalidateAndFinalize(CompilationUnit).static java.lang.StringUNKNOWN_ENTRYPOINTSError 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 voidvalidate(CodeMember member, boolean instance)Validates the givenCodeMember, checking that no other code member exists in its containingUnitwith the same signature, according toCodeMemberDescriptor.matchesSignature(CodeMemberDescriptor).voidvalidateAndFinalize(AbstractClassUnit unit)Validates the givenAbstractClassUnit.voidvalidateAndFinalize(ClassUnit unit)Validates the givenClassUnit.voidvalidateAndFinalize(CodeUnit unit)Validates the givenCodeUnit.voidvalidateAndFinalize(CompilationUnit unit)Validates the givenCompilationUnit.voidvalidateAndFinalize(InterfaceUnit unit)Validates the givenInterfaceUnit.voidvalidateAndFinalize(Program program)Validates the givenProgram, ensuring its consistency.voidvalidateAndFinalize(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 duplicatedCodeMembers in the sameUnit.- See Also:
- Constant Field Values
-
INVALID_NODE_LIST
public static final java.lang.String INVALID_NODE_LIST
Error message format for invalidNodeLists.- See Also:
- Constant Field Values
-
INVALID_CFSTRUCTURE
public static final java.lang.String INVALID_CFSTRUCTURE
Error message format for invalidControlFlowStructures.- See Also:
- Constant Field Values
-
EXIT_WITH_FOLLOWERS
public static final java.lang.String EXIT_WITH_FOLLOWERS
Error message format for terminatingStatements with followers.- See Also:
- Constant Field Values
-
NO_FOLLOWERS
public static final java.lang.String NO_FOLLOWERS
Error message format forStatements 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 forGlobals insideInterfaceUnits.- See Also:
- Constant Field Values
-
ABSTRACT_SEALED_UNIT
public static final java.lang.String ABSTRACT_SEALED_UNIT
Error message format for sealedAbstractClassUnits.- See Also:
- Constant Field Values
-
ABSTRACT_METHODS
public static final java.lang.String ABSTRACT_METHODS
Error message format forAbstractCodeMembers in non-AbstractClassUnits.- 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 sameCodeMemberinside the sameCompilationUnit.- See Also:
- Constant Field Values
-
ABSTRACT_NON_INSTANCE
public static final java.lang.String ABSTRACT_NON_INSTANCE
Error message format forAbstractCodeMemberthat is not instance.- See Also:
- Constant Field Values
-
MEMBER_MISMATCH
public static final java.lang.String MEMBER_MISMATCH
Error message format for aCodeMembernot matching its own signature.- See Also:
- Constant Field Values
-
processedUnits
public final java.util.Set<java.lang.String> processedUnits
The set ofCompilationUnits, 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 allCompilationUnits defined in the program).
Validating a program simply causes the validation of all theUnits andCodeMembers defined inside it, and ensures that all entrypoints (Program.getEntryPoints()) are defined.- Specified by:
validateAndFinalizein 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 itsCodeMembers 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
-
validateAndFinalize
public void validateAndFinalize(CodeUnit unit) throws ProgramValidationException
Validates the givenCodeUnit. This method checks that no instanceGlobals 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 noAbstractCodeMemberis 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 instanceGlobals 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 instanceCodeMembers are validated throughvalidate(CodeMember, boolean). These are also linked to other ones in the hierarchy, populating the collectionsCodeMemberDescriptor.overriddenBy()andCodeMemberDescriptor.overrides()and raising errors ifAbstractCodeMembers 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 containingUnitwith the same signature, according toCodeMemberDescriptor.matchesSignature(CodeMemberDescriptor). This avoids ambiguous call resolution. Moreover, this ensures that allCFGs 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
-
-