Commit e0166ddb authored by Philip Makedonski's avatar Philip Makedonski
Browse files

+ improvements to checkNoValueOfForValues, #7, handle return types, templates, struct/union fields

parent cac47e2b
Loading
Loading
Loading
Loading
+38 −2
Original line number Diff line number Diff line
@@ -90,6 +90,9 @@ import static extension org.eclipse.emf.ecore.util.EcoreUtil.*
import static extension org.eclipse.xtext.EcoreUtil2.*
import org.eclipse.xtext.EcoreUtil2.ElementReferenceAcceptor
import org.eclipse.emf.ecore.EReference
import de.ugoe.cs.swe.tTCN3.StructFieldDef
import de.ugoe.cs.swe.tTCN3.OpCall
import de.ugoe.cs.swe.tTCN3.UnionFieldDef

class CheckDefinitionComeFirstParameter {
	public boolean hasOtherDefinitions
@@ -886,6 +889,7 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {
			return
		}
		//TODO: overly specific.. 
		//TODO: overly complicated -> simplify and reduce/invert conditions
		var target = ""
		val expr = templateOp.template.template.simple.expr
//		.ref.head
@@ -897,14 +901,46 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {
				if (expr.ref.referencedValue instanceof FormalTemplatePar) {
					return
				}
				if (expr.ref.referencedValue instanceof BaseTemplate) {
					return
				}
				//TODO: add modulepar handling once BNF has been updated
				if (expr.ref.referencedValue instanceof StructFieldDef 
					|| expr.ref.referencedValue instanceof UnionFieldDef
				) {
					if (expr.ref.head.target instanceof SingleTempVarInstance
					 || expr.ref.head.target instanceof FormalTemplatePar
					) {
						return
					}
				}
				
				target = expr.ref.referencedValue.name
				//TODO: other conditions?
				
			} else {
				//TODO: check further?
				//TODO: check further? e.g. predefined values?
				return
			}
		} else if (expr instanceof OpCall) {
			if (expr.function !== null) {
				if (expr.function.ref instanceof FunctionDef) {
					var returnType = (expr.function.ref as FunctionDef).returnType
					if (returnType.template !== null) {  
						return	
					}
					if (returnType.restricted !== null) { 
						return	
					}
					//TODO: add field or revert to template above?
					target = expr.function.ref.name
				} else if (expr.function.ref instanceof BaseTemplate) {
					return
				}
				//TODO: handle altsteps and others?
			}
		} else {
			//TODO: check further? e.g. function return types?
			//TODO: check further? 
			return
		}
		statistics.incrementCountStyle