⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 checkmarte4cheddar.atl

📁 papyrus插件MARTE例子,uml建模
💻 ATL
📖 第 1 页 / 共 2 页
字号:
-- Thales MARTE to Cheddar (Copyright (c) THALES 2007 All rights reserved) is free software; you can redistribute itand/or modify-- it under the terms of the Eclipse Public License as published in http://www.eclipse.org/legal/epl-v10.html---- Thales MARTE to Cheddar is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Eclipse Public License for more details.---------------------------------------------------- Nicolas VIENNE-- Eric MAES---------------------------------------------------- Check the if MARTE model is well formed for MARTE2Cheddar transform ...--------------------------------------------------module CheckMARTE4cheddar;create  OUT:PROBLEM from IN:UML, parameters:XML;------ Libraries----uses MARTE;uses UML2;uses MARTE4CHEDDAR;uses XMLPARAMETERS;------ Check if the element is the element targeted by parameters----helper context UML!Element def : isTarget() : Boolean = 	if thisModule.hasParameter('targetElement') then 			if self.oclIsKindOf(UML!NamedElement) then				if thisModule.getParameter('targetElement') = self.getQualifiedName() then					true				else false endif			else true endif		else true endif;helper def : getErrorTarget(): String = 	if thisModule.hasParameter('targetElement')  then		' (' + thisModule.getParameter('targetElement') + ')'	else '' endif;------ Helping Rules----rule critic(e:UML!NamedElement, s:String) {	to p:PROBLEM!Problem (		severity <- #critic,		location <- e.getQualifiedName() + thisModule.getErrorTarget(),		description <-s	)}rule error(e:UML!NamedElement, s:String) {	to p:PROBLEM!Problem (		severity <- #error,		location <- e.getQualifiedName() + thisModule.getErrorTarget(),		description <-s	)}rule warning(e:UML!NamedElement, s:String) {	to p:PROBLEM!Problem (		severity <- #warning,		location <- e.getQualifiedName() + thisModule.getErrorTarget(),		description <-s	)}rule info(loc: String, descr:String) {	to p:PROBLEM!Problem (		severity <- #warning,		location <- loc + thisModule.getErrorTarget(),		description <- 'INFO: '+descr	)}rule unkerror2(e:UML!NamedElement,cont:String) {	to p:PROBLEM!Problem (		severity <- #error,		location <- cont + thisModule.getErrorTarget(),		description <-e.getQualifiedName() + ' is not a known element (it may be missing in a resources list)'	)}rule undeferror(e:UML!NamedElement, s:String) {	do {		thisModule.error(e,s+' is not defined');	}}rule unkerror(e:UML!NamedElement,e2:UML!NamedElement) {	do {		thisModule.error(e,e2.getQualifiedName() + ' is not a known element (it may be missing in a resources list)');	}}rule unkwarning(e:UML!NamedElement,e2:UML!NamedElement) {	do {		thisModule.warning(e,e2.getQualifiedName() + ' is not a known element (it may be missing in a resources list)');	}}rule undefwarning(e:UML!NamedElement, s:String) {	do {		thisModule.warning(e,s+' is not defined');	}}------ Rules----helper def : KnownNames : Sequence(String) = Sequence {};helper def : ProcessorNames : Sequence(String) = Sequence {};helper def : TaskNames : Sequence(String) = Sequence {};helper def : AddressSpaceNames : Sequence(String) = Sequence {};helper def : ResourceNames : Sequence(String) = Sequence {};helper def : MessageNames : Sequence(String) = Sequence {};helper def : BufferNames : Sequence(String) = Sequence {};helper def : EANames : Sequence(String) = Sequence {};helper def : AnalysisContextCount : Integer = 0;------ Rules----rule scheduler(e:UML!Element) {	do {		-- Scheduling Policy		let sp : String = e.marteGetAttributeValue(e.Scheduler(), e.Scheduler_schedPolicy()).toString() in 		if sp='IN!'+e.SchedPolicyKind_EarliestDeadlineFirst() then			0		else if sp='IN!'+e.SchedPolicyKind_LeastLaxityFirst() then			0		else if sp='IN!'+e.SchedPolicyKind_FixedPriority() then			0		else if sp='IN!'+e.SchedPolicyKind_RoundRobin() then			0		else if sp='IN!'+e.SchedPolicyKind_Other() then			if e.marteHasAttributeValue(e.Scheduler(), e.Scheduler_otherSchedPolicy()) then				let sp2 : String = e.marteGetAttributeValue(e.Scheduler(), e.Scheduler_otherSchedPolicy()) in				if sp2 = 'RATE_MONOTONIC_PROTOCOL' then					0				else if sp2 = 'DEADLINE_MONOTONIC_PROTOCOL' then					0				else if sp2 = 'TIME_SHARING_BASED_ON_WAIT_TIME_PROTOCOL' then					0				else if sp2 = 'MAXIMUM_URGENCY_FIRST_BASED_ON_LAXITY_PROTOCOL' then					0				else if sp2 = 'MAXIMUM_URGENCY_FIRST_BASED_ON_DEADLINE_PROTOCOL' then					0				else if sp2 = 'D_OVER_PROTOCOL' then					0				else if sp2 = 'TIME_SHARING_BASED_ON_CPU_USAGE_PROTOCOL' then					0				else 						thisModule.error(e,'Invalid scheduling policy, Scheduler::schedPolicy and/or Scheduler::otherSchedPolicy seems to be invalid')				endif					endif				endif				endif				endif				endif				endif			else					thisModule.error(e,'Invalid scheduling policy, Scheduler::schedPolicy and/or Scheduler::otherSchedPolicy seems to be invalid')			endif		else if sp='IN!'+e.SchedPolicyKind_Undef() then			#PIPELINE_USER_DEFINED_PROTOCOL		else			thisModule.error(e,'Invalid scheduling policy, Scheduler::schedPolicy and/or Scheduler::otherSchedPolicy seems to be invalid')		endif		endif		endif		endif		endif		endif;						-- Preemptibility		if(e.marteHasAttributeValue(e.Scheduler(), e.Scheduler_isPreemptible())) {			if(not (e.marteGetAttributeValue(e.Scheduler(), e.Scheduler_isPreemptible()) = 'true') and not (e.marteGetAttributeValue(e.Scheduler(), e.Scheduler_isPreemptible()) = 'false')) {				thisModule.error(e, 'Scheduler::isPreemtible invalid');			}		} else {			thisModule.undefwarning(e, 'Scheduler::isPreemtible');		}				-- parametric_filename		if (e.marteGetAttributeValue(e.Scheduler(), e.Scheduler_schedPolicy()).toString() = 'IN!'+e.SchedPolicyKind_Undef()) {			if( not e.marteHasAttributeValue(e.Scheduler(), e.Scheduler_otherSchedPolicy())) {				thisModule.error(e, 'otherSchedPolicy (parametric_filename) undefined with scheduling policy Undef');			}		}	}}rule processor( e:UML!Element) {	do {		e.verboseMessage('processor ' + e.getQName());		let s : UML!Element = e.getStereotypeAttributeValue(if e.marteIsTypeOf(e.SaExecHost()) then e.SaExecHost() else e.GaExecHost() endif,e.ProcessingResource_mainScheduler())		in if s.oclIsUndefined() then thisModule.undefwarning(e, 'mainScheduler')		else thisModule.scheduler(s) endif;			-- check for duplicate names		if(thisModule.KnownNames->exists(s | s = e.getQName())) {			thisModule.error(e, 'Duplicate name found');		} else {			thisModule.KnownNames <- thisModule.KnownNames->append(e.getQName());			thisModule.ProcessorNames <- thisModule.ProcessorNames->append(e.getQName());		}	}}rule address_space (e:UML!Element) {		do {		e.verboseMessage('address_space '+e.getQName());		 let proc : UML!Element = e.getFirstStereotypedTypeOfStereotypeAttribute_Seq(			e.MemoryPartition(), e.MemoryPartition_concurrentResources(),			Sequence {e.GaExecHost(), e.SaExecHost()})		in if not proc.oclIsUndefined() then			if thisModule.ProcessorNames->exists(s | s = proc.getQName()) then OclUndefined -- the processor referenced exists			else thisModule.unkerror(e,proc) endif		else thisModule.error(e, 'No <<GaExecHost>> or <<SaExecHost>> found in concurrentResources') endif;				let sched : UML!Element = e.getFirstStereotypedTypeOfStereotypeAttribute(			e.MemoryPartition(), e.MemoryPartition_concurrentResources(), e.Scheduler())		in if not sched.oclIsUndefined() then			thisModule.scheduler(sched)		else thisModule.error(e, 'No <<Scheduler>> found in concurrentResources') endif;				-- check for duplicate names		if(thisModule.KnownNames->exists(s | s = e.getQName())) {			thisModule.error(e, 'Duplicate name found');		} else {			thisModule.KnownNames <- thisModule.KnownNames->append(e.getQName());			thisModule.AddressSpaceNames <- thisModule.AddressSpaceNames->append(e.getQName());		}	}}rule task ( e:UML!Element) {	do {		e.verboseMessage('task '+e.getQName());				-- address_space (matched by name)		let as : UML!Element = e.getFirstStereotypedTypeOfStereotypeAttribute(e.SwSchedulableResource(), e.SwConcurrentResource_addressSpace(), e.MemoryPartition())			in if not as.oclIsUndefined() then 				if thisModule.AddressSpaceNames->exists(s | s = as.getQName()) then OclUndefined -- the referenced address_space exists				else thisModule.unkerror(e,as) endif			else thisModule.error(e,'No address_space defined (addressSpace should contain a element which type is an existing <<MemoryPartition>> element)') endif;						-- activation capacity		if(not e.marteHasAttributeValue(e.SwSchedulableResource(), e.SwConcurrentResource_activationCapacity())) {			thisModule.undeferror(e,'activationCapacity'); 		} else {			if( e.marteGetAttributeValue(e.SwSchedulableResource(), e.SwConcurrentResource_activationCapacity())='') {				thisModule.undeferror(e,'activationCapacity');			} else  if(not( e.marteGetAttributeValue(e.SwSchedulableResource(), e.SwConcurrentResource_activationCapacity()).toInteger() > 0)) {				thisModule.error(e,'activationCapacity must be > 0');			}		}				-- priority		if(e.getIntSADVBN(e.SwSchedulableResource(), e.SwConcurrentResource_priorityElements(), 'priority').oclIsUndefined()) {			thisModule.undeferror(e,'priority'); 		} else {			if(not (e.getIntSADVBN(e.SwSchedulableResource(), e.SwConcurrentResource_priorityElements(), 'priority') > 0)) {			thisModule.error(e,'priority must be > 0'); 			}		}		--  		-- /!\		--		-- WARNING : VSL Workaround		 if(e.marteHasAttributeValue(e.SwSchedulableResource(), e.SwConcurrentResource_type())) {		 	if(e.marteGetAttributeValue(e.SwSchedulableResource(), e.SwConcurrentResource_type()) =  'PERIODIC_TYPE'		 			or e.marteGetAttributeValue(e.SwSchedulableResource(), e.SwConcurrentResource_type()) =  'SPORADIC_TYPE'					or e.marteGetAttributeValue(e.SwSchedulableResource(), e.SwConcurrentResource_type()) =  'POISSON_TYPE' ) {		 		if(e.getIntSADVBN(e.SwSchedulableResource(), e.SwConcurrentResource_periodElements(), 'period').oclIsUndefined()) {		 			thisModule.error(e,'a period must be defined for this task\'s kind');		 		}		 	} else  if(e.marteGetAttributeValue(e.SwSchedulableResource(), e.SwConcurrentResource_type()) =  'PARAMETRIC_TYPE') {		 		if(e.getStrSADVBN(e.SwSchedulableResource(), e.SwResource_stateElements(), 'activation_rule').oclIsUndefined()) {		 			thisModule.error(e,'an activation rule must be defined for this task\'s kind');		 		}		 	} else  if(e.marteGetAttributeValue(e.SwSchedulableResource(), e.SwConcurrentResource_type()) =  'APERIODIC_TYPE') {		 		OclUndefined; -- 		 	} else {		 		thisModule.undeferror(e,'type');		 	}		 } else {		 	thisModule.undeferror(e,'type');		 }		--  		-- /!\		--		-- WARNING : <<SchedulableResourceInheritance>> Workaround		if(e.hasStereotypeKindOf(e.SchedulableResource())) {			if(e.hasStereotypeAttributeValue(e.SchedulableResource(), e.SchedulableResource_host())) {				-- CPU_NAME				 let exechost : UML!Element =					let scheduler : UML!Element = e.getStereotypeAttributeValue(e.SchedulableResource(), e.SchedulableResource_host())					in if not scheduler.oclIsUndefined() then						if scheduler.hasStereotypeKindOf(e.Scheduler()) then							scheduler.getStereotypeAttributeValue(e.Scheduler(), e.Scheduler_host())						else  thisModule.error(e,'host is not a valid scheduler')endif					else  thisModule.undeferror(e,'host') endif				in if not exechost.oclIsUndefined() then					if thisModule.ProcessorNames->exists(s | s = exechost.getQName()) then OclUndefined					else thisModule.unkerror(e,exechost) endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -