Commit abe85ea2 authored by Daniel Honsel's avatar Daniel Honsel
Browse files

recognize name clashes with function parameters

parent 960d60c7
Loading
Loading
Loading
Loading
+42 −11
Original line number Diff line number Diff line
@@ -2,19 +2,24 @@ package de.ugoe.cs.swe.validation

import de.ugoe.cs.swe.tTCN3.ConstDef
import de.ugoe.cs.swe.tTCN3.ConstList
import de.ugoe.cs.swe.tTCN3.ForStatement
import de.ugoe.cs.swe.tTCN3.FunctionDef
import de.ugoe.cs.swe.tTCN3.FunctionDefList
import de.ugoe.cs.swe.tTCN3.FunctionFormalPar
import de.ugoe.cs.swe.tTCN3.FunctionFormalParList
import de.ugoe.cs.swe.tTCN3.Initial
import de.ugoe.cs.swe.tTCN3.ModuleDefinition
import de.ugoe.cs.swe.tTCN3.ModuleDefinitionsList
import de.ugoe.cs.swe.tTCN3.RefValue
import de.ugoe.cs.swe.tTCN3.SingleConstDef
import de.ugoe.cs.swe.tTCN3.SingleVarInstance
import de.ugoe.cs.swe.tTCN3.StatementBlock
import de.ugoe.cs.swe.tTCN3.TTCN3Module
import de.ugoe.cs.swe.tTCN3.TTCN3Package
import de.ugoe.cs.swe.tTCN3.VarList
import org.eclipse.emf.ecore.EObject
import org.eclipse.xtext.validation.Check
import de.ugoe.cs.swe.tTCN3.SingleVarInstance
import de.ugoe.cs.swe.tTCN3.VarList
import de.ugoe.cs.swe.tTCN3.Initial
import de.ugoe.cs.swe.tTCN3.FormalValuePar

class TTCN3Validator extends AbstractTTCN3Validator {

@@ -28,6 +33,11 @@ class TTCN3Validator extends AbstractTTCN3Validator {
		variable.isNameClashInHierarchy
	}
	
	@Check
	def checkUniqueNameNestedVariable(FormalValuePar variable) {
		variable.isNameClashInHierarchy
	}	
	
	def private isNameClashInHierarchy(RefValue variable) {
		var parent = variable.eContainer
		while (parent != null) {
@@ -35,22 +45,36 @@ class TTCN3Validator extends AbstractTTCN3Validator {
			if (parent instanceof ModuleDefinitionsList) {
				if (parent.checkNameClashModuleDefinitionsList(variable)) {
					// TODO: TTCN3Package$Literals::SINGLE_CONST_DEF__NAME
					error('Name clash with constant variable definition in this scope!', null, -1);
					error('Name clash with another variable definition in this scope!', null, -1);
					return;
				}
			} else if (parent instanceof StatementBlock) {
				if (parent.checkNameClasStatementBlock(variable)) {
					error('Name clash with constant variable definition in this scope!', null, -1);
					error('Name clash with another variable definition in this scope!', null, -1);
					return;
				}
			} else if (parent instanceof Initial) {
				if (parent.checkNameClashInitial(variable)) {
					error('Name clash with constant variable definition in this scope!', null, -1);
					error('Name clash with another variable definition in this scope!', null, -1);
					return;
				}				
			} else if (parent instanceof ForStatement) {
				if (parent.init.checkNameClashInitial(variable)) {
					error('Name clash with another variable definition in this scope!', null, -1);
					return;
				}			
			} else if (parent instanceof FunctionDef) {
				if (parent.parameterList != null && parent.parameterList.checkNameClashFunctionParameterValue(variable)) {
					error('Name clash with another variable definition in this scope!', null, -1);
					return;
				}
			} else if (parent instanceof FunctionFormalParList) {
				if (parent.checkNameClashFunctionParameterValue(variable)) {
					error('Name clash with another variable definition in this scope!', null, -1);
					return;
				}
			}
			
			// TODO: function parameter
			// TODO: other references in scope
			parent = parent.eContainer
		}
@@ -95,7 +119,6 @@ class TTCN3Validator extends AbstractTTCN3Validator {
		return false;
	}
	
	// TODO: fix this
	def private boolean checkNameClashInitial(Initial init, RefValue variable) {
		if (init.variable != null) {
			val varList = init.variable.list as VarList
@@ -105,7 +128,15 @@ class TTCN3Validator extends AbstractTTCN3Validator {
				}
			}
		}
		return false
		return false;
	}
	
	def private boolean checkNameClashFunctionParameterValue(FunctionFormalParList list, RefValue variable) {
		for (FunctionFormalPar p : list.params.filter[it.value != null] ) {
			if (p.value != variable && p.value.name == variable.name)
				return true;
		}
		return false;
	}
	
	@Check