浏览代码

Merge branch 'master' into userdoc_structure_2.2_back_to_textile

Rainer Klute 9 年之前
父节点
当前提交
9a6073d2ff

+ 9 - 8
plugins/org.yakindu.sct.domain.generic/src/org/yakindu/sct/domain/generic/extension/GenericDomainInjectorProvider.java

@@ -148,14 +148,15 @@ public class GenericDomainInjectorProvider implements IDomainInjectorProvider {
 	}
 
 	@Override
-	public Injector getGeneratorInjector(String generatorId, Module overrides) {
-		Module result = null;
-		if (overrides != null) {
-			result = Modules.override(getGeneratorModule(generatorId)).with(overrides);
-		} else
-			result = getGeneratorModule(generatorId);
-		result = Modules.override(getSequencerModule()).with(result);
-		return Guice.createInjector(result);
+	public Injector getGeneratorInjector(String generatorId, Module baseModule) {
+		Module genModule = getGeneratorModule(generatorId);
+
+		if (baseModule != null) {
+			genModule = Modules.override(baseModule).with(genModule);
+		} 
+		
+		genModule = Modules.override(getSequencerModule()).with(genModule);
+		return Guice.createInjector(genModule);
 	}
 
 }

+ 4 - 1
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/CCodeGenerator.java

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2012, 2015 Committers of YAKINDU and others.
+ * Copyright (c) 2012-2016 Committers of YAKINDU and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -34,10 +34,13 @@ import com.google.inject.util.Modules;
  * 
  * @author Andreas Mülder
  * @author Alexander Nyßen
+ * @author axel terfloth
  * 
  */
 public class CCodeGenerator extends GenericJavaBasedGenerator {
 
+	public static String GENERATOR_ID = "yakindu::c";
+	
 	@Inject
 	private CGenerator delegate;
 	

+ 10 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/ConstantInitializationResolver.xtend

@@ -12,6 +12,8 @@ package org.yakindu.sct.generator.c
 
 import org.yakindu.base.expressions.expressions.Expression
 import org.yakindu.sct.model.stext.stext.VariableDefinition
+import org.yakindu.base.expressions.expressions.FeatureCall
+import org.yakindu.base.expressions.expressions.ElementReferenceExpression
 
 class ConstantInitializationResolver extends ExpressionCode {
 	
@@ -23,4 +25,12 @@ class ConstantInitializationResolver extends ExpressionCode {
 		target.initialValue.code
 	}
 		
+	override dispatch CharSequence code(FeatureCall it, VariableDefinition target) {
+		target.initialValue.code
+	}
+		
+	override dispatch CharSequence code(ElementReferenceExpression it, VariableDefinition target) {
+		target.initialValue.code
+	}
+		
 }

+ 15 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/ExpressionCode.xtend

@@ -49,6 +49,7 @@ import org.yakindu.sct.model.stext.stext.EventRaisingExpression
 import org.yakindu.sct.model.stext.stext.EventValueReferenceExpression
 import org.yakindu.sct.model.stext.stext.OperationDefinition
 import org.yakindu.sct.model.stext.stext.VariableDefinition
+import org.yakindu.base.types.Operation
 
 class ExpressionCode {
 
@@ -72,12 +73,26 @@ class ExpressionCode {
 
 	def dispatch CharSequence code(Expression it, VariableDefinition target) '''«target.access»'''
 
+	def dispatch CharSequence code(ElementReferenceExpression it, VariableDefinition target) '''«target.access»'''
+
+	def dispatch CharSequence code(FeatureCall it, VariableDefinition target) '''«target.access»'''
+
 	def dispatch CharSequence code(ElementReferenceExpression it, OperationDefinition target) '''«target.access»(«scHandle»«FOR arg : args BEFORE ', ' SEPARATOR ', '»«arg.
 		code»«ENDFOR»)'''
 
+	def dispatch CharSequence code(ElementReferenceExpression it, Operation target) '''«target.access»(«FOR arg : args SEPARATOR ', '»«arg.
+		code»«ENDFOR»)'''
+
+	def dispatch CharSequence code(ElementReferenceExpression it, org.yakindu.base.types.Property target) '''«target.access»'''
+
 	def dispatch CharSequence code(FeatureCall it, OperationDefinition target) '''«target.access»(«scHandle»«FOR arg : args BEFORE ', ' SEPARATOR ', '»«arg.
 		code»«ENDFOR»)'''
 
+	def dispatch CharSequence code(FeatureCall it, Operation target) '''«it.owner.code».«target.access»(«FOR arg : args SEPARATOR ', '»«arg.
+		code»«ENDFOR»)'''
+
+	def dispatch CharSequence code(FeatureCall it, org.yakindu.base.types.Property target) '''«it.owner.code».«target.access»'''
+
 	/* HANDLING LITERALS */
 	def dispatch CharSequence code(Literal it) '''#error unknown literal type «getClass().name» '''
 	

+ 8 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/Naming.xtend

@@ -242,6 +242,14 @@ class Naming {
 		if (isConst) '''«it.constantName»''' else '''«scHandle»->«scope.instance».«name.asEscapedIdentifier»'''
 	}
 
+	def dispatch access(org.yakindu.base.types.Property it) {
+		'''«name.asEscapedIdentifier»'''
+	}
+
+	def dispatch access(org.yakindu.base.types.Operation it) {
+		'''«name.asEscapedIdentifier»'''
+	}
+
 	def dispatch access(OperationDefinition it) '''«asFunction»'''
 
 	def dispatch access(Event it) '''«scHandle»->«scope.instance».«name.asIdentifier.raised»'''

+ 7 - 2
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineHeader.xtend

@@ -37,6 +37,7 @@ class StatemachineHeader {
 	@Inject extension GenmodelEntries
 	@Inject extension INamingService
 
+	
 	def generateStatemachineHeader(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry) {
 		flow.initializeNamingService
 		fsa.generateFile(flow.module.h, flow.generateStatemachineHeaderContents(entry))
@@ -48,8 +49,8 @@ class StatemachineHeader {
 		#ifndef «module.define»_H_
 		#define «module.define»_H_
 		
-		#include "«typesModule.h»"
-		
+		«includes»
+				
 		#ifdef __cplusplus
 		extern "C" { 
 		#endif 
@@ -109,6 +110,10 @@ class StatemachineHeader {
 		#endif /* «module.define»_H_ */
 	'''
 
+	def includes(ExecutionFlow it) '''
+		#include "«typesModule.h»"
+	'''
+	
 	def statesEnumDecl(ExecutionFlow it) '''
 		/*! Enumeration of all states */ 
 		typedef enum

+ 1 - 1
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineRequiredHeader.xtend

@@ -132,7 +132,7 @@ class StatemachineRequiredHeader {
 	def dispatch functionPrototypes(Declaration it) ''''''
 
 	def dispatch functionPrototypes(OperationDefinition it) '''
-		extern «type.targetLanguageName» «asFunction»(«scHandleDecl»«FOR p : parameters BEFORE ', ' SEPARATOR ', '»const «p.type.targetLanguageName» «p.name.asIdentifier»«ENDFOR»);
+		extern «type.targetLanguageName» «asFunction»(const «scHandleDecl»«FOR p : parameters BEFORE ', ' SEPARATOR ', '»const «p.type.targetLanguageName» «p.name.asIdentifier»«ENDFOR»);
 	'''
 
 }

+ 14 - 0
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/GeneratorExecutor.java

@@ -18,7 +18,11 @@ import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.emf.common.util.EList;
 import org.eclipse.emf.common.util.URI;
 import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
 import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.yakindu.base.types.typesystem.AbstractTypeSystem;
+import org.yakindu.base.types.typesystem.ITypeSystem;
 import org.yakindu.sct.domain.extension.DomainRegistry;
 import org.yakindu.sct.domain.extension.IDomainDescriptor;
 import org.yakindu.sct.generator.core.extensions.GeneratorExtensions;
@@ -44,6 +48,7 @@ public class GeneratorExecutor {
 			return;
 		final GeneratorModel model = (GeneratorModel) resource.getContents().get(0);
 
+
 		Job generatorJob = new Job("Execute SCT Genmodel " + file.getName()) {
 			@Override
 			protected IStatus run(IProgressMonitor monitor) {
@@ -81,6 +86,15 @@ public class GeneratorExecutor {
 		Injector injector = domainDescriptor.getDomainInjectorProvider().getGeneratorInjector(model.getGeneratorId(),
 				overridesModule);
 		injector.injectMembers(generator);
+		
+		// TODO: refactor location for adding type system resource.
+		ITypeSystem typeSystem = injector.getInstance(ITypeSystem.class);
+		if (typeSystem instanceof AbstractTypeSystem) {
+			ResourceSet set = entry.getElementRef().eResource().getResourceSet();
+			set.getResources().add(((AbstractTypeSystem) typeSystem).getResource());
+			EcoreUtil.resolveAll(set);
+		}
+
 		return generator;
 	}
 

+ 25 - 25
test-plugins/org.yakindu.sct.generator.c.test/gtests/Operations/OperationsCustom.cc

@@ -75,37 +75,37 @@ TEST(StatemachineTest, OperationCallback) {
 }
 
 
-void operationsInternal_internalOperation1(Operations* handle){
+void operationsInternal_internalOperation1(const Operations* handle){
 	internalOperation1Called = true;
 }
 
-sc_boolean operationsInternal_internalOperation2(Operations* handle, const sc_integer param1){
+sc_boolean operationsInternal_internalOperation2(const Operations* handle, const sc_integer param1){
 	internalOperation2Called = true;
 	internalOp2Param = param1;
 	return true;
 }
 
-sc_real operationsInternal_internalOperation3(Operations* handle){
+sc_real operationsInternal_internalOperation3(const Operations* handle){
 	return 0.0d;
 }
 
-sc_real operationsInternal_internalOperation3a(Operations* handle, const sc_real param1){
+sc_real operationsInternal_internalOperation3a(const Operations* handle, const sc_real param1){
 	return 0.0d;
 }
 
-sc_integer operationsInternal_internalOperation4(Operations* handle){
+sc_integer operationsInternal_internalOperation4(const Operations* handle){
 	return 0;
 }
 
-sc_integer operationsInternal_internalOperation4a(Operations* handle, const sc_integer param1){
+sc_integer operationsInternal_internalOperation4a(const Operations* handle, const sc_integer param1){
 	return 0;
 }
 
-sc_string operationsInternal_internalOperation5(Operations* handle){
+sc_string operationsInternal_internalOperation5(const Operations* handle){
 	return &myChar;
 }
 
-sc_string operationsInternal_internalOperation5a(Operations* handle, const sc_string param1){
+sc_string operationsInternal_internalOperation5a(const Operations* handle, const sc_string param1){
 	return &myChar;
 }
 
@@ -117,37 +117,37 @@ sc_string operationsInternal_internalOperation5a(Operations* handle, const sc_st
 
 
 
-void operationsIfaceInterface1_interfaceOperation1(Operations* handle){
+void operationsIfaceInterface1_interfaceOperation1(const Operations* handle){
 	interfaceOperation1Called = true;
 }
 
-sc_boolean operationsIfaceInterface1_interfaceOperation2(Operations* handle, const sc_integer param1){
+sc_boolean operationsIfaceInterface1_interfaceOperation2(const Operations* handle, const sc_integer param1){
 	interfaceOperation2Called = true;
 	interfaceOp2Param = param1;
 	return true;
 }
 
-sc_real operationsIfaceInterface1_interfaceOperation3(Operations* handle){
+sc_real operationsIfaceInterface1_interfaceOperation3(const Operations* handle){
 	return 0.0d;
 }
 
-sc_real operationsIfaceInterface1_interfaceOperation3a(Operations* handle, const sc_real param1){
+sc_real operationsIfaceInterface1_interfaceOperation3a(const Operations* handle, const sc_real param1){
 	return 0.0d;
 }
 
-sc_integer operationsIfaceInterface1_interfaceOperation4(Operations* handle){
+sc_integer operationsIfaceInterface1_interfaceOperation4(const Operations* handle){
 	return 0;
 }
 
-sc_integer operationsIfaceInterface1_interfaceOperation4a(Operations* handle, const sc_integer param1){
+sc_integer operationsIfaceInterface1_interfaceOperation4a(const Operations* handle, const sc_integer param1){
 	return 0;
 }
 
-sc_string operationsIfaceInterface1_interfaceOperation5(Operations* handle){
+sc_string operationsIfaceInterface1_interfaceOperation5(const Operations* handle){
 	return &myChar;
 }
 
-sc_string operationsIfaceInterface1_interfaceOperation5a(Operations* handle, const sc_string param1){
+sc_string operationsIfaceInterface1_interfaceOperation5a(const Operations* handle, const sc_string param1){
 	return &myChar;
 }
 
@@ -161,40 +161,40 @@ sc_string operationsIfaceInterface1_interfaceOperation5a(Operations* handle, con
 
 
 
-void operationsIface_unnamedInterfaceOperation1(Operations* handle){
+void operationsIface_unnamedInterfaceOperation1(const Operations* handle){
 	unnamedInterfaceOperation1Called = true;
 }
 
-sc_boolean operationsIface_unnamedInterfaceOperation2(Operations* handle, const sc_integer param1){
+sc_boolean operationsIface_unnamedInterfaceOperation2(const Operations* handle, const sc_integer param1){
 	unnamedInterfaceOperation2Called = true;
 	unnamedInterfaceOp2Param = param1;
 	return true;
 }
 
-sc_real operationsIface_unnamedOperation3(Operations* handle){
+sc_real operationsIface_unnamedOperation3(const Operations* handle){
 	return 0.0d;
 }
 
-sc_real operationsIface_unnamedOperation3a(Operations* handle, const sc_real param1){
+sc_real operationsIface_unnamedOperation3a(const Operations* handle, const sc_real param1){
 	return 0.0d;
 }
 
-sc_integer operationsIface_unnamedOperation4(Operations* handle){
+sc_integer operationsIface_unnamedOperation4(const Operations* handle){
 	return 0;
 }
 
-sc_integer operationsIface_unnamedOperation4a(Operations* handle, const sc_integer param1){
+sc_integer operationsIface_unnamedOperation4a(const Operations* handle, const sc_integer param1){
 	return 0;
 }
 
-sc_string operationsIface_unnamedOperation5(Operations* handle){
+sc_string operationsIface_unnamedOperation5(const Operations* handle){
 	return &myChar;
 }
 
-sc_string operationsIface_unnamedOperation5a(Operations* handle, const sc_string param1){
+sc_string operationsIface_unnamedOperation5a(const Operations* handle, const sc_string param1){
 	return &myChar;
 }
 
-sc_boolean operationsIface_alwaysTrue(Operations* handle){
+sc_boolean operationsIface_alwaysTrue(const Operations* handle){
 	return true;
 }

+ 3 - 3
test-plugins/org.yakindu.sct.generator.c.test/gtests/OperationsWithoutBraces/OperationsWithoutBracesCustom.cc

@@ -31,14 +31,14 @@ TEST(StatemachineTest, OperationsWithoutBracesTest) {
 	EXPECT_TRUE(operationsWithoutBraces_isStateActive(&handle, OperationsWithoutBraces_another_region_D));
 }
 		
-sc_boolean operationsWithoutBracesIface_myBoolOp(OperationsWithoutBraces* handle){
+sc_boolean operationsWithoutBracesIface_myBoolOp(const OperationsWithoutBraces* handle){
 	return false;
 }
 
-sc_integer operationsWithoutBracesIface_myIntOp(OperationsWithoutBraces* handle){
+sc_integer operationsWithoutBracesIface_myIntOp(const OperationsWithoutBraces* handle){
 	return 0;
 }
 
-sc_real operationsWithoutBracesIface_myRealOp(OperationsWithoutBraces* handle){
+sc_real operationsWithoutBracesIface_myRealOp(const OperationsWithoutBraces* handle){
 	return 0.0;
 }