Revision 8
Added by Willibald K. over 9 years ago
trunk/compiler/ooasCompiler/.settings/org.eclipse.jdt.ui.prefs | ||
---|---|---|
eclipse.preferences.version=1
|
||
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
|
||
sp_cleanup.add_default_serial_version_id=true
|
||
sp_cleanup.add_generated_serial_version_id=false
|
||
sp_cleanup.add_missing_annotations=true
|
||
sp_cleanup.add_missing_deprecated_annotations=true
|
||
sp_cleanup.add_missing_methods=false
|
||
sp_cleanup.add_missing_nls_tags=false
|
||
sp_cleanup.add_missing_override_annotations=true
|
||
sp_cleanup.add_missing_override_annotations_interface_methods=true
|
||
sp_cleanup.add_serial_version_id=false
|
||
sp_cleanup.always_use_blocks=true
|
||
sp_cleanup.always_use_parentheses_in_expressions=false
|
||
sp_cleanup.always_use_this_for_non_static_field_access=false
|
||
sp_cleanup.always_use_this_for_non_static_method_access=false
|
||
sp_cleanup.convert_functional_interfaces=false
|
||
sp_cleanup.convert_to_enhanced_for_loop=false
|
||
sp_cleanup.correct_indentation=false
|
||
sp_cleanup.format_source_code=false
|
||
sp_cleanup.format_source_code_changes_only=false
|
||
sp_cleanup.make_local_variable_final=true
|
||
sp_cleanup.make_parameters_final=false
|
||
sp_cleanup.make_private_fields_final=false
|
||
sp_cleanup.make_type_abstract_if_missing_method=false
|
||
sp_cleanup.make_variable_declarations_final=true
|
||
sp_cleanup.never_use_blocks=false
|
||
sp_cleanup.never_use_parentheses_in_expressions=true
|
||
sp_cleanup.on_save_use_additional_actions=true
|
||
sp_cleanup.organize_imports=false
|
||
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
|
||
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
|
||
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
|
||
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
|
||
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
|
||
sp_cleanup.remove_private_constructors=true
|
||
sp_cleanup.remove_trailing_whitespaces=true
|
||
sp_cleanup.remove_trailing_whitespaces_all=true
|
||
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
|
||
sp_cleanup.remove_unnecessary_casts=true
|
||
sp_cleanup.remove_unnecessary_nls_tags=false
|
||
sp_cleanup.remove_unused_imports=true
|
||
sp_cleanup.remove_unused_local_variables=false
|
||
sp_cleanup.remove_unused_private_fields=true
|
||
sp_cleanup.remove_unused_private_members=false
|
||
sp_cleanup.remove_unused_private_methods=true
|
||
sp_cleanup.remove_unused_private_types=true
|
||
sp_cleanup.sort_members=false
|
||
sp_cleanup.sort_members_all=false
|
||
sp_cleanup.use_anonymous_class_creation=false
|
||
sp_cleanup.use_blocks=false
|
||
sp_cleanup.use_blocks_only_for_return_and_throw=false
|
||
sp_cleanup.use_lambda=true
|
||
sp_cleanup.use_parentheses_in_expressions=false
|
||
sp_cleanup.use_this_for_non_static_field_access=false
|
||
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
|
||
sp_cleanup.use_this_for_non_static_method_access=false
|
||
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
|
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/AstBuilder.java | ||
---|---|---|
/**
|
||
*
|
||
* OOAS Compiler
|
||
*
|
||
* Copyright 2015, AIT Austrian Institute of Technology.
|
||
* This code is based on the C# Version of the OOAS Compiler, which is
|
||
* copyright 2015 by the Institute of Software Technology, Graz University
|
||
* of Technology with portions copyright by the AIT Austrian Institute of
|
||
* Technology. All rights reserved.
|
||
*
|
||
* SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
|
||
*
|
||
* If you modify the file please update the list of contributors below to in-
|
||
* clude your name. Please also stick to the coding convention of using TABs
|
||
* to do the basic (block-level) indentation and spaces for anything after
|
||
* that. (Enable the display of special chars and it should be pretty obvious
|
||
* what this means.) Also, remove all trailing whitespace.
|
||
*
|
||
* Contributors:
|
||
* Stefan Tiran (AIT)
|
||
* Willibald Krenn (AIT)
|
||
*
|
||
*/
|
||
|
||
|
||
package org.momut.ooas.ast;
|
||
|
||
|
||
import java.util.LinkedList;
|
||
import java.util.List;
|
||
|
||
import org.momut.ooas.ast.expressions.AccessExpression;
|
||
import org.momut.ooas.ast.expressions.CallExpression;
|
||
import org.momut.ooas.ast.expressions.Expression;
|
||
import org.momut.ooas.ast.expressions.IdentifierExpression;
|
||
import org.momut.ooas.ast.expressions.LeafExpression;
|
||
import org.momut.ooas.ast.expressions.ListConstructor;
|
||
import org.momut.ooas.ast.expressions.ObjectConstructor;
|
||
import org.momut.ooas.ast.expressions.UnresolvedIdentifierExpression;
|
||
import org.momut.ooas.ast.expressions.ValueExpression;
|
||
import org.momut.ooas.ast.identifiers.AttributeIdentifier;
|
||
import org.momut.ooas.ast.identifiers.EnumIdentifier;
|
||
import org.momut.ooas.ast.identifiers.Identifier;
|
||
import org.momut.ooas.ast.identifiers.IdentifierKind;
|
||
import org.momut.ooas.ast.identifiers.IdentifierList;
|
||
import org.momut.ooas.ast.identifiers.MainModule;
|
||
import org.momut.ooas.ast.identifiers.MethodIdentifier;
|
||
import org.momut.ooas.ast.identifiers.NamedActionIdentifier;
|
||
import org.momut.ooas.ast.identifiers.NondetIdentifierList;
|
||
import org.momut.ooas.ast.identifiers.ParameterIdentifier;
|
||
import org.momut.ooas.ast.identifiers.PrioIdentifierList;
|
||
import org.momut.ooas.ast.identifiers.SelfTypeIdentifier;
|
||
import org.momut.ooas.ast.identifiers.TypeIdentifier;
|
||
import org.momut.ooas.ast.statements.Assignment;
|
||
import org.momut.ooas.ast.statements.Block;
|
||
import org.momut.ooas.ast.statements.Call;
|
||
import org.momut.ooas.ast.statements.NondetBlock;
|
||
import org.momut.ooas.ast.statements.SeqBlock;
|
||
import org.momut.ooas.ast.statements.SkipStatement;
|
||
import org.momut.ooas.ast.statements.Statement;
|
||
import org.momut.ooas.ast.types.BoolType;
|
||
import org.momut.ooas.ast.types.EnumType;
|
||
import org.momut.ooas.ast.types.FunctionType;
|
||
import org.momut.ooas.ast.types.FunctionType.FunctionTypeEnum;
|
||
import org.momut.ooas.ast.types.IntType;
|
||
import org.momut.ooas.ast.types.ListType;
|
||
import org.momut.ooas.ast.types.OoActionSystemType;
|
||
import org.momut.ooas.ast.types.OpaqueType;
|
||
import org.momut.ooas.ast.types.UlyssesType;
|
||
import org.momut.ooas.parser.ParserError;
|
||
import org.momut.ooas.parser.ParserState;
|
||
|
||
|
||
public class AstBuilder {
|
||
|
||
public static void setSystemDescription(MainModule mainModule, Identifier systemDescription) {
|
||
final IdentifierList aDescr = new NondetIdentifierList();
|
||
aDescr.AddElement(systemDescription);
|
||
mainModule.SetSystemDescription(aDescr);
|
||
}
|
||
|
||
public static Identifier createPrioritizedSAB(LinkedList<Identifier> systems){
|
||
final IdentifierList systemDescription = new PrioIdentifierList();
|
||
for (final Identifier system : systems){
|
||
systemDescription.AddElement(system);
|
||
}
|
||
return systemDescription;
|
||
}
|
||
|
||
public static Identifier createNonDetChoiceSAB(LinkedList<Identifier> systems){
|
||
final IdentifierList systemDescription = new NondetIdentifierList();
|
||
for (final Identifier system : systems){
|
||
systemDescription.AddElement(system);
|
||
}
|
||
return systemDescription;
|
||
}
|
||
|
||
public static TypeIdentifier createActionSystem(boolean autocons, String name, IScope scope){
|
||
final OoActionSystemType type = new OoActionSystemType(autocons, null, null);
|
||
final SelfTypeIdentifier self = new SelfTypeIdentifier("self", type, scope);
|
||
type.AddIdentifier(self, null);
|
||
type.SetupAnonymousName(); // need to be called before setting the type identifier
|
||
final TypeIdentifier ident = new TypeIdentifier(name, type, scope);
|
||
|
||
type.SetTypeIdentifier(ident);
|
||
scope.AddIdentifier(ident, null);
|
||
|
||
return ident;
|
||
}
|
||
|
||
|
||
public static AttributeIdentifier createObjectAttribute(String varName, Identifier aClass, boolean doInstantiate, Identifier root){
|
||
final UlyssesType aType = aClass.type();
|
||
aType.SetupAnonymousName(); //not sure if necessary
|
||
Expression anExpr;
|
||
if (doInstantiate){
|
||
anExpr = new ObjectConstructor(aType, varName, 0, 0);
|
||
} else {
|
||
anExpr = new ValueExpression<Object>(null, 0, 0, Object.class);
|
||
}
|
||
|
||
final AttributeIdentifier attributeIdentifier = new AttributeIdentifier(varName, aType, ((IScope)(root).type()), anExpr, false, false, false );
|
||
((IScope)(root).type()).AddIdentifier(attributeIdentifier, null);
|
||
|
||
return attributeIdentifier;
|
||
}
|
||
|
||
|
||
public static Expression boolConstant(boolean b){
|
||
return new ValueExpression<Boolean>(b, 0, 0, Boolean.class);
|
||
}
|
||
|
||
public static ListType createListType(UlyssesType elemType, int max, TypeIdentifier anIdentifier){
|
||
final ListType result = new ListType(elemType, max, null);
|
||
result.SetupAnonymousName();
|
||
result.SetTypeIdentifier(anIdentifier);
|
||
return result;
|
||
}
|
||
|
||
public static EnumType createEnumType(String name, List<String> ranges, IScope scope){
|
||
final EnumType type = new EnumType(null);
|
||
|
||
EnumIdentifier enumval;
|
||
for (final String range : ranges){
|
||
enumval = new EnumIdentifier(range, type, scope);
|
||
type.AddEnumSymbol(enumval);
|
||
scope.AddIdentifier(enumval, null);
|
||
}
|
||
type.SetupAnonymousName();
|
||
final TypeIdentifier ident = new TypeIdentifier(name, type, scope);
|
||
|
||
type.SetTypeIdentifier(ident);
|
||
scope.AddIdentifier(ident, null);
|
||
return type;
|
||
}
|
||
|
||
|
||
public static UlyssesType createIntType(int low, int high){
|
||
return new IntType(low, high, null);
|
||
}
|
||
|
||
public static AttributeIdentifier createListAttribute(String varname, ListType type, Identifier root){
|
||
final Expression anExpr = new ListConstructor(0, 0);
|
||
final AttributeIdentifier attributeIdentifier = new AttributeIdentifier(varname, type, ((IScope)(root).type()), anExpr, false, false, false );
|
||
((IScope)(root).type()).AddIdentifier(attributeIdentifier, null);
|
||
|
||
return attributeIdentifier;
|
||
}
|
||
|
||
public static AttributeIdentifier createEnumAttribute(String varname, EnumType type, String init, Identifier root){
|
||
final Identifier initIdent = root.definingScope().ResolveIdentifier(init);
|
||
final Expression anExpr = new IdentifierExpression(initIdent, 0, 0);
|
||
final AttributeIdentifier attributeIdentifier = new AttributeIdentifier(varname, type, ((IScope)(root).type()), anExpr, false, false, false );
|
||
((IScope)(root).type()).AddIdentifier(attributeIdentifier, null);
|
||
|
||
return attributeIdentifier;
|
||
}
|
||
|
||
|
||
public static AttributeIdentifier createBoolAttribute(String varname, boolean isStatic, boolean init, Identifier root){
|
||
final Expression anExpr = new ValueExpression<Boolean>(init, 0, 0, Boolean.class);
|
||
final UlyssesType aType = new BoolType(null);
|
||
aType.SetupAnonymousName();
|
||
final AttributeIdentifier attributeIdentifier = new AttributeIdentifier(varname, aType, ((IScope)(root).type()), anExpr, isStatic, false, false );
|
||
((IScope)(root).type()).AddIdentifier(attributeIdentifier, null);
|
||
|
||
return attributeIdentifier;
|
||
}
|
||
|
||
public static AttributeIdentifier createAttribute(String varname, boolean isStatic, UlyssesType aType, Expression anExpr, IScope scope){
|
||
final AttributeIdentifier attributeIdentifier = new AttributeIdentifier(varname, aType, scope, anExpr, isStatic, false, false );
|
||
scope.AddIdentifier(attributeIdentifier, null);
|
||
|
||
return attributeIdentifier;
|
||
}
|
||
|
||
public static MethodIdentifier createMethod(
|
||
String name,
|
||
LinkedList<ParameterIdentifier> params,
|
||
UlyssesType returnType,
|
||
Identifier as,
|
||
Statement body
|
||
) {
|
||
final LinkedList<UlyssesType> parameterTypes = new LinkedList<UlyssesType>();
|
||
for (final ParameterIdentifier param : params) {
|
||
parameterTypes.add(param.type());
|
||
}
|
||
|
||
final FunctionType methodType = new FunctionType(FunctionType.FunctionTypeEnum.Method, parameterTypes, returnType);
|
||
|
||
final MethodIdentifier ident = new MethodIdentifier(name, methodType, (IScope)as.type());
|
||
((IScope)(as.type())).AddIdentifier(ident, null);
|
||
ident.SetParentScope((IScope)as.type());
|
||
ident.SetBody(body);
|
||
|
||
for (final ParameterIdentifier p : params) {
|
||
ident.AddParameter(p);
|
||
}
|
||
methodType.SetupAnonymousName();
|
||
|
||
return ident;
|
||
}
|
||
|
||
public static NamedActionIdentifier createActionWithoutBody(
|
||
FunctionType.FunctionTypeEnum functionType,
|
||
String name,
|
||
LinkedList<UlyssesType> parameters,
|
||
Identifier as)
|
||
{
|
||
final FunctionType actionType = new FunctionType(functionType, parameters, null);
|
||
actionType.SetupAnonymousName();
|
||
final NamedActionIdentifier ident = new NamedActionIdentifier(name, actionType, (IScope)as.type());
|
||
((IScope)(as.type())).AddIdentifier(ident, null);
|
||
return ident;
|
||
}
|
||
|
||
public static Identifier createAction(
|
||
FunctionType.FunctionTypeEnum functionType,
|
||
String name,
|
||
LinkedList<UlyssesType> parameters,
|
||
Identifier as,
|
||
Statement body)
|
||
{
|
||
final FunctionType actionType = new FunctionType(functionType, parameters, null);
|
||
actionType.SetupAnonymousName();
|
||
final NamedActionIdentifier ident = new NamedActionIdentifier(name, actionType, (IScope)as.type());
|
||
((IScope)(as.type())).AddIdentifier(ident, null);
|
||
ident.SetBody(body);
|
||
return ident;
|
||
}
|
||
|
||
public static Block createNonDetBlock(LinkedList<Identifier> actions){
|
||
final Block block = new NondetBlock(0, 0);
|
||
|
||
for (final Identifier action : actions) {
|
||
final Block block2 = new SeqBlock(0, 0);
|
||
final CallExpression ce = new CallExpression(
|
||
new IdentifierExpression(action,0,0),
|
||
null,
|
||
0,
|
||
0,
|
||
block
|
||
);
|
||
block2.AddStatement(new Call(ce, 0, 0));
|
||
block.AddStatement(block2);
|
||
}
|
||
|
||
return block;
|
||
}
|
||
|
||
|
||
public static MainModule buildHelloWorld(){
|
||
// == (1) define the main module, i.e. main scope ==
|
||
final MainModule mainModule = new MainModule();
|
||
|
||
// == (2) let's define the single action system type that is contained/defined in this main module ==
|
||
final OoActionSystemType greeterType = new OoActionSystemType(
|
||
true, // let's suppose this is auto-constructing
|
||
null, // refines no other action system
|
||
null // type identifier is set below
|
||
);
|
||
greeterType.AddIdentifier(new SelfTypeIdentifier("self", greeterType, greeterType), null);
|
||
greeterType.SetupAnonymousName(); // need to be called before setting the type identifier
|
||
|
||
// -- instantiate the type identifier for our action system type --
|
||
final TypeIdentifier greeterTypeIdentifier = new TypeIdentifier(
|
||
"greeter", // name
|
||
greeterType,// bind it to the type
|
||
mainModule // scope where this is defined
|
||
);
|
||
// -- wire up the type identifier with the type (doubly linked therefore this more cumbersome two-call approach)
|
||
greeterType.SetTypeIdentifier(greeterTypeIdentifier);
|
||
mainModule.AddIdentifier(greeterTypeIdentifier, null);
|
||
|
||
|
||
// == (3) define the sole observable action of the type ==
|
||
// -- define the (implicitly declared type of the action) --lBlock
|
||
final FunctionType helloWorldActionType = new FunctionType( // this type is anonymous and doesn't have a name!
|
||
FunctionTypeEnum.Observable, // This is observable, hence an action
|
||
new LinkedList<UlyssesType>(), // no parameters
|
||
null // void return
|
||
);
|
||
helloWorldActionType.SetupAnonymousName(); // need to be called before setting the type identifier
|
||
// -- define the actual identifier incl. impl. --
|
||
final NamedActionIdentifier helloWorldActionIdentifier = new NamedActionIdentifier(
|
||
"HelloWorld", // name of the action
|
||
helloWorldActionType, // type of the action
|
||
greeterType // defining scope
|
||
);
|
||
// -- register the new identifier with the current scope
|
||
greeterType.AddIdentifier(helloWorldActionIdentifier, null);
|
||
// -- add implementation of the action
|
||
//helloWorldActionIdentifier.SetBody(new SkipStatement(0, 0));
|
||
helloWorldActionIdentifier.SetBody(new SkipStatement(0, 0));
|
||
|
||
|
||
// == (4) define the do-od block of the action system type
|
||
final Block greeterDoOdBlock = new SeqBlock(0, 0);
|
||
greeterType.SetDoOdBlock(greeterDoOdBlock);
|
||
// -- add a call statement to the dood block --
|
||
final CallExpression callHelloWorldExpression = new CallExpression(
|
||
new IdentifierExpression(helloWorldActionIdentifier, 0, 0), // what to call
|
||
null, // arguments
|
||
0, // line
|
||
0, // col
|
||
greeterDoOdBlock // scope
|
||
);
|
||
greeterDoOdBlock.AddStatement(new Call(callHelloWorldExpression, 0, 0));
|
||
|
||
|
||
// == (5) add scheduling information (SAB block) ==
|
||
final IdentifierList systemDescription = new NondetIdentifierList();
|
||
systemDescription.AddElement(greeterTypeIdentifier);
|
||
mainModule.SetSystemDescription(systemDescription);
|
||
|
||
return mainModule;
|
||
}
|
||
|
||
|
||
public static LeafExpression createIntConstant(Integer i)
|
||
{
|
||
return new ValueExpression<Integer>(i, 0, 0, Integer.class);
|
||
}
|
||
|
||
public static Expression createIdentifierAccessExpressionWithoutResolve(String name, IScope scope){
|
||
final IdentifierExpression uIdent = new UnresolvedIdentifierExpression(name, scope);
|
||
final IdentifierExpression aself = new IdentifierExpression(scope.ResolveIdentifier("self"), 0, 0);
|
||
aself.setIsSelf(true);
|
||
final AccessExpression exp = new AccessExpression(aself, uIdent, 0, 0);
|
||
return exp;
|
||
}
|
||
|
||
public static Expression createIdentifierAccessExpression(Identifier attr){
|
||
final IdentifierExpression uIdent = new IdentifierExpression(attr, 0, 0);
|
||
|
||
final IdentifierExpression aself = new IdentifierExpression(attr.definingScope().ResolveIdentifier("self"), 0, 0);
|
||
aself.setIsSelf(true);
|
||
final AccessExpression exp = new AccessExpression(aself, uIdent, 0, 0);
|
||
return exp;
|
||
}
|
||
|
||
public static CallExpression createMethodAccessExpression(Expression subexpr, List<Expression> m_params, IScope scope){
|
||
return new CallExpression(subexpr, m_params, 0, 0, scope);
|
||
}
|
||
|
||
public static Statement createAssignment(AttributeIdentifier attr, ListConstructor lc) {
|
||
return new Assignment(createIdentifierAccessExpression(attr), lc, null, 0, 0);
|
||
}
|
||
|
||
public static Statement createAssignment(Expression exp1, Expression exp2) {
|
||
return new Assignment(exp1, exp2, null, 0, 0);
|
||
}
|
||
|
||
public static Statement createAssignment(AttributeIdentifier attr, boolean b) {
|
||
return new Assignment(createIdentifierAccessExpression(attr), new ValueExpression<Boolean>(b, 0, 0, Boolean.class),null,0,0);
|
||
}
|
||
|
||
public static Statement createAssignment2(
|
||
AttributeIdentifier attr, Identifier instance) {
|
||
//FIXXME here be dragons
|
||
return new Assignment(createIdentifierAccessExpression(attr), new IdentifierExpression(instance, 0, 0), null, 0, 0);
|
||
}
|
||
|
||
public static Statement createAssignmentWithoutResolve(String leftName, IScope leftScope, Expression right){
|
||
return new Assignment(new UnresolvedIdentifierExpression(leftName, leftScope), right , null, 0, 0);
|
||
}
|
||
|
||
public static Statement createAssignmentWithoutResolve(String leftName, IScope leftScope, String rightName, IScope rightScope){
|
||
return new Assignment(new UnresolvedIdentifierExpression(leftName, leftScope), new UnresolvedIdentifierExpression(rightName, rightScope), null, 0, 0);
|
||
}
|
||
|
||
public static Statement createAssignment(
|
||
AttributeIdentifier attr, Identifier instance) {
|
||
return new Assignment(createIdentifierAccessExpression(attr), createIdentifierAccessExpression(instance), null, 0, 0);
|
||
}
|
||
|
||
public static Expression createMethodAccessExpressionWithLocalVar(String objectName,
|
||
String methodName, List<Expression> m_params, IScope scope) {
|
||
final Expression subexpr = new AccessExpression(
|
||
new UnresolvedIdentifierExpression(objectName, scope),
|
||
new UnresolvedIdentifierExpression(methodName, scope),
|
||
0,0);
|
||
return new CallExpression(subexpr, m_params, 0, 0, scope);
|
||
}
|
||
|
||
|
||
public static Expression createMethodAccessExpressionWithoutResolveAtAll(String objectName,
|
||
String methodName, List<Expression> m_params, IScope scope) {
|
||
final UnresolvedIdentifierExpression modelSelf = new UnresolvedIdentifierExpression("self", scope);
|
||
modelSelf.setIsSelf(true);
|
||
|
||
final Expression subexpr = new AccessExpression(
|
||
new AccessExpression(
|
||
modelSelf,
|
||
new UnresolvedIdentifierExpression(objectName, scope),
|
||
0, 0),
|
||
new UnresolvedIdentifierExpression(methodName, scope),
|
||
0,0);
|
||
return new CallExpression(subexpr, m_params, 0, 0, scope);
|
||
}
|
||
|
||
|
||
public static Statement createAssignment(Identifier attr,
|
||
Identifier instance) {
|
||
return new Assignment(createIdentifierAccessExpression(attr), createIdentifierAccessExpression(instance), null, 0, 0);
|
||
}
|
||
|
||
public static Statement createAssignment(Identifier attr,
|
||
Expression exp) {
|
||
return new Assignment(createIdentifierAccessExpression(attr), exp, null, 0, 0);
|
||
}
|
||
|
||
public static LeafExpression createNullPointerConstant()
|
||
{
|
||
return new ValueExpression<Object>(null, 0, 0, Object.class);
|
||
}
|
||
|
||
public static Expression intConstant(int i) {
|
||
return new ValueExpression<Integer>(i, 0, 0, Integer.class);
|
||
}
|
||
|
||
public static void FixupNamedTypes(ParserState pState)
|
||
{
|
||
/*named type refs that could not be resolved in the first run, have to
|
||
be resolved now. */
|
||
for (final OpaqueType ntype: pState.typesToFixUp)
|
||
{
|
||
if (ntype.resolvedType() == null)
|
||
{
|
||
//ntype.identifier
|
||
final Identifier asym = pState.Lookup(ntype.identifier().tokenText(), ntype.identifier().definingScope());
|
||
if ((asym == null) || (asym.kind() != IdentifierKind.TypeIdentifier))
|
||
{
|
||
final ParserError error = new ParserError(pState.filename, ntype.identifier().line(), ntype.identifier().column(),
|
||
String.format("Can not resolve %s to a named type", ntype.identifier().tokenText()));
|
||
pState.AddErrorMessage(error);
|
||
}
|
||
else
|
||
ntype.SetResolvedType(asym.type());
|
||
}
|
||
}
|
||
pState.typesToFixUp.clear();
|
||
}
|
||
|
||
|
||
}
|
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/expressions/ObjectConstructor.java | ||
---|---|---|
* Stephan Zimmerer (AIT)
|
||
* Markus Demetz (AIT)
|
||
* Christoph Czurda (AIT)
|
||
* Stefan Tiran (AIT)
|
||
*
|
||
*/
|
||
|
||
... | ... | |
import org.momut.ooas.ast.IAstVisitor;
|
||
import org.momut.ooas.ast.types.OoActionSystemInstance;
|
||
import org.momut.ooas.ast.types.OpaqueType;
|
||
import org.momut.ooas.ast.types.UlyssesType;
|
||
|
||
public final class ObjectConstructor extends TypeConstructionExpression
|
||
{
|
||
... | ... | |
private int m_currentInstance;
|
||
private String m_fixedObjectName;
|
||
|
||
private final String cleanup(String name) {
|
||
if (name.startsWith("\"")) {
|
||
name = name.substring(1, name.length()-1);
|
||
}
|
||
return name;
|
||
}
|
||
|
||
public int currentInstance() { return m_currentInstance; }
|
||
public ArrayList<OoActionSystemInstance> instances() { return m_instances; }
|
||
public String givenObjectName() { return m_fixedObjectName; }
|
||
... | ... | |
SetType(aType);
|
||
m_instances = new ArrayList<OoActionSystemInstance>();
|
||
m_currentInstance = 0;
|
||
m_fixedObjectName = aName;
|
||
m_fixedObjectName = cleanup(aName);
|
||
}
|
||
|
||
public ObjectConstructor(UlyssesType aType, String aName, int line, int pos)
|
||
{
|
||
super (ExpressionKind.ObjectConstr, line, pos);
|
||
SetType(aType);
|
||
m_instances = new ArrayList<OoActionSystemInstance>();
|
||
m_currentInstance = 0;
|
||
m_fixedObjectName = cleanup(aName);
|
||
}
|
||
|
||
public ObjectConstructor(ObjectConstructor toCopy)
|
||
{
|
||
... | ... | |
}
|
||
|
||
@Override
|
||
public /*override*/ Expression Clone()
|
||
public Expression Clone()
|
||
{
|
||
return new ObjectConstructor(this);
|
||
}
|
||
|
||
public /*override*/ void Accept(IAstVisitor visitor)
|
||
@Override
|
||
public void Accept(IAstVisitor visitor)
|
||
{
|
||
visitor.visit(this);
|
||
}
|
||
... | ... | |
|
||
public OoActionSystemInstance GetNextInstance()
|
||
{
|
||
OoActionSystemInstance result = m_instances.get(m_currentInstance);
|
||
final OoActionSystemInstance result = m_instances.get(m_currentInstance);
|
||
m_currentInstance++;
|
||
return result;
|
||
}
|
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/expressions/UnresolvedIdentifierExpression.java | ||
---|---|---|
* Stephan Zimmerer (AIT)
|
||
* Markus Demetz (AIT)
|
||
* Christoph Czurda (AIT)
|
||
* Stefan Tiran (AIT)
|
||
*
|
||
*/
|
||
|
||
... | ... | |
m_tokenText = toCopy.m_tokenText;
|
||
}
|
||
|
||
public UnresolvedIdentifierExpression(String name, IScope aScope)
|
||
{
|
||
super (null, 0, 0);
|
||
m_kind = ExpressionKind.UnresolvedIdentifier;
|
||
m_tokenText = name;
|
||
m_scope = aScope;
|
||
}
|
||
|
||
|
||
@Override
|
||
public /*override*/ Expression Clone()
|
||
public Expression Clone()
|
||
{
|
||
return new UnresolvedIdentifierExpression(this);
|
||
}
|
||
|
||
public /*override*/ void Accept(IAstVisitor visitor)
|
||
|
||
@Override
|
||
public void Accept(IAstVisitor visitor)
|
||
{
|
||
visitor.visit(this);
|
||
}
|
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/identifiers/AttributeIdentifier.java | ||
---|---|---|
* Stephan Zimmerer (AIT)
|
||
* Markus Demetz (AIT)
|
||
* Christoph Czurda (AIT)
|
||
* Stefan Tiran (AIT)
|
||
*
|
||
*/
|
||
|
||
... | ... | |
m_isObservable = isObservable;
|
||
}
|
||
|
||
public AttributeIdentifier(String name,
|
||
UlyssesType aType,
|
||
IScope aDefiningScope,
|
||
Expression anInitializer,
|
||
boolean isStatic,
|
||
boolean isObservable,
|
||
boolean isControllable)
|
||
{
|
||
super(name, aType, IdentifierKind.AttributeIdentifier, aDefiningScope);
|
||
m_initializer = anInitializer;
|
||
m_isStatic = isStatic;
|
||
m_isControllable = isControllable;
|
||
m_isObservable = isObservable;
|
||
}
|
||
|
||
public AttributeIdentifier(AttributeIdentifier toCopy)
|
||
{
|
||
super(toCopy);
|
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/identifiers/EnumIdentifier.java | ||
---|---|---|
* Stephan Zimmerer (AIT)
|
||
* Markus Demetz (AIT)
|
||
* Christoph Czurda (AIT)
|
||
* Stefan Tiran (AIT)
|
||
*
|
||
*/
|
||
|
||
... | ... | |
haveValue = false;
|
||
}
|
||
|
||
public EnumIdentifier(String range,
|
||
EnumType aType,
|
||
IScope aDefiningScope)
|
||
{
|
||
super(range, aType, IdentifierKind.EnumIdentifier, aDefiningScope);
|
||
haveValue = false;
|
||
}
|
||
|
||
public EnumIdentifier(Token aToken,
|
||
int aValue,
|
||
... | ... | |
|
||
|
||
@Override
|
||
public /*override*/ Identifier Clone()
|
||
public Identifier Clone()
|
||
{
|
||
return this;
|
||
}
|
||
|
||
public /*override*/ void Accept(IAstVisitor visitor)
|
||
@Override
|
||
public void Accept(IAstVisitor visitor)
|
||
{
|
||
visitor.visit(this);
|
||
}
|
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/identifiers/FunctionIdentifier.java | ||
---|---|---|
* Stephan Zimmerer (AIT)
|
||
* Markus Demetz (AIT)
|
||
* Christoph Czurda (AIT)
|
||
* Stefan Tiran (AIT)
|
||
*
|
||
*/
|
||
|
||
... | ... | |
m_parameter = new ArrayList<ParameterIdentifier>(toCopy.m_parameter);
|
||
}
|
||
|
||
public FunctionIdentifier(
|
||
String name,
|
||
UlyssesType aType,
|
||
IdentifierKind aKind,
|
||
IScope aDefiningScope)
|
||
{
|
||
super(name, aType, aKind, aDefiningScope);
|
||
}
|
||
|
||
public void SetBody(Statement body)
|
||
{
|
||
m_body = body;
|
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/identifiers/LocalVariableIdentifier.java | ||
---|---|---|
* Stephan Zimmerer (AIT)
|
||
* Markus Demetz (AIT)
|
||
* Christoph Czurda (AIT)
|
||
* Stefan Tiran (AIT)
|
||
*
|
||
*/
|
||
|
||
... | ... | |
super (aToken, aType, IdentifierKind.LocalVariableIdentifier, aDefiningScope);
|
||
}
|
||
|
||
public LocalVariableIdentifier(String name,
|
||
UlyssesType aType,
|
||
IScope aDefiningScope)
|
||
{
|
||
super (name, aType, IdentifierKind.LocalVariableIdentifier, aDefiningScope);
|
||
}
|
||
|
||
public LocalVariableIdentifier(LocalVariableIdentifier toCopy)
|
||
{
|
||
super (toCopy);
|
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/identifiers/MethodIdentifier.java | ||
---|---|---|
* Stephan Zimmerer (AIT)
|
||
* Markus Demetz (AIT)
|
||
* Christoph Czurda (AIT)
|
||
* Stefan Tiran (AIT)
|
||
*
|
||
*/
|
||
|
||
... | ... | |
super (aToken, aType, IdentifierKind.MethodIdentifier, aDefiningScope);
|
||
}
|
||
|
||
public MethodIdentifier(String aName,
|
||
UlyssesType aType,
|
||
IScope aDefiningScope)
|
||
{
|
||
super (aName, aType, IdentifierKind.MethodIdentifier, aDefiningScope);
|
||
}
|
||
|
||
public MethodIdentifier(MethodIdentifier toCopy)
|
||
{
|
||
super (toCopy);
|
||
}
|
||
|
||
@Override
|
||
public /*override*/ Identifier Clone()
|
||
public Identifier Clone()
|
||
{
|
||
return new MethodIdentifier(this);
|
||
}
|
||
|
||
@Override
|
||
public /*override*/ void Accept(IAstVisitor visitor)
|
||
{
|
||
visitor.visit(this);
|
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/identifiers/NamedActionIdentifier.java | ||
---|---|---|
* Stephan Zimmerer (AIT)
|
||
* Markus Demetz (AIT)
|
||
* Christoph Czurda (AIT)
|
||
* Stefan Tiran (AIT)
|
||
*
|
||
*/
|
||
|
||
... | ... | |
super (aToken, aType, IdentifierKind.NamedActionIdentifier, aDefiningScope);
|
||
}
|
||
|
||
public NamedActionIdentifier(String aName,
|
||
UlyssesType aType,
|
||
IScope aDefiningScope)
|
||
{
|
||
super (aName, aType, IdentifierKind.NamedActionIdentifier, aDefiningScope);
|
||
}
|
||
|
||
public NamedActionIdentifier(NamedActionIdentifier toCopy)
|
||
{
|
||
super (toCopy);
|
||
}
|
||
|
||
@Override
|
||
public /*override*/ Identifier Clone()
|
||
public Identifier Clone()
|
||
{
|
||
return new NamedActionIdentifier(this);
|
||
}
|
||
|
||
public /*override*/ void Accept(IAstVisitor visitor)
|
||
@Override
|
||
public void Accept(IAstVisitor visitor)
|
||
{
|
||
visitor.visit(this);
|
||
}
|
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/identifiers/ValueIdentifier.java | ||
---|---|---|
* Stephan Zimmerer (AIT)
|
||
* Markus Demetz (AIT)
|
||
* Christoph Czurda (AIT)
|
||
* Stefan Tiran (AIT)
|
||
*
|
||
*/
|
||
|
||
... | ... | |
super(aToken, aType, aKind, aDefiningScope);
|
||
}
|
||
|
||
public ValueIdentifier(String name,
|
||
UlyssesType aType,
|
||
IdentifierKind aKind,
|
||
IScope aDefiningScope)
|
||
{
|
||
super(name, aType, aKind, aDefiningScope);
|
||
}
|
||
|
||
public ValueIdentifier(ValueIdentifier toCopy) { super(toCopy); }
|
||
}
|
trunk/compiler/ooasCompiler/src/org/momut/ooas/codegen/java/JavaExpression.java | ||
---|---|---|
return "!";
|
||
|
||
case Cast:
|
||
JavaType ctype = new JavaType();
|
||
final JavaType ctype = new JavaType();
|
||
expression.type().Accept(ctype);
|
||
return String.format("(%s)", ctype.toString());
|
||
|
||
... | ... | |
{
|
||
if (identifierExpression.identifier().kind() == IdentifierKind.LandmarkIdentifier)
|
||
{
|
||
LandmarkIdentifier lmid = (LandmarkIdentifier)identifierExpression.identifier();
|
||
QrType qr = (QrType)lmid.type();
|
||
final LandmarkIdentifier lmid = (LandmarkIdentifier)identifierExpression.identifier();
|
||
final QrType qr = (QrType)lmid.type();
|
||
m_emitter.Append(qr.landmarks().indexOf(lmid));
|
||
return;
|
||
}
|
||
... | ... | |
@Override
|
||
public void visit(ObjectConstructor objectConstructor)
|
||
{
|
||
int num = m_data.m_constructors.size();
|
||
final int num = m_data.m_constructors.size();
|
||
m_data.m_constructors.add(objectConstructor);
|
||
if (objectConstructor.givenObjectName() != null)
|
||
m_emitter.Append(String.format("new %s(this,%s,%s)",
|
||
m_emitter.Append(String.format("new %s(this,%s,\"%s\")",
|
||
GetIdentifierString(objectConstructor.type().identifier().tokenText()),
|
||
num,
|
||
objectConstructor.givenObjectName()));
|
||
... | ... | |
{
|
||
if (listConstructor.hasComprehension())
|
||
{
|
||
String helpername = String.format("list_constr_helper_%s", UnsignedHelper.toString(listConstructor.hashCode()));
|
||
final String helpername = String.format("list_constr_helper_%s", UnsignedHelper.toString(listConstructor.hashCode()));
|
||
m_emitter.Append(String.format("%s(new org.momut.ooas.codegen.java.runtime.CustomList<Object>())",
|
||
helpername));
|
||
OoasCodeEmitter helperEmitter = new OoasCodeEmitter();
|
||
final OoasCodeEmitter helperEmitter = new OoasCodeEmitter();
|
||
helperEmitter.AppendLine(String.format(
|
||
"public org.momut.ooas.codegen.java.runtime.CustomList<Object> %s (org.momut.ooas.codegen.java.runtime.CustomList<Object> newList){",
|
||
helpername));
|
||
|
||
|
||
for (Identifier sym: listConstructor.comprehensionVariables().symbolList())
|
||
for (final Identifier sym: listConstructor.comprehensionVariables().symbolList())
|
||
{
|
||
JavaType atype = new JavaType();
|
||
final JavaType atype = new JavaType();
|
||
sym.type().Accept(atype);
|
||
|
||
if (sym.type().IsNumeric())
|
||
... | ... | |
throw new NotImplementedException();
|
||
}
|
||
|
||
StringBuilder helperhelper = new StringBuilder();
|
||
final StringBuilder helperhelper = new StringBuilder();
|
||
|
||
|
||
String guardexpr = "true";
|
||
if (listConstructor.comprehension() != null)
|
||
{
|
||
JavaExpression expr = new JavaExpression(helperhelper, m_data);
|
||
final JavaExpression expr = new JavaExpression(helperhelper, m_data);
|
||
listConstructor.comprehension().Accept(expr);
|
||
guardexpr = expr.toString();
|
||
}
|
||
|
||
JavaExpression expr2 = new JavaExpression(helperhelper, m_data);
|
||
final JavaExpression expr2 = new JavaExpression(helperhelper, m_data);
|
||
listConstructor.elements().get(0).Accept(expr2);
|
||
|
||
helperEmitter.AppendLine(String.format("if (%s) {", guardexpr));
|
||
helperEmitter.AppendLine(String.format("newList.Add(%s);", expr2.toString()));
|
||
helperEmitter.AppendLine("}");
|
||
|
||
int count = listConstructor.comprehensionVariables().symbolList().size();
|
||
final int count = listConstructor.comprehensionVariables().symbolList().size();
|
||
for (int i = 0; i< count; i++)
|
||
helperEmitter.AppendLine("}");
|
||
|
||
... | ... | |
if (listConstructor.elements().size() > 0)
|
||
{
|
||
m_emitter.Append("new Object[] { ");
|
||
for (Expression x: listConstructor.elements())
|
||
for (final Expression x: listConstructor.elements())
|
||
{
|
||
if (i != 0)
|
||
m_emitter.Append(",");
|
||
... | ... | |
{
|
||
m_emitter.Append(String.format("new %s(", GetIdentifierString(tupleConstructor.tupleType().tokenText())));
|
||
int i = 0;
|
||
for (Expression arg: tupleConstructor.values())
|
||
for (final Expression arg: tupleConstructor.values())
|
||
{
|
||
if (i != 0)
|
||
m_emitter.Append(",");
|
||
... | ... | |
@Override
|
||
public void visit(QValConstructor qValConstructor)
|
||
{
|
||
StringBuilder helpers = new StringBuilder();
|
||
final StringBuilder helpers = new StringBuilder();
|
||
|
||
String landmarkOne = "null";
|
||
if (qValConstructor.value().length >= 1 && qValConstructor.value()[0] != null)
|
||
{
|
||
JavaExpression lndmrk1 = new JavaExpression(helpers, m_data);
|
||
final JavaExpression lndmrk1 = new JavaExpression(helpers, m_data);
|
||
qValConstructor.value()[0].Accept(lndmrk1);
|
||
landmarkOne = lndmrk1.toString();
|
||
}
|
||
String landmarkTwo = "null";
|
||
if (qValConstructor.value().length >= 2 && qValConstructor.value()[1] != null)
|
||
{
|
||
JavaExpression lndmrk = new JavaExpression(helpers, m_data);
|
||
final JavaExpression lndmrk = new JavaExpression(helpers, m_data);
|
||
qValConstructor.value()[1].Accept(lndmrk);
|
||
landmarkTwo = lndmrk.toString();
|
||
}
|
Also available in: Unified diff
adding initial version of the AstBuilder feature, contributed by Stefan T.