Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
MontiSecArc
Commits
dce17f86
Commit
dce17f86
authored
Oct 26, 2014
by
Paff
Browse files
infrastructure for code generation
parent
a956295b
Changes
22
Hide whitespace changes
Inline
Side-by-side
lang-example/mc.cfg
View file @
dce17f86
/**
* Generated on Sun Oct 26 1
3
:1
7:07
CET 2014
* Generated on Sun Oct 26 1
5
:1
8:46
CET 2014
*/
config {
Require-Model:
...
...
lang-example/src/main/java/secarc/MontiSecArcConstants.java
View file @
dce17f86
...
...
@@ -51,6 +51,16 @@ public final class MontiSecArcConstants extends Interfaces2Constants {
*/
public
static
final
String
FILE_ENDING
=
LANGUAGE_SHORTNAME
;
/**
* Name of the MontiSecArc roots.
*/
public
static
final
String
MONTI_SEC_ARC_ROOT_NAME
=
FILE_ENDING
;
/**
* Default name of the file to configure the MontiSecArc model path.
*/
public
static
final
String
DEFAULT_MONTI_ARC_CONFIG_FILE
=
"ma.cfg"
;
/**
* name for pep entry
*/
...
...
lang-example/src/main/java/secarc/MontiSecArcTool.java
View file @
dce17f86
...
...
@@ -3,6 +3,8 @@
* http://www.monticore.de/ - http://www.se-rwth.de/ */
package
secarc
;
import
java.io.File
;
import
com.google.inject.Guice
;
import
com.google.inject.Injector
;
...
...
@@ -58,4 +60,50 @@ public class MontiSecArcTool extends ETSTool {
setCocoConfiguration
(
MontiSecArcContextConditionCreator
.
createConfig
());
}
/**
* Replaces values of parameters with one value in the given arguments.
*
* @param args arguments to modify
* @param parameter parameter to find
* @param newValue value to set for the given parameter
* @param checkExistence if this is true, it is first checked, if the old
* value exists as a file. If this file exists, the value is NOT
* replaced!
*/
public
static
void
replaceFileParameterValue
(
String
[]
args
,
String
parameter
,
String
newValue
,
boolean
checkExistence
)
{
int
paramPosition
=
-
1
;
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
String
arg
=
args
[
i
];
if
(
arg
.
equals
(
parameter
)
&&
args
.
length
>
(
i
+
1
))
{
paramPosition
=
i
+
1
;
break
;
}
}
if
(
paramPosition
!=
-
1
)
{
boolean
exists
=
false
;
if
(
checkExistence
)
{
File
cfgFile
=
new
File
(
args
[
paramPosition
]);
exists
=
cfgFile
.
exists
();
}
if
(!
exists
)
{
String
newConf
=
args
[
paramPosition
];
int
pos
=
newConf
.
lastIndexOf
(
File
.
separator
);
if
(
pos
==
-
1
)
{
pos
=
newConf
.
lastIndexOf
(
'/'
);
}
if
(
pos
!=
-
1
)
{
newConf
=
newConf
.
substring
(
0
,
pos
+
1
)
+
newValue
;
}
else
{
newConf
=
newValue
;
}
args
[
paramPosition
]
=
newConf
;
}
}
}
}
lang-example/src/main/java/secarc/prettyprint/MontiSecArcInterfacePrinterWorkflow.java
0 → 100644
View file @
dce17f86
package
secarc.prettyprint
;
import
secarc._tool.MontiSecArcRoot
;
import
mc.DSLWorkflow
;
public
class
MontiSecArcInterfacePrinterWorkflow
extends
DSLWorkflow
<
MontiSecArcRoot
>
{
public
MontiSecArcInterfacePrinterWorkflow
()
{
super
(
MontiSecArcRoot
.
class
);
}
@Override
public
void
run
(
MontiSecArcRoot
dslRoot
)
{
//TODO
}
}
montiSecArcAnalysis/mc.cfg
View file @
dce17f86
/**
* Generated on Sun Oct 26 1
3
:1
8:26
CET 2014
* Generated on Sun Oct 26 1
5
:1
9:08
CET 2014
*/
config {
Require-Model:
...
...
montiSecArcBE/src/main/java/secarc/MontiSecArcGeneratorConstants.java
0 → 100644
View file @
dce17f86
package
secarc
;
/**
* Constants for the MontiSecArc generator.
*
* <br>
* <br>
* Copyright (c) 2012 RWTH Aachen. All rights reserved.
*
* @author (last commit) $Author$
* @version $Date$<br>
* $Revision$
*/
public
final
class
MontiSecArcGeneratorConstants
{
/**
* Empty private constructor to prevent constant class instantiation.
*/
private
MontiSecArcGeneratorConstants
()
{
}
/**
* Turn this on to generate protocols.
*/
protected
static
boolean
generateProtocols
=
false
;
/**
* Template name of the MontiSecArc component generator.
*/
public
static
final
String
COMPONENT_GENERATOR
=
"mc.umlp.arc.ComponentMain"
;
/**
* Template name of the MontiSecArc factory generator.
*/
public
static
final
String
FACTORY_GENERATOR
=
"mc.umlp.arc.ComponentFactoryMain"
;
/**
* Template name of the MontiSecArc interface generator.
*/
public
static
final
String
INTERFACE_GENERATOR
=
"mc.umlp.arc.ComponentInterfaceMain"
;
/**
* Contains all default generators.
*/
public
static
final
String
[]
DEFAULT_GENERATORS
=
new
String
[]
{
INTERFACE_GENERATOR
,
FACTORY_GENERATOR
,
COMPONENT_GENERATOR
};
}
montiSecArcBE/src/main/java/secarc/MontiSecArcGeneratorDefaultModule.java
0 → 100644
View file @
dce17f86
package
secarc
;
/**
* Default guice module for MontiSecArc generator.
*
* @author (last commit) $Author$
* @version $Revision$,
* $Date$
*
*/
public
class
MontiSecArcGeneratorDefaultModule
extends
MontiSecArcDefaultModule
{
}
montiSecArcBE/src/main/java/secarc/MontiSecArcGeneratorLanguage.java
0 → 100644
View file @
dce17f86
package
secarc
;
import
static
mc
.
umlp
.
arcd
.
ToolConstants
.
WF_CREATE_SYMTAB
;
import
static
mc
.
umlp
.
arcd
.
ToolConstants
.
WF_INIT_CHECK
;
import
static
mc
.
umlp
.
arcd
.
ToolConstants
.
WF_PARSE
;
import
static
mc
.
umlp
.
arcd
.
ToolConstants
.
WF_PRETTY_PRINT
;
import
static
mc
.
umlp
.
arcd
.
ToolConstants
.
WF_PRE_CHECK_TRAFO
;
import
static
mc
.
umlp
.
arcd
.
ToolConstants
.
WF_PRE_CODEGEN_TRAFO
;
import
secarc._tool.MontiSecArcParsingWorkflow
;
import
secarc._tool.MontiSecArcRoot
;
import
secarc._tool.MontiSecArcRootFactory
;
import
secarc.codegen.transform.PreCodegenTransformationWorkflow
;
import
secarc.ets.transform.PreCoCoCheckMontiSecArcTransformationWorkflow
;
import
secarc.prettyprint.MontiSecArcInterfacePrinterWorkflow
;
import
secarc.prettyprint.MontiSecArcPrettyPrintWorkflow
;
import
com.google.inject.Inject
;
import
interfaces2.language.ILanguage
;
import
interfaces2.workflows.CreateExportedInterfaceWorkflow
;
import
interfaces2.workflows.PrepareCheckWorkflow
;
import
mc.DSLRootFactory
;
import
mc.GenerationLanguage
;
import
mc.IErrorDelegator
;
import
mc.IModelInfrastructureProvider
;
public
class
MontiSecArcGeneratorLanguage
extends
GenerationLanguage
{
/**
* Creates a new {@link MontiArcGeneratorLanguage}.
*/
@Inject
public
MontiSecArcGeneratorLanguage
(
final
ILanguage
component
)
{
super
();
this
.
language
=
component
;
// 1) PARSING-SETUP:
// Set Root-Class (can be called by "arc" on the command line)
dslRootClassForUserNames
.
put
(
MontiSecArcConstants
.
FILE_ENDING
,
MontiSecArcRoot
.
class
);
setRootClass
(
MontiSecArcRoot
.
class
);
// Set file-extension
setFileEnding
(
MontiSecArcConstants
.
FILE_ENDING
);
// 2) WORKFLOWS
// Parse-Workflow (can be called by "parse" on the command line)
addExecutionUnit
(
WF_PARSE
,
new
MontiSecArcParsingWorkflow
());
// Creates exported interface (can be called by "createExported" on the
// command line)
addExecutionUnit
(
WF_CREATE_SYMTAB
,
new
CreateExportedInterfaceWorkflow
<
MontiSecArcRoot
>(
MontiSecArcRoot
.
class
,
this
));
// prepares context checks (can be called by "prepareCheck" on the
// command line)
addExecutionUnit
(
WF_INIT_CHECK
,
new
PrepareCheckWorkflow
<
MontiSecArcRoot
>(
MontiSecArcRoot
.
class
,
this
));
// Transformation-Workflow before coco checks (can be called by
// "preCheckTransformation" on the command line)
addExecutionUnit
(
WF_PRE_CHECK_TRAFO
,
new
PreCoCoCheckMontiSecArcTransformationWorkflow
<
MontiSecArcRoot
>(
MontiSecArcRoot
.
class
));
// Transformation-Workflow after coco checks but before code generation
// (can be called by "preCodegenTransformation" on the command line)
addExecutionUnit
(
WF_PRE_CODEGEN_TRAFO
,
new
PreCodegenTransformationWorkflow
<
MontiSecArcRoot
>(
MontiSecArcRoot
.
class
));
// PrettyPrinter (can be called by "print" on the command line)
addExecutionUnit
(
WF_PRETTY_PRINT
,
new
MontiSecArcPrettyPrintWorkflow
(
MontiSecArcRoot
.
class
));
// InterfacePrinter (can be called by "printInterface" on the command
// line)
addExecutionUnit
(
"printInterface"
,
new
MontiSecArcInterfacePrinterWorkflow
());
}
/*
* (non-Javadoc)
* @see mc.GenerationLanguage#getConstant(java.lang.String)
*/
@Override
public
String
getConstant
(
String
key
)
{
return
MontiSecArcConstants
.
get
(
key
);
}
/*
* (non-Javadoc)
* @see interfaces2.language.ModelingLanguage#getRootFactory(mc.
* IModelInfrastructureProvider, mc.IErrorDelegator, java.lang.String)
*/
@Override
public
DSLRootFactory
<?>
getRootFactory
(
IModelInfrastructureProvider
infrastructureprovider
,
IErrorDelegator
errorHandler
,
String
encoding
)
{
return
new
MontiSecArcRootFactory
(
infrastructureprovider
,
errorHandler
,
encoding
);
}
/*
* (non-Javadoc)
* @see interfaces2.language.ModelingLanguage#initILanguage()
*/
@Override
protected
ILanguage
initILanguage
()
{
return
null
;
}
}
montiSecArcBE/src/main/java/secarc/MontiSecArcGeneratorTool.java
0 → 100644
View file @
dce17f86
package
secarc
;
import
secarc.ets.check.MontiSecArcContextConditionCreator
;
import
interfaces2.language.LanguageFamily
;
import
com.google.inject.AbstractModule
;
import
com.google.inject.Guice
;
import
com.google.inject.Injector
;
import
mc.GenerationTool
;
import
mc.GenerationToolParameters
;
import
mc.MCG
;
import
mc.Parameters
;
import
mc.umlp.arc.MontiArcConstants
;
import
mc.umlp.arc.MontiArcTool
;
import
mc.umlp.arcd.InjectorProvider
;
import
mc.umlp.arcd.ToolConstants
;
/**
* MontiSecArc tool that is able to generate simulation components. <br>
* <br>
* Copyright (c) 2012 RWTH Aachen. All rights reserved.
*
* @author (last commit) $Author$
* @version $Date$<br>
* $Revision$
*/
public
class
MontiSecArcGeneratorTool
extends
GenerationTool
{
public
MontiSecArcGeneratorTool
(
final
String
[]
args
)
{
this
(
args
,
new
MontiSecArcGeneratorDefaultModule
());
}
/**
* @param args tool parameters
*/
public
MontiSecArcGeneratorTool
(
final
String
[]
args
,
AbstractModule
bindings
)
{
super
(
args
);
// Define tool components
Injector
injector
=
Guice
.
createInjector
(
bindings
);
InjectorProvider
.
setInjector
(
injector
);
LanguageFamily
languageFamily
=
injector
.
getInstance
(
LanguageFamily
.
class
);
setLanguages
(
languageFamily
);
setCocoConfiguration
(
MontiSecArcContextConditionCreator
.
createConfig
());
init
();
initGraphLogger
();
}
/**
* Initializes and registers a {@link GMLLogger}, if protocol is enabled.
*/
private
void
initGraphLogger
()
{
}
/* (non-Javadoc)
*
* @see interfaces2.language.ETSTool#initParameters(java.lang.String[]) */
@Override
protected
void
initParameters
(
String
[]
args
)
{
if
(
args
!=
null
)
{
String
[]
passedArgs
=
MontiArcTool
.
addStandardParameters
(
args
);
MontiSecArcTool
.
replaceFileParameterValue
(
passedArgs
,
ToolConstants
.
ARG_CONF
,
MontiArcConstants
.
DEFAULT_MONTI_ARC_CONFIG_FILE
,
true
);
super
.
initParameters
(
passedArgs
);
// generate Log?
if
(
parameters
.
getOptionParameter
(
ToolConstants
.
PARAM_GENLOG
)
!=
null
)
{
MCG
.
getLogger
().
info
(
"Protocol enanbled"
);
MontiSecArcGeneratorConstants
.
generateProtocols
=
true
;
}
}
}
@Override
protected
void
initGenerator
()
{
// default cfg file
if
(
parameters
.
getModelPathConfigFile
()
==
null
)
{
parameters
.
setModelPathConfigFile
(
parameters
.
getBaseDir
()
+
"/"
+
MontiSecArcConstants
.
DEFAULT_MONTI_ARC_CONFIG_FILE
);
}
// default execution units
if
(
parameters
.
getAnalyses
().
isEmpty
()
&&
parameters
.
getSyntheses
().
isEmpty
())
{
parameters
.
addAnalysis
(
Parameters
.
ALL
,
ToolConstants
.
WF_PARSE
);
parameters
.
addAnalysis
(
ToolConstants
.
ROOT_NAME_JAVA
,
"setname"
);
parameters
.
addAnalysis
(
ToolConstants
.
ROOT_NAME_JAVA
,
"addImports"
);
parameters
.
addAnalysis
(
Parameters
.
ALL
,
ToolConstants
.
WF_INIT_SYMTAB
);
parameters
.
addAnalysis
(
Parameters
.
ALL
,
ToolConstants
.
WF_CREATE_SYMTAB
);
parameters
.
addSynthesis
(
Parameters
.
ALL
,
ToolConstants
.
WF_INIT_CHECK
);
parameters
.
addSynthesis
(
MontiSecArcConstants
.
MONTI_SEC_ARC_ROOT_NAME
,
ToolConstants
.
WF_PRE_CHECK_TRAFO
);
parameters
.
addSynthesis
(
MontiSecArcConstants
.
MONTI_SEC_ARC_ROOT_NAME
,
ToolConstants
.
WF_RUN_CHECK
);
parameters
.
addSynthesis
(
MontiSecArcConstants
.
MONTI_SEC_ARC_ROOT_NAME
,
ToolConstants
.
WF_PRE_CODEGEN_TRAFO
);
}
// generator parameters
if
(
parameters
.
getOptionParameter
(
GenerationToolParameters
.
GENERATOR
.
toString
())
==
null
)
{
for
(
String
generator
:
MontiSecArcGeneratorConstants
.
DEFAULT_GENERATORS
)
{
parameters
.
addOptionParameter
(
GenerationToolParameters
.
GENERATOR
.
toString
(),
new
String
[]
{
generator
,
"MontiSecArcComponent"
});
}
}
super
.
initGenerator
();
}
/* (non-Javadoc)
*
* @see mc.DSLTool#printHelpMessage() */
@Override
protected
void
printHelpMessage
()
{
getErrorDelegator
().
addInfo
(
"MontiSecArcGeneratorTool "
);
getErrorDelegator
().
addInfo
(
"-----------------------------------------------------------------------------"
);
getErrorDelegator
().
addInfo
(
"Specify MontiSecArc input files as command line arguments"
);
}
/**
* Runs the MontiArc generator tool.
*
* @param args the command line parameters
*/
public
static
void
main
(
String
[]
args
)
{
// Init MontiCoreGlobals
MCG
.
initMonticoreGlobals
();
// MontiArcGeneratorTool
MontiSecArcGeneratorTool
tool
=
new
MontiSecArcGeneratorTool
(
args
);
// setup CoCos
tool
.
setCocoConfiguration
(
MontiSecArcContextConditionCreator
.
createConfig
());
// Init tool-infrastructure
tool
.
init
();
// run
tool
.
run
();
}
}
montiSecArcBE/src/main/java/secarc/codegen/transform/PreCodegenTransformationWorkflow.java
0 → 100644
View file @
dce17f86
package
secarc.codegen.transform
;
import
mc.DSLRoot
;
import
mc.DSLWorkflow
;
import
mc.umlp.arc._ast.ASTMCCompilationUnit
;
/**
*
* Workflow for transformations that are applied before code generation.
*
* <br>
* <br>
* Copyright (c) 2011 RWTH Aachen. All rights reserved.
*
* @author (last commit) $Author$
* @version $Date$<br>
* $Revision$
* @param <T> dsl root type
*/
public
class
PreCodegenTransformationWorkflow
<
T
extends
DSLRoot
<?
extends
ASTMCCompilationUnit
>>
extends
DSLWorkflow
<
T
>
{
/**
* @param responsibleClass responsible dsl root class
*/
public
PreCodegenTransformationWorkflow
(
Class
<
T
>
responsibleClass
)
{
super
(
responsibleClass
);
// TODO Auto-generated constructor stub
}
/*
* (non-Javadoc)
* @see mc.DSLWorkflow#run(mc.DSLRoot)
*/
@Override
public
void
run
(
T
arg0
)
{
// TODO Auto-generated method stub
}
}
montiSecArcBE/target/classes/META-INF/MANIFEST.MF
0 → 100644
View file @
dce17f86
Manifest-Version: 1.0
Built-By: user
Build-Jdk: 1.7.0_67
Created-By: Maven Integration for Eclipse
montiSecArcBE/target/classes/META-INF/maven/de.se.rwth.secarc.lang/montiSecArcBE/pom.properties
0 → 100644
View file @
dce17f86
#Generated by Maven Integration for Eclipse
#Sun Oct 26 15:20:33 CET 2014
version
=
0.0.1-SNAPSHOT
groupId
=
de.se.rwth.secarc.lang
m2e.projectName
=
montiSecArcBE
m2e.projectLocation
=
/home/user/workspace/MA-Paff/03.Implementierung/montiSecArcBE
artifactId
=
montiSecArcBE
montiSecArcBE/target/classes/META-INF/maven/de.se.rwth.secarc.lang/montiSecArcBE/pom.xml
0 → 100644
View file @
dce17f86
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<!-- == PROJECT COORDINATES ============================================= -->
<parent>
<groupId>
de.se.rwth.secarc.lang
</groupId>
<artifactId>
build
</artifactId>
<!-- <version>1.5.1</version> -->
<version>
0.0.1-SNAPSHOT
</version>
<relativePath>
../build
</relativePath>
</parent>
<artifactId>
montiSecArcBE
</artifactId>
<dependencies>
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
</dependency>
<dependency>
<groupId>
net.sourceforge.plantuml
</groupId>
<artifactId>
plantuml
</artifactId>
<version>
7942
</version>
</dependency>
<dependency>
<groupId>
de.se.rwth.secarc.lang
</groupId>
<artifactId>
montiSecArc-lang
</artifactId>
<version>
${project.version}
</version>
</dependency>
<!-- TEST DEPENDENCIES -->
<dependency>
<groupId>
de.monticore
</groupId>
<artifactId>
de.monticore.java.lib
</artifactId>
<classifier>
symbols
</classifier>
<version>
3.2.0-38
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
de.monticore.lang.montiarc
</groupId>
<artifactId>
de.arcd.fe
</artifactId>
<classifier>
tests
</classifier>
<scope>
test
</scope>
<version>
${montiarc.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-io
</artifactId>
<scope>
test
</scope>
<version>
2.3
</version>
</dependency>
<dependency>
<groupId>
ch.qos.logback
</groupId>
<artifactId>
logback-classic
</artifactId>
<scope>
test
</scope>
<version>
1.0.7
</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Run MontiCore -->
<plugin>
<groupId>
de.monticore.maven
</groupId>
<artifactId>
monticore-maven-plugin
</artifactId>
</plugin>
<!-- Source Jar -->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-source-plugin
</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
montiSecArcBE/target/classes/secarc/MontiSecArcGeneratorConstants.class
0 → 100644
View file @
dce17f86
File added
montiSecArcBE/target/classes/secarc/MontiSecArcGeneratorDefaultModule.class
0 → 100644
View file @
dce17f86
File added
montiSecArcBE/target/classes/secarc/MontiSecArcGeneratorLanguage.class
0 → 100644
View file @
dce17f86
File added
montiSecArcBE/target/classes/secarc/MontiSecArcGeneratorTool.class
0 → 100644
View file @
dce17f86
File added
montiSecArcBE/target/classes/secarc/codegen/transform/PreCodegenTransformationWorkflow.class
0 → 100644
View file @
dce17f86
File added
montiSecArcBE/target/maven-archiver/pom.properties
View file @
dce17f86
#Generated by Maven
#Sun Oct 26 1
3
:1
8:5
2 CET 2014
#Sun Oct 26 1
5
:1
9:1
2 CET 2014
version
=
0.0.1-SNAPSHOT
groupId
=
de.se.rwth.secarc.lang
artifactId
=
montiSecArcBE
montiSecArcBE/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
0 → 100644
View file @
dce17f86