Browse Source

Added hooks and extended generator to handle external variables and
operations.

Axel Terfloth 9 years ago
parent
commit
64debc800f

+ 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;
 	

+ 11 - 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 {
 
@@ -75,9 +76,19 @@ class ExpressionCode {
 	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