Parcourir la source

First prototype for relative include path computation.

Thomas Kutz il y a 9 ans
Parent
commit
1a28428c6c

+ 69 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/ArtifactLocationProvider.java

@@ -0,0 +1,69 @@
+package org.yakindu.sct.generator.c;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.util.URI;
+import org.yakindu.sct.generator.core.filesystem.ISCTFileSystemAccess;
+
+public class ArtifactLocationProvider {
+
+	private ISCTFileSystemAccess sctFsa;
+
+	public static class Artifact {
+		
+		private String outputName;
+		private String name;
+		
+		public Artifact(String name, String outputConfigName) {
+			this.name = name;
+			this.outputName = outputConfigName;
+		}
+
+		public String getName() {
+			return name;
+		}
+
+		public String getOutputName() {
+			return outputName;
+		}
+	}
+	
+	public ArtifactLocationProvider(ISCTFileSystemAccess sctFsa) {
+		this.sctFsa = sctFsa;
+	}
+	
+	protected List<Artifact> generationArtifacts = new ArrayList<Artifact>();
+	
+	public void addArtifact(String artifactName, String outputConfigName) {
+		generationArtifacts.add(new Artifact(artifactName, outputConfigName));
+	}
+
+	protected URI getURIForArtifcat(String artifactName) {
+		for (Artifact artifact : generationArtifacts) {
+			if (artifact.getName().equals(artifactName)) {
+				return sctFsa.getURI(artifact.getName(), artifact.getOutputName());
+			}
+		}
+		return null;
+	}
+	
+	public String computeRelativeForPath(String absolutePath, String baseArtifactName) {
+		URI baseTarget = getURIForArtifcat(baseArtifactName);
+		
+		IPath basePath = new Path(baseTarget.toFileString());
+		IPath absPath = new Path(absolutePath);
+		return absPath.makeRelativeTo(basePath).toOSString();
+	}
+	
+	public String computeRelativeForName(String referencedArtifactName, String baseArtifactName) {
+		URI baseUri = getURIForArtifcat(baseArtifactName);
+		URI absUri = getURIForArtifcat(referencedArtifactName);
+		
+		IPath basePath = new Path(baseUri.toFileString());
+		IPath absPath = new Path(absUri.toFileString());
+		return absPath.makeRelativeTo(basePath).toOSString();
+	}
+}

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

@@ -50,7 +50,7 @@ public class CCodeGenerator extends GenericJavaBasedGenerator {
 		if (debugFeatureHelper.isDumpSexec(entry)) {
 			dumpSexec(entry, flow);
 		}
-		delegate.generate(flow, entry, sctFsa.getIFileSystemAccess());
+		delegate.generate(flow, entry, sctFsa);
 	}
 
 	@Override

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

@@ -16,6 +16,7 @@ import org.yakindu.sct.generator.core.impl.IExecutionFlowGenerator
 import org.yakindu.sct.model.sexec.ExecutionFlow
 import org.yakindu.sct.model.sgen.GeneratorEntry
 import org.yakindu.sct.model.sgraph.Statechart
+import org.yakindu.sct.generator.core.filesystem.ISCTFileSystemAccess
 
 /**
  * This is the C code generators main class. 
@@ -31,12 +32,34 @@ class CGenerator implements IExecutionFlowGenerator {
 	@Inject extension Navigation
 	@Inject extension GenmodelEntries
 	
+	@Inject extension Naming
+	
 	override generate(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa) {
-		flow.generateTypesH(flow.sourceElement as Statechart, fsa, entry)
-		flow.generateStatemachineHeader(flow.sourceElement as Statechart, fsa, entry)
+//		flow.generateTypesH(flow.sourceElement as Statechart, fsa, entry)
+//		flow.generateStatemachineHeader(flow.sourceElement as Statechart, fsa, entry)
+//		if (flow.timed || !flow.operations.empty || entry.tracingEnterState || entry.tracingExitState) {
+//			flow.generateStatemachineRequiredHeader(flow.sourceElement as Statechart, fsa, entry)
+//		}
+//		flow.generateStatemachineSource(flow.sourceElement as Statechart, fsa, entry)
+	}
+	
+	def generate(ExecutionFlow flow, GeneratorEntry entry, ISCTFileSystemAccess sctFsa) {
+		// initialize generation artifacts and their locations
+		val locations = new ArtifactLocationProvider(sctFsa)
+		locations.addArtifact(flow.typesModule.h, IExecutionFlowGenerator.LIBRARY_TARGET_FOLDER_OUTPUT)
+		locations.addArtifact(flow.module.h, IExecutionFlowGenerator.TARGET_FOLDER_OUTPUT)
+		locations.addArtifact(flow.module.c, IExecutionFlowGenerator.TARGET_FOLDER_OUTPUT)
 		if (flow.timed || !flow.operations.empty || entry.tracingEnterState || entry.tracingExitState) {
-			flow.generateStatemachineRequiredHeader(flow.sourceElement as Statechart, fsa, entry)
+			locations.addArtifact(flow.module.client.h, IExecutionFlowGenerator.TARGET_FOLDER_OUTPUT)
 		}
-		flow.generateStatemachineSource(flow.sourceElement as Statechart, fsa, entry)
+
+		// perform generation
+		flow.generateTypesH(flow.sourceElement as Statechart, sctFsa.IFileSystemAccess, entry)
+		flow.generateStatemachineHeader(flow.sourceElement as Statechart, sctFsa.IFileSystemAccess, entry, locations)
+		if (flow.timed || !flow.operations.empty || entry.tracingEnterState || entry.tracingExitState) {
+			flow.generateStatemachineRequiredHeader(flow.sourceElement as Statechart, sctFsa.IFileSystemAccess, entry)
+		}
+		flow.generateStatemachineSource(flow.sourceElement as Statechart, sctFsa.IFileSystemAccess, entry)
 	}
+	
 }

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

@@ -38,18 +38,18 @@ class StatemachineHeader {
 	@Inject extension INamingService
 
 	
-	def generateStatemachineHeader(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry) {
+	def generateStatemachineHeader(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry, ArtifactLocationProvider locations) {
 		flow.initializeNamingService
-		fsa.generateFile(flow.module.h, flow.generateStatemachineHeaderContents(entry))
+		fsa.generateFile(flow.module.h, flow.generateStatemachineHeaderContents(entry, locations))
 	}
 
-	def generateStatemachineHeaderContents(ExecutionFlow it, GeneratorEntry entry) '''
+	def generateStatemachineHeaderContents(ExecutionFlow it, GeneratorEntry entry, ArtifactLocationProvider locations) '''
 		«entry.licenseText»
 		
 		#ifndef «module.define»_H_
 		#define «module.define»_H_
 		
-		«includes»
+		«includes(locations)»
 				
 		#ifdef __cplusplus
 		extern "C" { 
@@ -110,8 +110,8 @@ class StatemachineHeader {
 		#endif /* «module.define»_H_ */
 	'''
 
-	def includes(ExecutionFlow it) '''
-		#include "«typesModule.h»"
+	def includes(ExecutionFlow it, ArtifactLocationProvider locations) '''
+		#include "«locations.computeRelativeForName(typesModule.h, module.h)»"
 	'''
 	
 	def statesEnumDecl(ExecutionFlow it) '''

+ 2 - 0
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/filesystem/ISCTFileSystemAccess.java

@@ -38,6 +38,8 @@ public interface ISCTFileSystemAccess {
 	 * @return
 	 */
 	URI getURI(String path);
+	
+	URI getURI(String path, String outputName);
 
 	/**
 	 * Add an output path for an output name.