Procházet zdrojové kódy

Added support for licence headers in c code generator.
Bugfix: license feature name did not match in feature library and feature constants file.

markus.muehlbrandt@gmail.com před 13 roky
rodič
revize
80aa0a6e69

+ 4 - 4
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/CSCTGenerator.xtend

@@ -31,12 +31,12 @@ class CSCTGenerator implements IExecutionFlowGenerator {
 	
 	override generate(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa) {
 
-		flow.generateTypesH(flow.sourceElement as Statechart, fsa)
+		flow.generateTypesH(flow.sourceElement as Statechart, fsa, entry)
 		
-		flow.generateStatemachineH(flow.sourceElement as Statechart, fsa)
-		flow.generateStatemachineClientH(flow.sourceElement as Statechart, fsa)
+		flow.generateStatemachineH(flow.sourceElement as Statechart, fsa, entry)
+		flow.generateStatemachineClientH(flow.sourceElement as Statechart, fsa, entry)
 
-		flow.generateStatemachineC(flow.sourceElement as Statechart, fsa)
+		flow.generateStatemachineC(flow.sourceElement as Statechart, fsa, entry)
 
 	}
 

+ 32 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/GenmodelEntries.xtend

@@ -0,0 +1,32 @@
+/**
+  Copyright (c) 2012 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
+  http://www.eclipse.org/legal/epl-v10.html
+  Contributors:
+  	Markus Muehlbrandt - Initial contribution and API
+ */
+package org.yakindu.sct.generator.c
+
+import org.yakindu.sct.generator.core.features.ICoreFeatureConstants
+import org.yakindu.sct.model.sgen.FeatureParameterValue
+import org.yakindu.sct.model.sgen.GeneratorEntry
+
+class GenmodelEntries {
+	
+	def private getLicenseFeature(GeneratorEntry it) {
+		getFeatureConfiguration(ICoreFeatureConstants::LICENSE_HEADER)
+	}
+	
+	def private FeatureParameterValue getLicenseTextParameter(GeneratorEntry it) {
+		licenseFeature?.getParameterValue(ICoreFeatureConstants::LICENSE_TEXT)
+	}
+	
+	def getLicenseText(GeneratorEntry it) {
+		if (licenseTextParameter != null) {
+			return "/*"+licenseTextParameter.stringValue+"*/"
+		}
+		return null
+	}
+}

+ 7 - 3
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/Statemachine.xtend

@@ -23,18 +23,22 @@ import org.yakindu.sct.model.stext.stext.StatechartScope
 import org.yakindu.sct.model.sexec.TimeEvent
 import org.yakindu.sct.model.stext.stext.Direction
 import org.yakindu.base.types.ITypeSystemAccess
+import org.yakindu.sct.model.sgen.GeneratorEntry
 
 class Statemachine {
 	
 	@Inject extension Naming cNaming
 	@Inject extension Navigation
 	@Inject extension ITypeSystemAccess
+	@Inject extension GenmodelEntries
 	
-	def generateStatemachineH(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa) {
-		 fsa.generateFile(flow.module.h, flow.statemachineHContent )
+	def generateStatemachineH(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry) {
+		 fsa.generateFile(flow.module.h, flow.statemachineHContent(entry) )
 	}
 	
-	def statemachineHContent(ExecutionFlow it) '''
+	def statemachineHContent(ExecutionFlow it,  GeneratorEntry entry) '''
+			«entry.licenseText»
+			
 			#ifndef «module.define»_H_
 			#define «module.define»_H_
 

+ 11 - 7
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineC.xtend

@@ -17,21 +17,25 @@ import org.yakindu.sct.model.sexec.Check
 import org.yakindu.sct.model.sexec.ExecutionFlow
 import org.yakindu.sct.model.sexec.Step
 import org.yakindu.sct.model.sgraph.Statechart
-import org.yakindu.base.types.ITypeSystemAccess
-
+import org.yakindu.base.types.ITypeSystemAccess
+import org.yakindu.sct.model.sgen.GeneratorEntry
+import org.yakindu.sct.generator.c.GenmodelEntries
+
 class StatemachineC {
 	
 	@Inject extension Naming
 	@Inject extension Navigation
 	@Inject extension FlowCode
-	@Inject extension ITypeSystemAccess
+	@Inject extension ITypeSystemAccess
+	@Inject extension GenmodelEntries
 	
-	
-	def generateStatemachineC(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa) {
-		 fsa.generateFile(flow.module.c, flow.statemachineCContent )
+	def generateStatemachineC(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry) {
+		 fsa.generateFile(flow.module.c, flow.statemachineCContent(entry) )
 	}
 	
-	def statemachineCContent(ExecutionFlow it) '''
+	def statemachineCContent(ExecutionFlow it, GeneratorEntry entry) '''
+		«entry.licenseText»
+		
 		#include <stdlib.h>
 		#include <string.h>
 		#include "«typesModule.h»"

+ 7 - 3
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineRequired.xtend

@@ -18,18 +18,22 @@ import org.yakindu.sct.model.sgraph.Statechart
 import org.yakindu.sct.model.stext.stext.OperationDefinition
 import org.yakindu.sct.model.stext.stext.StatechartScope
 import org.yakindu.base.types.ITypeSystemAccess
+import org.yakindu.sct.model.sgen.GeneratorEntry
 
 class StatemachineRequired {
 
 	@Inject extension Naming cNaming
 	@Inject extension Navigation
 	@Inject extension ITypeSystemAccess
+	@Inject extension GenmodelEntries
 	
-	def generateStatemachineClientH(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa) {
-		 fsa.generateFile(flow.module.client.h, flow.statemachineClientHContent )
+	def generateStatemachineClientH(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry) {
+		 fsa.generateFile(flow.module.client.h, flow.statemachineClientHContent(entry) )
 	}
 	
-	def statemachineClientHContent(ExecutionFlow it) '''
+	def statemachineClientHContent(ExecutionFlow it, GeneratorEntry entry) '''
+			«entry.licenseText»
+			
 			#ifndef «module.client.define»_H_
 			#define «module.client.define»_H_
 

+ 7 - 3
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/Types.xtend

@@ -14,17 +14,21 @@ import org.yakindu.sct.model.sexec.ExecutionFlow
 import org.yakindu.sct.model.sgraph.Statechart
 import org.eclipse.xtext.generator.IFileSystemAccess
 import com.google.inject.Inject
+import org.yakindu.sct.model.sgen.GeneratorEntry
 
 class Types {
 	
 	@Inject extension Naming
+	@Inject extension GenmodelEntries
 	 
-	def generateTypesH(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa) {
-		 fsa.generateFile(flow.typesModule.h, flow.typesHContent)
+	def generateTypesH(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry) {
+		 fsa.generateFile(flow.typesModule.h, flow.typesHContent(entry))
 	}
 	
 	
-	def typesHContent(ExecutionFlow it) '''
+	def typesHContent(ExecutionFlow it, GeneratorEntry entry) '''
+		«entry.licenseText»
+		
 		#ifndef «typesModule.define»_H_
 		#define «typesModule.define»_H_
 		

+ 1 - 1
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/features/ICoreFeatureConstants.java

@@ -39,6 +39,6 @@ public interface ICoreFeatureConstants {
 	public static final String FUNCTION_INLINING_FEATURE_INLINE_ENTER_REGION = "inlineEnterRegion";
 	public static final String FUNCTION_INLINING_FEATURE_INLINE_EXIT_REGION = "inlineExitRegion";
 
-	public static final String LICENSE_HEADER = "licenseHeader";
+	public static final String LICENSE_HEADER = "LicenseHeader";
 	public static final String LICENSE_TEXT = "licenseText";
 }