Changed grammar and added code generator

* changed the grammar to ease code generation
* added a code generator and a standalone setup to generate SystemC code
using SC-Components lib
This commit is contained in:
2017-09-19 18:08:17 +02:00
parent 2d55eac2b9
commit cc2891cb8c
68 changed files with 20392 additions and 13870 deletions

View File

@ -4,23 +4,19 @@ import org.eclipse.emf.ecore.EObject
import org.eclipse.xtext.ui.editor.hover.html.DefaultEObjectHoverProvider
import com.minres.rdl.rdl.ComponentDefinition
import com.minres.rdl.rdl.ComponentInstance
import com.minres.rdl.rdl.ImmediateInstantiation
import com.minres.rdl.rdl.NamedInstantiation
import com.minres.rdl.rdl.Instantiation
class RDLEObjectHoverProvider extends DefaultEObjectHoverProvider {
override protected String getFirstLine(EObject o) {
switch(o){
ComponentDefinition: return 'Component '+o.name+' of type '+o.type.literal
ComponentInstance: {
val parent = o.eContainer
if (parent instanceof ImmediateInstantiation) {
val compDef = parent.eContainer as ComponentDefinition
return compDef.type.literal+' '+o.name
} else if (parent instanceof NamedInstantiation) {
return parent.component.type.literal+' '+o.name
}
}
}
return super.getFirstLine(o)
}
override protected String getFirstLine(EObject o) {
switch(o){
ComponentDefinition: return 'Component '+o.name+' of type '+o.type.literal
ComponentInstance: {
val parent = o.eContainer
if (parent instanceof Instantiation) {
return (if(parent.componentRef !== null) parent.componentRef.type else parent.component.type).literal.toFirstUpper+' '+o.name
}
}
}
return super.getFirstLine(o)
}
}

View File

@ -8,7 +8,6 @@ import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider
import org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider
import com.minres.rdl.rdl.ComponentDefinition
import com.minres.rdl.rdl.ExplicitPropertyAssignment
import com.minres.rdl.rdl.ImmediateInstantiation
import com.minres.rdl.rdl.ComponentInstance
import com.minres.rdl.rdl.PropertyAssignment
import com.minres.rdl.rdl.PropertyAssignmentRhs
@ -19,7 +18,6 @@ import com.minres.rdl.rdl.RValueConstant
import com.minres.rdl.rdl.PropertyModifier
import com.minres.rdl.rdl.ComponentDefinitionType
import com.minres.rdl.rdl.EnumDefinition
import com.minres.rdl.rdl.NamedInstantiation
import com.minres.rdl.rdl.PostPropertyAssignment
import com.minres.rdl.rdl.InstanceRef
import com.minres.rdl.rdl.InstancePropertyRef
@ -38,23 +36,8 @@ class RDLLabelProvider extends DefaultEObjectLabelProvider {
super(delegate);
}
// Labels and icons can be computed like this:
// def text(Greeting ele) {
// 'A greeting to ' + ele.name
// }
//
// def image(Greeting ele) {
// 'Greeting.gif'
// }
def text(ComponentDefinition e){
if(e.immediateInstantiation!==null){
if(e.name!==null)
text(e.immediateInstantiation)+' ('+e.name+')'
else
text(e.immediateInstantiation)
}else if(e.name!==null){
if(e.name!==null){
e.type.literal+' '+e.name
} else{
val pa = e.propertyAssignments.findFirst[PropertyAssignment pa |
@ -91,14 +74,10 @@ class RDLLabelProvider extends DefaultEObjectLabelProvider {
e.instance.name
}
def text( ImmediateInstantiation e){
e.componentInstances.map[text(it)].join(", ")
}
def text( ComponentInstance e){
var res = e.name
if(e.range !== null)
res+='['+(if(e.range.size!==null) e.range.size.toString else e.range.start+':'+e.range.end)+']'
res+='['+(if(e.range.size!==null) e.range.size.toString else e.range.left+':'+e.range.right)+']'
if(e.address!==null)
res+=' @'+e.address
return res
@ -140,10 +119,6 @@ class RDLLabelProvider extends DefaultEObjectLabelProvider {
return string
}
def text(NamedInstantiation e){
e.componentInstances.map[text(it)].join(", ")+' ('+e.component.name+')'
}
def text(EnumEntry e){
if(e.index !== null)
e.name + '=' + e.index.toString
@ -198,7 +173,7 @@ class RDLLabelProvider extends DefaultEObjectLabelProvider {
'P.png'
}
def image(NamedInstantiation e){
def image(ComponentInstance e){
'I.png'
}

View File

@ -8,13 +8,13 @@ import org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider
import org.eclipse.xtext.ui.editor.outline.impl.DocumentRootNode
import com.minres.rdl.rdl.ComponentDefinition
import org.eclipse.xtext.ui.editor.outline.IOutlineNode
import com.minres.rdl.rdl.PropertyAssignment
import com.minres.rdl.rdl.NamedInstantiation
import com.minres.rdl.rdl.ExplicitPropertyAssignment
import com.minres.rdl.rdl.PostPropertyAssignment
import com.minres.rdl.rdl.PropertyAssignmentRhs
import com.minres.rdl.rdl.EnumDefinition
import com.minres.rdl.rdl.EnumEntry
import com.minres.rdl.rdl.Instantiation
import com.minres.rdl.rdl.ComponentInstance
/**
* Customization of the default outline structure.
@ -28,16 +28,22 @@ class RDLOutlineTreeProvider extends DefaultOutlineTreeProvider {
domainModel.propertyDefinitions.forEach[createNode(parentNode, it)]
domainModel.componentDefinitions.forEach[createNode(parentNode, it)]
domainModel.propertyAssignments.forEach[createNode(parentNode, it)]
domainModel.namedInstantiations.forEach[createNode(parentNode, it)]
domainModel.instantiations.forEach[Instantiation instantiation |
if(instantiation.component!==null) createNode(parentNode, instantiation.component)
instantiation.componentInstances.forEach[createNode(parentNode, it)]
]
}
protected def _createChildren(IOutlineNode parentNode, ComponentDefinition compDef) {
compDef.enumDefinitions.forEach[createNode(parentNode, it)]
compDef.componentDefinitions.forEach[createNode(parentNode, it)]
compDef.propertyAssignments.forEach[createNode(parentNode, it)]
compDef.namedInstantiations.forEach[createNode(parentNode, it)]
compDef.instantiations.forEach[Instantiation instantiation |
if(instantiation.component!==null) createNode(parentNode, instantiation.component)
instantiation.componentInstances.forEach[createNode(parentNode, it)]
]
}
protected def _createChildren(IOutlineNode parentNode, EnumDefinition e) {
e.body.entries.forEach[createNode(parentNode, it)]
}
@ -50,14 +56,18 @@ class RDLOutlineTreeProvider extends DefaultOutlineTreeProvider {
return true;
}
protected def boolean _isLeaf(NamedInstantiation feature) {
return true;
protected def boolean _isLeaf(Instantiation feature) {
return feature.component===null && feature.componentInstances.size==0;
}
protected def boolean _isLeaf(PropertyAssignmentRhs feature) {
return true;
}
protected def boolean _isLeaf(ComponentInstance feature) {
return true;
}
protected def boolean _isLeaf(EnumEntry feature) {
return feature.properties.size==0;
}