Commit 0b5ee18b authored by Philip Makedonski's avatar Philip Makedonski
Browse files

+ added support for excluding types from checkNoUninitialisedVariables, related to #73

+ improved handling of variable assignments, related to #72
parent 2253ae03
Loading
Loading
Loading
Loading
+48 −1
Original line number Diff line number Diff line
@@ -61,6 +61,12 @@ import de.ugoe.cs.swe.tTCN3.Expression
import de.ugoe.cs.swe.tTCN3.BooleanExpression
import de.ugoe.cs.swe.tTCN3.AltstepInstance
import de.ugoe.cs.swe.tTCN3.FunctionActualPar
import de.ugoe.cs.swe.tTCN3.RecordDefNamed
import de.ugoe.cs.swe.tTCN3.RecordOfDefNamed
import de.ugoe.cs.swe.tTCN3.SetDefNamed
import de.ugoe.cs.swe.tTCN3.SetOfDefNamed
import de.ugoe.cs.swe.tTCN3.UnionDefNamed
import de.ugoe.cs.swe.tTCN3.EnumDefNamed

class DataFlowValidator extends AbstractDeclarativeValidator {
    val ConfigTools configTools = ConfigTools.getInstance;
@@ -287,7 +293,12 @@ class DataFlowValidator extends AbstractDeclarativeValidator {
    protected def void processVarInstance(VarInstance variable, DataFlowHelper dfh) {
        if (variable.list !== null) {
            for (target : variable.list.variables) {
                dfh.checkVariableStatus(target.eAllOfType(ReferencedValue))
                //DONE: this needs to be refined
                //split treatment of the variable and the right hand side (similar to assignment
                //TODO: also for templates below?
                if (target.expr !== null) {
                    target.expr.processExpression(dfh)
                }
                dfh.updateVariableStatus(target)
            }
        } else if (variable.tempList !== null) {
@@ -879,8 +890,44 @@ class DataFlowValidator extends AbstractDeclarativeValidator {
        }
    }
    
    protected def Boolean checkIfExcluded(SingleVarInstance target) {
        var filter = false
        if (!activeProfile.checkNoUninitialisedVariablesExclude.empty) {
            var vi = target.findDesiredParent(VarInstance)
            if (vi !== null) {
                var type = vi.listType
                if (type !== null) {
                    if (type.pre !== null && activeProfile.checkNoUninitialisedVariablesExclude.contains(type.pre)) {
                        filter = true;
                    } else if (type.ref !== null) {
                        if (type.ref.head instanceof RecordDefNamed && activeProfile.checkNoUninitialisedVariablesExclude.contains("record")) {
                            filter = true
                        } else if (type.ref.head instanceof RecordOfDefNamed && activeProfile.checkNoUninitialisedVariablesExclude.contains("record of")) {
                            filter = true
                        } else if (type.ref.head instanceof SetDefNamed && activeProfile.checkNoUninitialisedVariablesExclude.contains("set")) {
                            filter = true
                        } else if (type.ref.head instanceof SetOfDefNamed && activeProfile.checkNoUninitialisedVariablesExclude.contains("set of")) {
                            filter = true
                        } else if (type.ref.head instanceof UnionDefNamed && activeProfile.checkNoUninitialisedVariablesExclude.contains("union")) {
                            filter = true
                        } else if (type.ref.head instanceof EnumDefNamed && activeProfile.checkNoUninitialisedVariablesExclude.contains("enumerated")) {
                            filter = true
                        } else if (activeProfile.checkNoUninitialisedVariablesExclude.contains(type.ref.head.name)) {
                            filter = true
                        }
                    }
                } 
            }
        }
        return filter        
    }
    
    protected def void uninitialisedVariableWarning(SingleVarInstance target, String status, EObject context) {
        TTCN3StatisticsProvider.getInstance.incrementCountStyle
        if (checkIfExcluded(target)) {
            return
        }
        
        var parentName = "Module Control Part"
        val parent = context.findDesiredParent(FunctionDef)
        if (parent !== null) {
+9 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ public class QualityCheckProfile extends ConfigurationProfile {
	private boolean checkNoUnusedFormalParameters = true;
	private boolean checkNoUnusedLocalDefinitions = true;
	private boolean checkNoUninitialisedVariables = true;
	private String[] checkNoUninitialisedVariablesExclude = {"enumerated", "union", "record", "record of", "set", "set of"};
	private boolean checkNoLiterals = true;
	private boolean checkLevelOfNestedCalls = true;
	private int maxLevelOfNestedCalls = 4;
@@ -593,6 +594,14 @@ public class QualityCheckProfile extends ConfigurationProfile {
		this.dependencyOutputPath = dependencyOutputPath;
	}

	public String[] getCheckNoUninitialisedVariablesExclude() {
		return checkNoUninitialisedVariablesExclude;
	}

	public void setCheckNoUninitialisedVariablesExclude(String[] checkNoUninitialisedVariablesExclude) {
		this.checkNoUninitialisedVariablesExclude = checkNoUninitialisedVariablesExclude;
	}

	

}