Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
af3
AF3
Commits
ac37e3eb
Commit
ac37e3eb
authored
May 24, 2012
by
Florian Hölzl
Browse files
data_dictionary generation finished
refs 121
parent
3e1d9ef2
Changes
10
Hide whitespace changes
Inline
Side-by-side
org.fortiss.af3.expression/trunk/src/org/fortiss/af3/expression/generator/c/DataDictionaryGenerator.java
View file @
ac37e3eb
...
...
@@ -41,6 +41,7 @@ import org.fortiss.af3.generator.common.model.oldsource.DeclarationBase;
* The generator for {@link DataDictionary}. It produces two files: <code>data_dictionary.h</code>
* and <code>data_dictionary.c</code>;
*
* @deprecated
* @author hoelzl
* @author $Author$
* @version $Rev$
...
...
org.fortiss.af3.expression/trunk/src/org/fortiss/af3/expression/generator/c/EnumGenerator.java
View file @
ac37e3eb
...
...
@@ -37,6 +37,7 @@ import org.fortiss.af3.project.model.typesystem.IType;
/**
* C enumeration type generator.
*
* @deprecated
* @author hoelzl
* @author $Author$
* @version $Rev$
...
...
@@ -59,9 +60,8 @@ public class EnumGenerator {
@Override
public
String
toString
()
{
return
"enum "
+
TYPE_STRING_GENERATOR
.
getTypeString
(
definedType
(
enumeration
.
getName
()))
+
';'
;
TYPE_STRING_GENERATOR
.
getTypeString
(
definedType
(
enumeration
.
getName
()))
+
';'
;
}
};
}
...
...
@@ -83,23 +83,20 @@ public class EnumGenerator {
IType
enumType
=
definedType
(
enumeration
.
getName
());
StringBuffer
buf
=
new
StringBuffer
();
buf
.
append
(
"typedef enum Enum_"
)
.
append
(
TYPE_STRING_GENERATOR
.
getTypeString
(
enumType
))
.
append
(
"{\n"
);
.
append
(
TYPE_STRING_GENERATOR
.
getTypeString
(
enumType
)).
append
(
"{\n"
);
for
(
int
i
=
0
;
i
<
enumeration
.
getMembersLength
();
i
++)
{
if
(
i
>
0
)
{
buf
.
append
(
",\n"
);
}
EnumerationMember
mem
=
enumeration
.
getMembers
(
i
);
buf
.
append
(
mem
.
getName
()).
append
(
"_ID"
).
append
(
mem
.
getId
())
.
append
(
" = "
)
.
append
(
i
).
append
(
"\n"
);
buf
.
append
(
mem
.
getName
()).
append
(
"_ID"
).
append
(
mem
.
getId
())
.
append
(
" = "
)
.
append
(
i
).
append
(
"\n"
);
}
buf
.
append
(
"#ifdef USE_GCC\n"
);
buf
.
append
(
"} __attribute__ ((packed)) "
)
.
append
(
TYPE_STRING_GENERATOR
.
getTypeString
(
enumType
))
.
append
(
";\n"
);
.
append
(
TYPE_STRING_GENERATOR
.
getTypeString
(
enumType
)).
append
(
";\n"
);
buf
.
append
(
"#else\n"
);
buf
.
append
(
"} "
)
.
append
(
TYPE_STRING_GENERATOR
.
getTypeString
(
enumType
))
buf
.
append
(
"} "
).
append
(
TYPE_STRING_GENERATOR
.
getTypeString
(
enumType
))
.
append
(
";\n"
);
buf
.
append
(
"#endif\n"
);
buf
.
append
(
"\n"
);
...
...
@@ -112,8 +109,7 @@ public class EnumGenerator {
private
Function
createEnumMemberConstructor
(
EnumerationMember
member
)
{
IType
resultType
=
definedType
(
member
.
getEnumeration
().
getName
());
String
enumName
=
member
.
getName
()
+
"_ID"
+
member
.
getId
();
return
new
Function
(
EXTERN
,
resultType
,
member
.
getName
(),
EMPTY_LIST
,
EMPTY_LIST
,
sequence
(
returns
(
definedConst
(
enumName
))),
TYPE_STRING_GENERATOR
);
return
new
Function
(
EXTERN
,
resultType
,
member
.
getName
(),
EMPTY_LIST
,
EMPTY_LIST
,
sequence
(
returns
(
definedConst
(
enumName
))),
TYPE_STRING_GENERATOR
);
}
}
org.fortiss.af3.expression/trunk/src/org/fortiss/af3/expression/generator/c/ProgramTransformation.java
View file @
ac37e3eb
...
...
@@ -23,6 +23,7 @@ import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFactor
import
static
org
.
fortiss
.
af3
.
generator
.
common
.
utils
.
CLanguageModelElementFactory
.
createCFunctionDefinition
;
import
static
org
.
fortiss
.
af3
.
generator
.
common
.
utils
.
CLanguageModelElementFactory
.
createCSourcePackage
;
import
static
org
.
fortiss
.
af3
.
generator
.
common
.
utils
.
CLanguageModelElementFactory
.
createCVariable
;
import
static
org
.
fortiss
.
af3
.
generator
.
common
.
utils
.
CLanguageModelElementFactory
.
createGeneratedHeaderInclude
;
import
static
org
.
fortiss
.
af3
.
generator
.
common
.
utils
.
CLanguageModelElementFactory
.
createHeaderFile
;
import
static
org
.
fortiss
.
af3
.
generator
.
common
.
utils
.
CLanguageModelElementFactory
.
createImplementationFile
;
import
static
org
.
fortiss
.
af3
.
generator
.
common
.
utils
.
CLanguageModelElementFactory
.
createInclude
;
...
...
@@ -48,7 +49,6 @@ import org.fortiss.af3.generator.common.model.c.types.CEnumerationMember;
import
org.fortiss.af3.generator.common.model.source.SourcePackage
;
import
org.fortiss.tooling.kernel.extension.ITransformationProvider
;
import
org.fortiss.tooling.kernel.extension.data.ITransformationContext
;
import
org.fortiss.tooling.kernel.extension.exception.TransformationFailedException
;
/**
* An {@link ITransformationProvider} for the transformation of {@link Program} into a C
...
...
@@ -83,8 +83,7 @@ public class ProgramTransformation implements ITransformationProvider {
/** {@inheritDoc} */
@Override
public
Object
transform
(
Object
source
,
ITransformationContext
context
)
throws
TransformationFailedException
{
public
Object
transform
(
Object
source
,
ITransformationContext
context
)
{
Program
p
=
(
Program
)
source
;
CSourcePackage
pack
=
createCSourcePackage
();
Map
<
ProgramFunction
,
CFunctionDeclaration
>
functionMap
=
prepareProgramFunctions
(
p
);
...
...
@@ -107,7 +106,6 @@ public class ProgramTransformation implements ITransformationProvider {
def
.
getParametersList
().
add
(
cVar
);
}
CFunctionDeclaration
decl
=
createCFunctionDeclaration
(
mod
,
def
);
decl
.
setDefinition
(
def
);
functionMap
.
put
(
fun
,
decl
);
}
return
functionMap
;
...
...
@@ -123,7 +121,7 @@ public class ProgramTransformation implements ITransformationProvider {
for
(
ProgramFunction
fun
:
p
.
getFunctionsList
())
{
implFile
.
getDefinitionsList
().
add
(
functionMap
.
get
(
fun
).
getDefinition
());
}
implFile
.
getImportsList
().
add
(
createInclude
(
p
.
getName
()
,
false
));
implFile
.
getImportsList
().
add
(
create
GeneratedHeader
Include
(
p
.
getName
()));
return
implFile
;
}
...
...
org.fortiss.af3.expression/trunk/src/org/fortiss/af3/expression/generator/c/Types.java
View file @
ac37e3eb
...
...
@@ -29,11 +29,12 @@ import org.fortiss.af3.generator.common.model.oldc.VoidType;
import
org.fortiss.af3.project.model.typesystem.IType
;
/**
* Utility class for C type generator. The singleton is passed to
* {@link
Variable} and {@link
Function} (which are below this class in the
* Utility class for C type generator. The singleton is passed to
{@link Variable} and
* {@link Function} (which are below this class in the
* plugin dependencies) in order to ensure the types are correctly turned into
* strings.
*
* @deprecated
* @author hoelzl
* @author $Author$
* @version $Rev$
...
...
@@ -47,23 +48,23 @@ public class Types implements ITypeStringGenerator {
/** {@inheritDoc} */
@Override
public
String
getTypeString
(
IType
t
)
{
if
(
t
==
null
||
t
instanceof
VoidType
)
{
if
(
t
==
null
||
t
instanceof
VoidType
)
{
return
"void"
;
}
if
(
t
instanceof
BaseType
)
{
if
(
t
instanceof
BaseType
)
{
return
t
.
toString
();
}
if
(
t
instanceof
TInt
)
{
if
(
t
instanceof
TInt
)
{
return
"TYPE_int"
;
}
if
(
t
instanceof
TBool
)
{
if
(
t
instanceof
TBool
)
{
return
"TYPE_boolean"
;
}
if
(
t
instanceof
TDouble
)
{
if
(
t
instanceof
TDouble
)
{
return
"TYPE_double"
;
}
if
(
t
instanceof
TDefinedType
)
{
return
"TYPE_"
+
((
TDefinedType
)
t
).
getName
();
if
(
t
instanceof
TDefinedType
)
{
return
"TYPE_"
+
((
TDefinedType
)
t
).
getName
();
}
return
t
.
toString
();
}
...
...
org.fortiss.af3.generator.common/trunk/model/languages.ecore
View file @
ac37e3eb
...
...
@@ -184,6 +184,11 @@
containment=
"true"
/>
</eClassifiers>
<eClassifiers
xsi:type=
"ecore:EClass"
name=
"CVariable"
eSuperTypes=
"platform:/plugin/org.fortiss.tooling.kernel/model/kernel.ecore#//INamedElement"
>
<eOperations
name=
"toString"
eType=
"ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
>
<eAnnotations
source=
"http://www.eclipse.org/emf/2002/GenModel"
>
<details
key=
"body"
value=
"return org.fortiss.af3.generator.common.textgen.c.CLanguageConstructTextGenerator.variableDefinitionToString(this);"
/>
</eAnnotations>
</eOperations>
<eStructuralFeatures
xsi:type=
"ecore:EReference"
name=
"type"
eType=
"ecore:EClass ../../org.fortiss.af3.project/model/project.ecore#//typesystem/IType"
containment=
"true"
/>
</eClassifiers>
...
...
org.fortiss.af3.generator.common/trunk/model/languages.genmodel
View file @
ac37e3eb
...
...
@@ -92,6 +92,7 @@
</genClasses>
<genClasses
ecoreClass=
"languages.ecore#//c/CVariable"
>
<genFeatures
property=
"None"
children=
"true"
createChild=
"true"
ecoreFeature=
"ecore:EReference languages.ecore#//c/CVariable/type"
/>
<genOperations
ecoreOperation=
"languages.ecore#//c/CVariable/toString"
/>
</genClasses>
<nestedGenPackages
prefix=
"Types"
basePackage=
"org.fortiss.af3.generator.common.model.c"
disposableProviderFactory=
"true"
ecorePackage=
"languages.ecore#//c/types"
>
...
...
org.fortiss.af3.generator.common/trunk/src/org/fortiss/af3/generator/common/textgen/c/CLanguageConstructTextGenerator.java
View file @
ac37e3eb
...
...
@@ -20,6 +20,7 @@ package org.fortiss.af3.generator.common.textgen.c;
import
static
org
.
fortiss
.
af3
.
generator
.
common
.
model
.
c
.
CModifier
.
EXTERN
;
import
static
org
.
fortiss
.
af3
.
generator
.
common
.
model
.
c
.
CModifier
.
NONE
;
import
static
org
.
fortiss
.
af3
.
generator
.
common
.
model
.
c
.
CModifier
.
STATIC
;
import
static
org
.
fortiss
.
af3
.
generator
.
common
.
textgen
.
c
.
CLanguageTypesTextGenerator
.
typeToString
;
import
org.fortiss.af3.generator.common.model.c.CFunctionDeclaration
;
import
org.fortiss.af3.generator.common.model.c.CFunctionDefinition
;
...
...
@@ -58,22 +59,9 @@ public class CLanguageConstructTextGenerator {
*/
public
static
String
functionDeclarationToString
(
CFunctionDeclaration
decl
)
{
StringBuffer
buf
=
new
StringBuffer
();
buf
.
append
(
modifierToString
(
decl
.
getModifier
())).
append
(
' '
);
CFunctionDefinition
def
=
decl
.
getDefinition
();
buf
.
append
(
def
.
getReturnType
().
toString
()).
append
(
' '
);
buf
.
append
(
def
.
getName
()).
append
(
' '
);
buf
.
append
(
'('
);
boolean
first
=
true
;
for
(
CVariable
param
:
def
.
getParametersList
())
{
if
(!
first
)
{
buf
.
append
(
','
);
}
else
{
first
=
false
;
}
buf
.
append
(
param
.
toString
());
}
buf
.
append
(
");\n"
);
return
null
;
buf
.
append
(
functionSignatureToString
(
decl
.
getDefinition
(),
decl
.
getModifier
()));
buf
.
append
(
";\n"
);
return
buf
.
toString
();
}
/**
...
...
@@ -101,9 +89,8 @@ public class CLanguageConstructTextGenerator {
* @return the textual representation
*/
public
static
String
variableDeclarationToString
(
CVariableDeclaration
decl
)
{
return
modifierToString
(
decl
.
getModifier
())
+
' '
+
decl
.
getVariable
().
getType
().
toString
()
+
' '
+
decl
.
getVariable
().
getName
()
+
";\n"
;
return
modifierToString
(
decl
.
getModifier
())
+
typeToString
(
decl
.
getVariable
().
getType
())
+
decl
.
getVariable
().
getName
()
+
";\n"
;
}
/**
...
...
@@ -119,9 +106,20 @@ public class CLanguageConstructTextGenerator {
if
(
EXTERN
.
equals
(
mod
))
{
mod
=
NONE
;
}
buf
.
append
(
functionSignatureToString
(
def
,
mod
));
buf
.
append
(
"{\n"
);
buf
.
append
(
def
.
getBody
().
toString
());
buf
.
append
(
"}\n"
);
return
buf
.
toString
();
}
/** Creates the text for the function signature. */
private
static
String
functionSignatureToString
(
CFunctionDefinition
def
,
CModifier
mod
)
{
StringBuffer
buf
=
new
StringBuffer
();
buf
.
append
(
modifierToString
(
mod
));
buf
.
append
(
def
.
getReturnType
()
.
toString
()).
append
(
' '
);
buf
.
append
(
def
.
getName
())
.
append
(
' '
)
;
buf
.
append
(
typeToString
(
def
.
getReturnType
()
)
);
buf
.
append
(
def
.
getName
());
buf
.
append
(
'('
);
boolean
first
=
true
;
for
(
CVariable
param
:
def
.
getParametersList
())
{
...
...
@@ -132,10 +130,18 @@ public class CLanguageConstructTextGenerator {
}
buf
.
append
(
param
.
toString
());
}
buf
.
append
(
") {\n"
);
buf
.
append
(
def
.
getBody
().
toString
());
buf
.
append
(
"}\n"
);
return
null
;
buf
.
append
(
")"
);
return
buf
.
toString
();
}
/**
* Creates the text for the given variable definition.
*
* @param cVar
* the C variable
* @return the textual representation
*/
public
static
String
variableDefinitionToString
(
CVariable
cVar
)
{
return
typeToString
(
cVar
.
getType
())
+
cVar
.
getName
();
}
}
org.fortiss.af3.generator.common/trunk/src/org/fortiss/af3/generator/common/textgen/c/CLanguageTypesTextGenerator.java
View file @
ac37e3eb
...
...
@@ -19,6 +19,7 @@ package org.fortiss.af3.generator.common.textgen.c;
import
org.fortiss.af3.generator.common.model.c.types.CEnumerationDeclaration
;
import
org.fortiss.af3.generator.common.model.c.types.CEnumerationMember
;
import
org.fortiss.af3.project.model.typesystem.IType
;
/**
* Text generator for C language types.
...
...
@@ -29,6 +30,22 @@ import org.fortiss.af3.generator.common.model.c.types.CEnumerationMember;
* @ConQAT.Rating RED Hash:
*/
public
class
CLanguageTypesTextGenerator
{
/** The prefix used for generated C types. */
private
static
final
String
C_TYPE_PREFIX
=
"GEN_TYPE_"
;
/**
* Creates the text for the given type.
*
* @param type
* the type
* @return the textual representation of the declaration
*/
public
static
String
typeToString
(
IType
type
)
{
if
(
type
==
null
)
{
return
"void "
;
}
return
C_TYPE_PREFIX
+
type
.
toString
()
+
' '
;
}
/** Creates the C enumeration type declaration text. */
public
static
String
enumerationToString
(
CEnumerationDeclaration
cenum
)
{
...
...
@@ -42,9 +59,10 @@ public class CLanguageTypesTextGenerator {
buf
.
append
(
mem
.
getName
()).
append
(
" = "
).
append
(
mem
.
getValue
()).
append
(
"\n"
);
}
buf
.
append
(
"#ifdef USE_GCC\n"
);
buf
.
append
(
"} __attribute__ ((packed)) TYPE_"
).
append
(
cenum
.
getName
()).
append
(
";\n"
);
buf
.
append
(
"} __attribute__ ((packed)) "
).
append
(
C_TYPE_PREFIX
).
append
(
cenum
.
getName
())
.
append
(
";\n"
);
buf
.
append
(
"#else\n"
);
buf
.
append
(
"}
TYPE_"
).
append
(
cenum
.
getName
()).
append
(
";\n"
);
buf
.
append
(
"}
"
).
append
(
C_TYPE_PREFIX
).
append
(
cenum
.
getName
()).
append
(
";\n"
);
buf
.
append
(
"#endif\n"
);
buf
.
append
(
"\n"
);
return
buf
.
toString
();
...
...
org.fortiss.af3.generator.common/trunk/src/org/fortiss/af3/generator/common/utils/CLanguageModelElementFactory.java
View file @
ac37e3eb
...
...
@@ -155,6 +155,14 @@ public class CLanguageModelElementFactory {
return
inc
;
}
/**
* Creates an include statement for the given header reference in
* {@link #INC_GEN_SOURCE_PACKAGE}.
*/
public
static
CInclude
createGeneratedHeaderInclude
(
String
headerRef
)
{
return
createInclude
(
INC_GEN_SOURCE_PACKAGE
+
'/'
+
headerRef
,
false
);
}
/** Creates a {@link CVariable} with the given name and type. */
public
static
CVariable
createCVariable
(
String
name
,
IType
type
)
{
CVariable
cvar
=
AF3GeneratorCommonLanguagesCFactory
.
eINSTANCE
.
createCVariable
();
...
...
org.fortiss.af3.generator.common/trunk/src/org/fortiss/af3/generator/common/utils/SourceUtils.java
View file @
ac37e3eb
...
...
@@ -17,11 +17,11 @@ $Id$
+--------------------------------------------------------------------------*/
package
org.fortiss.af3.generator.common.utils
;
import
static
org
.
eclipse
.
emf
.
ecore
.
util
.
EcoreUtil
.
copy
;
import
java.io.File
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.fortiss.af3.generator.common.model.source.FormattedSourceUnit
;
import
org.fortiss.af3.generator.common.model.source.SourcePackage
;
...
...
@@ -116,7 +116,8 @@ public class SourceUtils {
}
/**
* Merges the given source package into the given target package.
* Merges the given source package into the given target package. Note that the source units and
* packages are moved not copied.
*
* @param toBeMerged
* the package to be merged into the other package
...
...
@@ -124,16 +125,21 @@ public class SourceUtils {
* the target package to be extended by the former package's content
*/
public
static
void
mergeSourcePackageInto
(
SourcePackage
toBeMerged
,
SourcePackage
target
)
{
for
(
SourceUnit
unit
:
toBeMerged
.
getUnitsList
())
{
target
.
getUnitsList
().
add
(
copy
(
unit
));
}
List
<
SourcePackage
>
toBeMoved
=
new
ArrayList
<
SourcePackage
>();
for
(
SourcePackage
s
:
toBeMerged
.
getSubPackagesList
())
{
SourcePackage
t
=
target
.
getSubPackage
(
s
.
getBaseLocation
());
if
(
t
==
null
)
{
t
arget
.
getSubPackagesList
().
add
(
copy
(
s
)
);
t
oBeMoved
.
add
(
target
);
}
else
{
mergeSourcePackageInto
(
s
,
t
);
}
}
for
(
SourcePackage
p
:
toBeMoved
)
{
target
.
getSubPackagesList
().
add
(
p
);
}
while
(
toBeMerged
.
getUnitsLength
()
>
0
)
{
SourceUnit
unit
=
toBeMerged
.
getUnitsList
().
remove
(
0
);
target
.
getUnitsList
().
add
(
unit
);
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment