blob: 1854398b922eb2c6c83428e0d3bf8561455129f5 [file] [log] [blame]
/**
********************************************************************************
* Copyright (c) 2020-2021 Robert Bosch GmbH.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Robert Bosch GmbH - initial API and implementation
* *******************************************************************************
*/
package org.eclipse.app4mc.slg.ros2.transformers.sw;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.app4mc.slg.commons.m2t.generators.RunnableTranslationUnit;
import org.eclipse.app4mc.slg.commons.m2t.generators.TranslationUnit;
import org.eclipse.app4mc.slg.commons.m2t.transformers.sw.RunnableTransformer;
import org.eclipse.app4mc.slg.ros2.generators.RosRunnableGenerator;
import org.eclipse.app4mc.slg.ros2.generators.RosRunnableTranslationUnit;
import org.eclipse.app4mc.transformation.util.OutputBuffer;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import com.google.inject.Inject;
public class RosRunnableTransformer extends RunnableTransformer {
@Inject private OutputBuffer outputBuffer;
@Inject private RosActivityGraphItemTransformer psCallGraphItemTransformer;
private final HashMap<ArrayList<?>, RunnableTranslationUnit> cache = CollectionLiterals.newHashMap();
@Override
public RunnableTranslationUnit transform(final org.eclipse.app4mc.amalthea.model.Runnable runnable) {
final ArrayList<?> key = CollectionLiterals.newArrayList(runnable);
final RosRunnableTranslationUnit _result;
synchronized (cache) {
if (cache.containsKey(key)) {
return cache.get(key);
}
RosRunnableTranslationUnit tu = new RosRunnableTranslationUnit(this.outputBuffer,
this.psCallGraphItemTransformer, runnable);
_result = tu;
cache.put(key, _result);
}
_init_transform(_result, runnable);
return _result;
}
private void _init_transform(final RosRunnableTranslationUnit it,
final org.eclipse.app4mc.amalthea.model.Runnable runnable) {
}
@Override
public Map<ArrayList<?>, ? extends TranslationUnit> getCache() {
return this.cache;
}
@Override
public boolean createCMake() {
return outputBuffer.appendTo(
"OTHER",
RosRunnableTranslationUnit.getMakeFilePathStatic(),
RosRunnableGenerator.toCMake(RosRunnableTranslationUnit.getLibName(), getSrcFiles()));
}
}