Commit 3ade7057 authored by Daniel Honsel's avatar Daniel Honsel
Browse files

started scope for referenced values

parent c435ebe3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ Workflow {
			// Xtend-based API for validation
			fragment = validation.ValidatorFragment auto-inject {
			//    composedCheck = "org.eclipse.xtext.validation.ImportUriValidator"
			//    composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
			    composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
			}

			// old scoping and exporting API
+71 −0
Original line number Diff line number Diff line
package de.ugoe.cs.swe.common

import de.ugoe.cs.swe.tTCN3.ConstDef
import de.ugoe.cs.swe.tTCN3.ConstList
import de.ugoe.cs.swe.tTCN3.FunctionDefList
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.StatementBlock
import org.eclipse.emf.ecore.EObject
import org.eclipse.xtext.scoping.IScope

import static org.eclipse.xtext.scoping.Scopes.*

class TTCN3ScopeHelper {
	
	// TODO: use some generic solution
	def static ModuleDefinitionsList getModuleDefList(EObject o) {
		if (o.eContainer == null)
			null
		else if (o.eContainer instanceof ModuleDefinitionsList)
			o.eContainer as ModuleDefinitionsList
		else
			o.eContainer.getModuleDefList
	}
	
	def static StatementBlock getStatementBlock(EObject o) {
		if (o.eContainer == null)
			null
		else if (o.eContainer instanceof StatementBlock)
			o.eContainer as StatementBlock
		else
			o.eContainer.getStatementBlock
	}	
	
	def static IScope moduleVariableScope(RefValue value) {
		val container = value.getModuleDefList
		// TODO:  || it.def instanceof ModuleParDef
		val defs = container.definitions.filter[it.def instanceof ConstDef]
		val inner = newArrayList;
		
		for (EObject v : defs) {
			val constDefList = ((v as ModuleDefinition).def as ConstDef).defs as ConstList			
			for (EObject d : constDefList.list) {
				if (d != value) inner.add(d)
			}
		}		
		scopeFor(inner)				
	}
	
	def static IScope functionVariableScope(RefValue value) {
		val container = value.getStatementBlock
		
		if (container == null) {
			value.moduleVariableScope
		} else {
			val inner = newArrayList
			
			for (FunctionDefList l : container.def.filter [it != null])
			
			if( l.locDef.constDef != null ) {
				val constDefList = l.locDef.constDef.defs as ConstList
				for (EObject d : constDefList.list) {
					if (d != value) inner.add(d)
				}						
			}
			scopeFor(inner, value.moduleVariableScope)
		}
	}
	
}
+12 −11
Original line number Diff line number Diff line
/*
 * generated by Xtext
 */
package de.ugoe.cs.swe.scoping

/**
 * This class contains custom scoping description.
 * 
 * see : http://www.eclipse.org/Xtext/documentation.html#scoping
 * on how and when to use it 
 *
 */
class TTCN3ScopeProvider extends org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider {
import de.ugoe.cs.swe.tTCN3.RefValue
import org.eclipse.emf.ecore.EReference
import org.eclipse.xtext.scoping.IScope
import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider

import static extension de.ugoe.cs.swe.common.TTCN3ScopeHelper.*

class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider {
	
	def IScope scope_RefValue(RefValue value, EReference ref) {
		value.functionVariableScope
	}
	
}
+9 −15
Original line number Diff line number Diff line
package de.ugoe.cs.swe.validation
import org.eclipse.xtext.validation.Check
import de.ugoe.cs.swe.tTCN3.SingleConstDef
import de.ugoe.cs.swe.tTCN3.TTCN3Package
import org.eclipse.emf.ecore.EObject
import de.ugoe.cs.swe.tTCN3.ModuleDefinitionsList
import de.ugoe.cs.swe.tTCN3.ModuleDefinition

import de.ugoe.cs.swe.tTCN3.ConstDef
import de.ugoe.cs.swe.tTCN3.ConstList
import de.ugoe.cs.swe.tTCN3.ModuleDefinition
import de.ugoe.cs.swe.tTCN3.SingleConstDef
import de.ugoe.cs.swe.tTCN3.TTCN3Module
import de.ugoe.cs.swe.tTCN3.TTCN3Package
import org.eclipse.emf.ecore.EObject
import org.eclipse.xtext.validation.Check

import static extension de.ugoe.cs.swe.common.TTCN3ScopeHelper.*

class TTCN3Validator extends AbstractTTCN3Validator {

	@Check
	def checkUniqueNameNestedVariable(SingleConstDef variable) {
		val container = variable.moduleDefList
		val container = variable.getModuleDefList
		
		if (container == null) return;
		
@@ -32,14 +34,6 @@ class TTCN3Validator extends AbstractTTCN3Validator {
		}
	}
	
	def private ModuleDefinitionsList getModuleDefList(EObject o) {
		if (o.eContainer == null)
			null
		else if (o.eContainer instanceof ModuleDefinitionsList)
			o.eContainer as ModuleDefinitionsList
		else
			o.eContainer.getModuleDefList
	}
	
	@Check
	def checkModuleStartsWithM(TTCN3Module module) {