Project

General

Profile

Revision 8

Added by Willibald K. over 9 years ago

adding initial version of the AstBuilder feature, contributed by Stefan T.

View differences:

trunk/compiler/ooasCompiler/.settings/org.eclipse.jdt.ui.prefs
1
eclipse.preferences.version=1
2
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
3
sp_cleanup.add_default_serial_version_id=true
4
sp_cleanup.add_generated_serial_version_id=false
5
sp_cleanup.add_missing_annotations=true
6
sp_cleanup.add_missing_deprecated_annotations=true
7
sp_cleanup.add_missing_methods=false
8
sp_cleanup.add_missing_nls_tags=false
9
sp_cleanup.add_missing_override_annotations=true
10
sp_cleanup.add_missing_override_annotations_interface_methods=true
11
sp_cleanup.add_serial_version_id=false
12
sp_cleanup.always_use_blocks=true
13
sp_cleanup.always_use_parentheses_in_expressions=false
14
sp_cleanup.always_use_this_for_non_static_field_access=false
15
sp_cleanup.always_use_this_for_non_static_method_access=false
16
sp_cleanup.convert_functional_interfaces=false
17
sp_cleanup.convert_to_enhanced_for_loop=false
18
sp_cleanup.correct_indentation=false
19
sp_cleanup.format_source_code=false
20
sp_cleanup.format_source_code_changes_only=false
21
sp_cleanup.make_local_variable_final=true
22
sp_cleanup.make_parameters_final=false
23
sp_cleanup.make_private_fields_final=false
24
sp_cleanup.make_type_abstract_if_missing_method=false
25
sp_cleanup.make_variable_declarations_final=true
26
sp_cleanup.never_use_blocks=false
27
sp_cleanup.never_use_parentheses_in_expressions=true
28
sp_cleanup.on_save_use_additional_actions=true
29
sp_cleanup.organize_imports=false
30
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
31
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
32
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
33
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
34
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
35
sp_cleanup.remove_private_constructors=true
36
sp_cleanup.remove_trailing_whitespaces=true
37
sp_cleanup.remove_trailing_whitespaces_all=true
38
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
39
sp_cleanup.remove_unnecessary_casts=true
40
sp_cleanup.remove_unnecessary_nls_tags=false
41
sp_cleanup.remove_unused_imports=true
42
sp_cleanup.remove_unused_local_variables=false
43
sp_cleanup.remove_unused_private_fields=true
44
sp_cleanup.remove_unused_private_members=false
45
sp_cleanup.remove_unused_private_methods=true
46
sp_cleanup.remove_unused_private_types=true
47
sp_cleanup.sort_members=false
48
sp_cleanup.sort_members_all=false
49
sp_cleanup.use_anonymous_class_creation=false
50
sp_cleanup.use_blocks=false
51
sp_cleanup.use_blocks_only_for_return_and_throw=false
52
sp_cleanup.use_lambda=true
53
sp_cleanup.use_parentheses_in_expressions=false
54
sp_cleanup.use_this_for_non_static_field_access=false
55
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
56
sp_cleanup.use_this_for_non_static_method_access=false
57
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/expressions/ObjectConstructor.java
21 21
  *               Stephan Zimmerer (AIT)
22 22
  *               Markus Demetz (AIT)
23 23
  *               Christoph Czurda (AIT)
24
  *               Stefan Tiran (AIT)
24 25
  *
25 26
  */
26 27

  
......
32 33
import org.momut.ooas.ast.IAstVisitor;
33 34
import org.momut.ooas.ast.types.OoActionSystemInstance;
34 35
import org.momut.ooas.ast.types.OpaqueType;
36
import org.momut.ooas.ast.types.UlyssesType;
35 37

  
36 38
public final class ObjectConstructor extends TypeConstructionExpression
37 39
{
......
39 41
	private int m_currentInstance;
40 42
	private String m_fixedObjectName;
41 43

  
44
	private final String cleanup(String name) {
45
		if (name.startsWith("\"")) {
46
			name = name.substring(1, name.length()-1);
47
		}
48
		return name;
49
	}
50

  
42 51
	public int currentInstance() { return m_currentInstance; }
43 52
	public ArrayList<OoActionSystemInstance> instances() { return m_instances; }
44 53
	public String givenObjectName() { return m_fixedObjectName; }
......
59 68
		SetType(aType);
60 69
		m_instances = new ArrayList<OoActionSystemInstance>();
61 70
		m_currentInstance = 0;
62
		m_fixedObjectName = aName;
71
		m_fixedObjectName = cleanup(aName);
63 72
	}
64 73

  
74
	public ObjectConstructor(UlyssesType aType, String aName, int line, int pos)
75
	{
76
		super (ExpressionKind.ObjectConstr, line, pos);
77
		SetType(aType);
78
		m_instances = new ArrayList<OoActionSystemInstance>();
79
		m_currentInstance = 0;
80
		m_fixedObjectName = cleanup(aName);
81
	}
65 82

  
66 83
	public ObjectConstructor(ObjectConstructor toCopy)
67 84
	{
......
72 89
	}
73 90

  
74 91
	@Override
75
	public /*override*/ Expression Clone()
92
	public Expression Clone()
76 93
	{
77 94
		return new ObjectConstructor(this);
78 95
	}
79 96

  
80
	public /*override*/ void Accept(IAstVisitor visitor)
97
	@Override
98
	public void Accept(IAstVisitor visitor)
81 99
	{
82 100
		visitor.visit(this);
83 101
	}
......
89 107

  
90 108
	public OoActionSystemInstance GetNextInstance()
91 109
	{
92
		OoActionSystemInstance result = m_instances.get(m_currentInstance);
110
		final OoActionSystemInstance result = m_instances.get(m_currentInstance);
93 111
		m_currentInstance++;
94 112
		return result;
95 113
	}
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/expressions/UnresolvedIdentifierExpression.java
21 21
  *               Stephan Zimmerer (AIT)
22 22
  *               Markus Demetz (AIT)
23 23
  *               Christoph Czurda (AIT)
24
  *               Stefan Tiran (AIT)
24 25
  *
25 26
  */
26 27

  
......
58 59
		m_tokenText = toCopy.m_tokenText;
59 60
	}
60 61

  
62
	public UnresolvedIdentifierExpression(String name, IScope aScope)
63
	{
64
		super (null, 0, 0);
65
		m_kind = ExpressionKind.UnresolvedIdentifier;
66
		m_tokenText = name;
67
		m_scope = aScope;
68
	}
69

  
70

  
61 71
	@Override
62
	public /*override*/ Expression Clone()
72
	public Expression Clone()
63 73
	{
64 74
		return new UnresolvedIdentifierExpression(this);
65 75
	}
66 76

  
67
	public /*override*/ void Accept(IAstVisitor visitor)
77

  
78
	@Override
79
	public void Accept(IAstVisitor visitor)
68 80
	{
69 81
		visitor.visit(this);
70 82
	}
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/identifiers/AttributeIdentifier.java
21 21
  *               Stephan Zimmerer (AIT)
22 22
  *               Markus Demetz (AIT)
23 23
  *               Christoph Czurda (AIT)
24
  *               Stefan Tiran (AIT)
24 25
  *
25 26
  */
26 27

  
......
61 62
		m_isObservable = isObservable;
62 63
	}
63 64

  
65
	public AttributeIdentifier(String name,
66
			UlyssesType aType,
67
			IScope aDefiningScope,
68
			Expression anInitializer,
69
			boolean isStatic,
70
			boolean isObservable,
71
			boolean isControllable)
72
	{
73
		super(name, aType, IdentifierKind.AttributeIdentifier, aDefiningScope);
74
		m_initializer = anInitializer;
75
		m_isStatic = isStatic;
76
		m_isControllable = isControllable;
77
		m_isObservable = isObservable;
78
	}
79

  
64 80
	public AttributeIdentifier(AttributeIdentifier toCopy)
65 81
	{
66 82
		super(toCopy);
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/identifiers/EnumIdentifier.java
21 21
  *               Stephan Zimmerer (AIT)
22 22
  *               Markus Demetz (AIT)
23 23
  *               Christoph Czurda (AIT)
24
  *               Stefan Tiran (AIT)
24 25
  *
25 26
  */
26 27

  
......
49 50
		haveValue = false;
50 51
	}
51 52

  
53
	public EnumIdentifier(String range,
54
			EnumType aType,
55
			IScope aDefiningScope)
56
	{
57
		super(range, aType, IdentifierKind.EnumIdentifier, aDefiningScope);
58
		haveValue = false;
59
	}
52 60

  
53 61
	public EnumIdentifier(Token aToken,
54 62
			int aValue,
......
70 78

  
71 79

  
72 80
	@Override
73
	public /*override*/ Identifier Clone()
81
	public Identifier Clone()
74 82
	{
75 83
		return this;
76 84
	}
77 85

  
78
	public /*override*/ void Accept(IAstVisitor visitor)
86
	@Override
87
	public void Accept(IAstVisitor visitor)
79 88
	{
80 89
		visitor.visit(this);
81 90
	}
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/identifiers/FunctionIdentifier.java
21 21
  *               Stephan Zimmerer (AIT)
22 22
  *               Markus Demetz (AIT)
23 23
  *               Christoph Czurda (AIT)
24
  *               Stefan Tiran (AIT)
24 25
  *
25 26
  */
26 27

  
......
60 61
		m_parameter = new ArrayList<ParameterIdentifier>(toCopy.m_parameter);
61 62
	}
62 63

  
64
	public FunctionIdentifier(
65
			String name,
66
			UlyssesType aType,
67
			IdentifierKind aKind,
68
			IScope aDefiningScope)
69
	{
70
		super(name, aType, aKind, aDefiningScope);
71
	}
72

  
63 73
	public void SetBody(Statement body)
64 74
	{
65 75
		m_body = body;
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/identifiers/LocalVariableIdentifier.java
21 21
  *               Stephan Zimmerer (AIT)
22 22
  *               Markus Demetz (AIT)
23 23
  *               Christoph Czurda (AIT)
24
  *               Stefan Tiran (AIT)
24 25
  *
25 26
  */
26 27

  
......
42 43
		super (aToken, aType, IdentifierKind.LocalVariableIdentifier, aDefiningScope);
43 44
	}
44 45

  
46
	public LocalVariableIdentifier(String name,
47
			UlyssesType aType,
48
			IScope aDefiningScope)
49
	{
50
		super (name, aType, IdentifierKind.LocalVariableIdentifier, aDefiningScope);
51
	}
52

  
45 53
	public LocalVariableIdentifier(LocalVariableIdentifier toCopy)
46 54
	{
47 55
		super (toCopy);
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/identifiers/MethodIdentifier.java
21 21
  *               Stephan Zimmerer (AIT)
22 22
  *               Markus Demetz (AIT)
23 23
  *               Christoph Czurda (AIT)
24
  *               Stefan Tiran (AIT)
24 25
  *
25 26
  */
26 27

  
......
41 42
		super (aToken, aType, IdentifierKind.MethodIdentifier, aDefiningScope);
42 43
	}
43 44

  
45
	public MethodIdentifier(String aName,
46
			UlyssesType aType,
47
			IScope aDefiningScope)
48
	{
49
		super (aName, aType, IdentifierKind.MethodIdentifier, aDefiningScope);
50
	}
51

  
44 52
	public MethodIdentifier(MethodIdentifier toCopy)
45 53
	{
46 54
		super (toCopy);
47 55
	}
48 56

  
49 57
	@Override
50
	public /*override*/ Identifier Clone()
58
	public Identifier Clone()
51 59
	{
52 60
		return new MethodIdentifier(this);
53 61
	}
54 62

  
63
	@Override
55 64
	public /*override*/ void Accept(IAstVisitor visitor)
56 65
	{
57 66
		visitor.visit(this);
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/identifiers/NamedActionIdentifier.java
21 21
  *               Stephan Zimmerer (AIT)
22 22
  *               Markus Demetz (AIT)
23 23
  *               Christoph Czurda (AIT)
24
  *               Stefan Tiran (AIT)
24 25
  *
25 26
  */
26 27

  
......
41 42
		super (aToken, aType, IdentifierKind.NamedActionIdentifier, aDefiningScope);
42 43
	}
43 44

  
45
	public NamedActionIdentifier(String aName,
46
			UlyssesType aType,
47
			IScope aDefiningScope)
48
	{
49
		super (aName, aType, IdentifierKind.NamedActionIdentifier, aDefiningScope);
50
	}
51

  
44 52
	public NamedActionIdentifier(NamedActionIdentifier toCopy)
45 53
	{
46 54
		super (toCopy);
47 55
	}
48 56

  
49 57
	@Override
50
	public /*override*/ Identifier Clone()
58
	public Identifier Clone()
51 59
	{
52 60
		return new NamedActionIdentifier(this);
53 61
	}
54 62

  
55
	public /*override*/ void Accept(IAstVisitor visitor)
63
	@Override
64
	public void Accept(IAstVisitor visitor)
56 65
	{
57 66
		visitor.visit(this);
58 67
	}
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/identifiers/ValueIdentifier.java
21 21
  *               Stephan Zimmerer (AIT)
22 22
  *               Markus Demetz (AIT)
23 23
  *               Christoph Czurda (AIT)
24
  *               Stefan Tiran (AIT)
24 25
  *
25 26
  */
26 27

  
......
43 44
		super(aToken, aType, aKind, aDefiningScope);
44 45
	}
45 46

  
47
	public ValueIdentifier(String name,
48
			UlyssesType aType,
49
			IdentifierKind aKind,
50
			IScope aDefiningScope)
51
	{
52
		super(name, aType, aKind, aDefiningScope);
53
	}
54

  
46 55
	public ValueIdentifier(ValueIdentifier toCopy) { super(toCopy); }
47 56
}
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/AstBuilder.java
1
/**
2
  *
3
  *                      OOAS Compiler
4
  *
5
  *       Copyright 2015, AIT Austrian Institute of Technology.
6
  * This code is based on the C# Version of the OOAS Compiler, which is
7
  * copyright 2015 by the Institute of Software Technology, Graz University
8
  * of Technology with portions copyright by the AIT Austrian Institute of
9
  * Technology. All rights reserved.
10
  *
11
  * SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
12
  *
13
  * If you modify the file please update the list of contributors below to in-
14
  * clude your name. Please also stick to the coding convention of using TABs
15
  * to do the basic (block-level) indentation and spaces for anything after
16
  * that. (Enable the display of special chars and it should be pretty obvious
17
  * what this means.) Also, remove all trailing whitespace.
18
  *
19
  * Contributors:
20
  *               Stefan Tiran (AIT)
21
  *               Willibald Krenn (AIT)
22
  *
23
  */
24

  
25

  
26
package org.momut.ooas.ast;
27

  
28

  
29
import java.util.LinkedList;
30
import java.util.List;
31

  
32
import org.momut.ooas.ast.expressions.AccessExpression;
33
import org.momut.ooas.ast.expressions.CallExpression;
34
import org.momut.ooas.ast.expressions.Expression;
35
import org.momut.ooas.ast.expressions.IdentifierExpression;
36
import org.momut.ooas.ast.expressions.LeafExpression;
37
import org.momut.ooas.ast.expressions.ListConstructor;
38
import org.momut.ooas.ast.expressions.ObjectConstructor;
39
import org.momut.ooas.ast.expressions.UnresolvedIdentifierExpression;
40
import org.momut.ooas.ast.expressions.ValueExpression;
41
import org.momut.ooas.ast.identifiers.AttributeIdentifier;
42
import org.momut.ooas.ast.identifiers.EnumIdentifier;
43
import org.momut.ooas.ast.identifiers.Identifier;
44
import org.momut.ooas.ast.identifiers.IdentifierKind;
45
import org.momut.ooas.ast.identifiers.IdentifierList;
46
import org.momut.ooas.ast.identifiers.MainModule;
47
import org.momut.ooas.ast.identifiers.MethodIdentifier;
48
import org.momut.ooas.ast.identifiers.NamedActionIdentifier;
49
import org.momut.ooas.ast.identifiers.NondetIdentifierList;
50
import org.momut.ooas.ast.identifiers.ParameterIdentifier;
51
import org.momut.ooas.ast.identifiers.PrioIdentifierList;
52
import org.momut.ooas.ast.identifiers.SelfTypeIdentifier;
53
import org.momut.ooas.ast.identifiers.TypeIdentifier;
54
import org.momut.ooas.ast.statements.Assignment;
55
import org.momut.ooas.ast.statements.Block;
56
import org.momut.ooas.ast.statements.Call;
57
import org.momut.ooas.ast.statements.NondetBlock;
58
import org.momut.ooas.ast.statements.SeqBlock;
59
import org.momut.ooas.ast.statements.SkipStatement;
60
import org.momut.ooas.ast.statements.Statement;
61
import org.momut.ooas.ast.types.BoolType;
62
import org.momut.ooas.ast.types.EnumType;
63
import org.momut.ooas.ast.types.FunctionType;
64
import org.momut.ooas.ast.types.FunctionType.FunctionTypeEnum;
65
import org.momut.ooas.ast.types.IntType;
66
import org.momut.ooas.ast.types.ListType;
67
import org.momut.ooas.ast.types.OoActionSystemType;
68
import org.momut.ooas.ast.types.OpaqueType;
69
import org.momut.ooas.ast.types.UlyssesType;
70
import org.momut.ooas.parser.ParserError;
71
import org.momut.ooas.parser.ParserState;
72

  
73

  
74
public class AstBuilder {
75

  
76
	public static void setSystemDescription(MainModule mainModule, Identifier systemDescription) {
77
		final IdentifierList aDescr = new NondetIdentifierList();
78
		aDescr.AddElement(systemDescription);
79
		mainModule.SetSystemDescription(aDescr);
80
	}
81

  
82
	public static Identifier createPrioritizedSAB(LinkedList<Identifier> systems){
83
		final IdentifierList systemDescription = new PrioIdentifierList();
84
		for (final Identifier system : systems){
85
			systemDescription.AddElement(system);
86
		}
87
		return systemDescription;
88
	}
89

  
90
	public static Identifier createNonDetChoiceSAB(LinkedList<Identifier> systems){
91
		final IdentifierList systemDescription = new NondetIdentifierList();
92
		for (final Identifier system : systems){
93
			systemDescription.AddElement(system);
94
		}
95
		return systemDescription;
96
	}
97

  
98
	public static TypeIdentifier createActionSystem(boolean autocons, String name, IScope scope){
99
		final OoActionSystemType type = new OoActionSystemType(autocons, null, null);
100
		final SelfTypeIdentifier self = new SelfTypeIdentifier("self", type, scope);
101
		type.AddIdentifier(self, null);
102
		type.SetupAnonymousName(); // need to be called before setting the type identifier
103
		final TypeIdentifier ident = new TypeIdentifier(name, type, scope);
104

  
105
		type.SetTypeIdentifier(ident);
106
		scope.AddIdentifier(ident, null);
107

  
108
		return ident;
109
	}
110

  
111

  
112
	public static AttributeIdentifier createObjectAttribute(String varName, Identifier aClass, boolean doInstantiate, Identifier root){
113
		final UlyssesType aType = aClass.type();
114
		aType.SetupAnonymousName(); //not sure if necessary
115
		Expression anExpr;
116
		if (doInstantiate){
117
			anExpr = new ObjectConstructor(aType, varName, 0, 0);
118
		} else {
119
			anExpr = new ValueExpression<Object>(null, 0, 0, Object.class);
120
		}
121

  
122
		final AttributeIdentifier attributeIdentifier = new AttributeIdentifier(varName, aType, ((IScope)(root).type()), anExpr, false, false, false );
123
		((IScope)(root).type()).AddIdentifier(attributeIdentifier, null);
124

  
125
		return attributeIdentifier;
126
	}
127

  
128

  
129
	public static Expression boolConstant(boolean b){
130
		return new ValueExpression<Boolean>(b, 0, 0, Boolean.class);
131
	}
132

  
133
	public static ListType createListType(UlyssesType elemType, int max, TypeIdentifier anIdentifier){
134
		final ListType result = new ListType(elemType, max, null);
135
		result.SetupAnonymousName();
136
		result.SetTypeIdentifier(anIdentifier);
137
		return result;
138
	}
139

  
140
	public static EnumType createEnumType(String name, List<String> ranges, IScope scope){
141
		final EnumType type = new EnumType(null);
142

  
143
		EnumIdentifier enumval;
144
		for (final String range : ranges){
145
			enumval = new EnumIdentifier(range, type, scope);
146
			type.AddEnumSymbol(enumval);
147
			scope.AddIdentifier(enumval, null);
148
		}
149
		type.SetupAnonymousName();
150
		final TypeIdentifier ident = new TypeIdentifier(name, type, scope);
151

  
152
		type.SetTypeIdentifier(ident);
153
		scope.AddIdentifier(ident, null);
154
		return type;
155
	}
156

  
157

  
158
	public static UlyssesType createIntType(int low, int high){
159
		return new IntType(low, high, null);
160
	}
161

  
162
	public static AttributeIdentifier createListAttribute(String varname, ListType type, Identifier root){
163
		final Expression anExpr = new ListConstructor(0, 0);
164
		final AttributeIdentifier attributeIdentifier = new AttributeIdentifier(varname, type, ((IScope)(root).type()), anExpr, false, false, false );
165
		((IScope)(root).type()).AddIdentifier(attributeIdentifier, null);
166

  
167
		return attributeIdentifier;
168
	}
169

  
170
	public static AttributeIdentifier createEnumAttribute(String varname, EnumType type, String init, Identifier root){
171
		final Identifier initIdent = root.definingScope().ResolveIdentifier(init);
172
		final Expression anExpr = new IdentifierExpression(initIdent, 0, 0);
173
		final AttributeIdentifier attributeIdentifier = new AttributeIdentifier(varname, type, ((IScope)(root).type()), anExpr, false, false, false );
174
		((IScope)(root).type()).AddIdentifier(attributeIdentifier, null);
175

  
176
		return attributeIdentifier;
177
	}
178

  
179

  
180
	public static AttributeIdentifier createBoolAttribute(String varname, boolean isStatic, boolean init, Identifier root){
181
		final Expression anExpr = new ValueExpression<Boolean>(init, 0, 0, Boolean.class);
182
		final UlyssesType aType = new BoolType(null);
183
		aType.SetupAnonymousName();
184
		final AttributeIdentifier attributeIdentifier = new AttributeIdentifier(varname, aType, ((IScope)(root).type()), anExpr, isStatic, false, false );
185
		((IScope)(root).type()).AddIdentifier(attributeIdentifier, null);
186

  
187
		return attributeIdentifier;
188
	}
189

  
190
	public static AttributeIdentifier createAttribute(String varname, boolean isStatic, UlyssesType aType, Expression anExpr, IScope scope){
191
		final AttributeIdentifier attributeIdentifier = new AttributeIdentifier(varname, aType, scope, anExpr, isStatic, false, false );
192
		scope.AddIdentifier(attributeIdentifier, null);
193

  
194
		return attributeIdentifier;
195
	}
196

  
197
	public static MethodIdentifier createMethod(
198
			String name,
199
			LinkedList<ParameterIdentifier> params,
200
			UlyssesType returnType,
201
			Identifier as,
202
			Statement body
203
			) {
204
		final LinkedList<UlyssesType> parameterTypes = new LinkedList<UlyssesType>();
205
		for (final ParameterIdentifier param : params) {
206
			parameterTypes.add(param.type());
207
		}
208

  
209
		final FunctionType methodType = new FunctionType(FunctionType.FunctionTypeEnum.Method, parameterTypes, returnType);
210

  
211
		final MethodIdentifier ident = new MethodIdentifier(name, methodType, (IScope)as.type());
212
		((IScope)(as.type())).AddIdentifier(ident, null);
213
		ident.SetParentScope((IScope)as.type());
214
		ident.SetBody(body);
215

  
216
		for (final ParameterIdentifier p : params) {
217
			ident.AddParameter(p);
218
		}
219
		methodType.SetupAnonymousName();
220

  
221
		return ident;
222
	}
223

  
224
	public static NamedActionIdentifier createActionWithoutBody(
225
			FunctionType.FunctionTypeEnum functionType,
226
			String name,
227
			LinkedList<UlyssesType> parameters,
228
			Identifier as)
229
	{
230
		final FunctionType actionType = new FunctionType(functionType, parameters, null);
231
		actionType.SetupAnonymousName();
232
		final NamedActionIdentifier ident = new NamedActionIdentifier(name, actionType, (IScope)as.type());
233
		((IScope)(as.type())).AddIdentifier(ident, null);
234
		return ident;
235
	}
236

  
237
	public static Identifier createAction(
238
			FunctionType.FunctionTypeEnum functionType,
239
			String name,
240
			LinkedList<UlyssesType> parameters,
241
			Identifier as,
242
			Statement body)
243
	{
244
		final FunctionType actionType = new FunctionType(functionType, parameters, null);
245
		actionType.SetupAnonymousName();
246
		final NamedActionIdentifier ident = new NamedActionIdentifier(name, actionType, (IScope)as.type());
247
		((IScope)(as.type())).AddIdentifier(ident, null);
248
		ident.SetBody(body);
249
		return ident;
250
	}
251

  
252
	public static Block createNonDetBlock(LinkedList<Identifier> actions){
253
		final Block block = new NondetBlock(0, 0);
254

  
255
		for (final Identifier action : actions) {
256
			final Block block2 = new SeqBlock(0, 0);
257
			final CallExpression ce = new CallExpression(
258
					new IdentifierExpression(action,0,0),
259
					null,
260
					0,
261
					0,
262
					block
263
					);
264
			block2.AddStatement(new Call(ce, 0, 0));
265
			block.AddStatement(block2);
266
		}
267

  
268
		return block;
269
	}
270

  
271

  
272
	public static MainModule buildHelloWorld(){
273
		// == (1) define the main module, i.e. main scope ==
274
		final MainModule mainModule = new MainModule();
275

  
276
		// == (2) let's define the single action system type that is contained/defined in this main module ==
277
		final OoActionSystemType greeterType = new OoActionSystemType(
278
				true,      // let's suppose this is auto-constructing
279
				null,      // refines no other action system
280
				null       // type identifier is set below
281
		);
282
		greeterType.AddIdentifier(new SelfTypeIdentifier("self", greeterType, greeterType), null);
283
		greeterType.SetupAnonymousName(); // need to be called before setting the type identifier
284

  
285
		// -- instantiate the type identifier for our action system type --
286
		final TypeIdentifier greeterTypeIdentifier = new TypeIdentifier(
287
				"greeter",  // name
288
				greeterType,// bind it to the type
289
				mainModule  // scope where this is defined
290
		);
291
		// -- wire up the type identifier with the type (doubly linked therefore this more cumbersome two-call approach)
292
		greeterType.SetTypeIdentifier(greeterTypeIdentifier);
293
		mainModule.AddIdentifier(greeterTypeIdentifier, null);
294

  
295

  
296
		// == (3) define the sole observable action of the type ==
297
		// -- define the (implicitly declared type of the action) --lBlock
298
		final FunctionType helloWorldActionType = new FunctionType(  // this type is anonymous and doesn't have a name!
299
				FunctionTypeEnum.Observable,   // This is observable, hence an action
300
				new LinkedList<UlyssesType>(), // no parameters
301
				null                           // void return
302
		);
303
		helloWorldActionType.SetupAnonymousName(); // need to be called before setting the type identifier
304
		// -- define the actual identifier incl. impl. --
305
		final NamedActionIdentifier helloWorldActionIdentifier = new NamedActionIdentifier(
306
				"HelloWorld",           // name of the action
307
				helloWorldActionType,   // type of the action
308
				greeterType             // defining scope
309
		);
310
		// -- register the new identifier with the current scope
311
		greeterType.AddIdentifier(helloWorldActionIdentifier, null);
312
		// -- add implementation of the action
313
		//helloWorldActionIdentifier.SetBody(new SkipStatement(0, 0));
314
		helloWorldActionIdentifier.SetBody(new SkipStatement(0, 0));
315

  
316

  
317
		// == (4) define the do-od block of the action system type
318
		final Block greeterDoOdBlock = new SeqBlock(0, 0);
319
		greeterType.SetDoOdBlock(greeterDoOdBlock);
320
		// -- add a call statement to the dood block --
321
		final CallExpression callHelloWorldExpression = new CallExpression(
322
				new IdentifierExpression(helloWorldActionIdentifier, 0, 0),  // what to call
323
				null,             // arguments
324
				0,                // line
325
				0,                // col
326
				greeterDoOdBlock  // scope
327
		);
328
		greeterDoOdBlock.AddStatement(new Call(callHelloWorldExpression, 0, 0));
329

  
330

  
331
		// == (5) add scheduling information (SAB block) ==
332
		final IdentifierList systemDescription = new NondetIdentifierList();
333
		systemDescription.AddElement(greeterTypeIdentifier);
334
		mainModule.SetSystemDescription(systemDescription);
335

  
336
		return mainModule;
337
	}
338

  
339

  
340
	public static LeafExpression createIntConstant(Integer i)
341
	{
342
		return new ValueExpression<Integer>(i, 0, 0, Integer.class);
343
	}
344

  
345
	public static Expression createIdentifierAccessExpressionWithoutResolve(String name, IScope scope){
346
		final IdentifierExpression uIdent = new UnresolvedIdentifierExpression(name, scope);
347
		final IdentifierExpression aself = new IdentifierExpression(scope.ResolveIdentifier("self"), 0, 0);
348
		aself.setIsSelf(true);
349
		final AccessExpression exp = new AccessExpression(aself, uIdent, 0, 0);
350
		return exp;
351
	}
352

  
353
	public static Expression createIdentifierAccessExpression(Identifier attr){
354
		final IdentifierExpression uIdent = new IdentifierExpression(attr, 0, 0);
355

  
356
		final IdentifierExpression aself = new IdentifierExpression(attr.definingScope().ResolveIdentifier("self"), 0, 0);
357
		aself.setIsSelf(true);
358
		final AccessExpression exp = new AccessExpression(aself, uIdent, 0, 0);
359
		return exp;
360
	}
361

  
362
	public static CallExpression createMethodAccessExpression(Expression subexpr, List<Expression> m_params, IScope scope){
363
		return new CallExpression(subexpr, m_params, 0, 0, scope);
364
	}
365

  
366
	public static Statement createAssignment(AttributeIdentifier attr, ListConstructor lc) {
367
		return new Assignment(createIdentifierAccessExpression(attr), lc, null, 0, 0);
368
	}
369

  
370
	public static Statement createAssignment(Expression exp1, Expression exp2) {
371
		return new Assignment(exp1, exp2, null, 0, 0);
372
	}
373

  
374
	public static Statement createAssignment(AttributeIdentifier attr, boolean b) {
375
		return new Assignment(createIdentifierAccessExpression(attr), new ValueExpression<Boolean>(b, 0, 0, Boolean.class),null,0,0);
376
	}
377

  
378
	public static Statement createAssignment2(
379
			AttributeIdentifier attr, Identifier instance) {
380
		//FIXXME here be dragons
381
		return new Assignment(createIdentifierAccessExpression(attr), new IdentifierExpression(instance, 0, 0), null, 0, 0);
382
	}
383

  
384
	public static Statement createAssignmentWithoutResolve(String leftName, IScope leftScope, Expression right){
385
		return new Assignment(new UnresolvedIdentifierExpression(leftName, leftScope), right , null, 0, 0);
386
	}
387

  
388
	public static Statement createAssignmentWithoutResolve(String leftName, IScope leftScope, String rightName, IScope rightScope){
389
		return new Assignment(new UnresolvedIdentifierExpression(leftName, leftScope), new UnresolvedIdentifierExpression(rightName, rightScope), null, 0, 0);
390
	}
391

  
392
	public static Statement createAssignment(
393
			AttributeIdentifier attr, Identifier instance) {
394
		return new Assignment(createIdentifierAccessExpression(attr), createIdentifierAccessExpression(instance), null, 0, 0);
395
	}
396

  
397
	public static Expression createMethodAccessExpressionWithLocalVar(String objectName,
398
			String methodName, List<Expression> m_params, IScope scope) {
399
		final Expression subexpr = new AccessExpression(
400
				new UnresolvedIdentifierExpression(objectName, scope),
401
				new UnresolvedIdentifierExpression(methodName, scope),
402
				0,0);
403
		return new CallExpression(subexpr, m_params, 0, 0, scope);
404
	}
405

  
406

  
407
	public static Expression createMethodAccessExpressionWithoutResolveAtAll(String objectName,
408
			String methodName, List<Expression> m_params, IScope scope) {
409
		final UnresolvedIdentifierExpression modelSelf = new UnresolvedIdentifierExpression("self", scope);
410
		modelSelf.setIsSelf(true);
411

  
412
		final Expression subexpr = new AccessExpression(
413
				new AccessExpression(
414
						modelSelf,
415
						new UnresolvedIdentifierExpression(objectName, scope),
416
						0, 0),
417
				new UnresolvedIdentifierExpression(methodName, scope),
418
				0,0);
419
		return new CallExpression(subexpr, m_params, 0, 0, scope);
420
	}
421

  
422

  
423
	public static Statement createAssignment(Identifier attr,
424
			Identifier instance) {
425
		return new Assignment(createIdentifierAccessExpression(attr), createIdentifierAccessExpression(instance), null, 0, 0);
426
	}
427

  
428
	public static Statement createAssignment(Identifier attr,
429
			Expression exp) {
430
		return new Assignment(createIdentifierAccessExpression(attr), exp, null, 0, 0);
431
	}
432

  
433
	public static LeafExpression createNullPointerConstant()
434
	{
435
		return new ValueExpression<Object>(null, 0, 0, Object.class);
436
	}
437

  
438
	public static Expression intConstant(int i) {
439
		return new ValueExpression<Integer>(i, 0, 0, Integer.class);
440
	}
441

  
442
	public static void FixupNamedTypes(ParserState pState)
443
	{
444
		/*named type refs that could not be resolved in the first run, have to
445
		  be resolved now. */
446
		for (final OpaqueType ntype: pState.typesToFixUp)
447
		{
448
			if (ntype.resolvedType() == null)
449
			{
450
				//ntype.identifier
451
				final Identifier asym = pState.Lookup(ntype.identifier().tokenText(), ntype.identifier().definingScope());
452
				if ((asym == null) || (asym.kind() != IdentifierKind.TypeIdentifier))
453
				{
454
					final ParserError error = new ParserError(pState.filename, ntype.identifier().line(), ntype.identifier().column(),
455
							String.format("Can not resolve %s to a named type", ntype.identifier().tokenText()));
456
					pState.AddErrorMessage(error);
457
				}
458
				else
459
					ntype.SetResolvedType(asym.type());
460
			}
461
		}
462
		pState.typesToFixUp.clear();
463
	}
464

  
465

  
466
}
trunk/compiler/ooasCompiler/src/org/momut/ooas/codegen/java/JavaExpression.java
155 155
			return "!";
156 156

  
157 157
		case Cast:
158
			JavaType ctype = new JavaType();
158
			final JavaType ctype = new JavaType();
159 159
			expression.type().Accept(ctype);
160 160
			return String.format("(%s)", ctype.toString());
161 161

  
......
178 178
	{
179 179
		if (identifierExpression.identifier().kind() == IdentifierKind.LandmarkIdentifier)
180 180
		{
181
			LandmarkIdentifier lmid = (LandmarkIdentifier)identifierExpression.identifier();
182
			QrType qr = (QrType)lmid.type();
181
			final LandmarkIdentifier lmid = (LandmarkIdentifier)identifierExpression.identifier();
182
			final QrType qr = (QrType)lmid.type();
183 183
			m_emitter.Append(qr.landmarks().indexOf(lmid));
184 184
			return;
185 185
		}
......
205 205
	@Override
206 206
	public void visit(ObjectConstructor objectConstructor)
207 207
	{
208
		int num = m_data.m_constructors.size();
208
		final int num = m_data.m_constructors.size();
209 209
		m_data.m_constructors.add(objectConstructor);
210 210
		if (objectConstructor.givenObjectName() != null)
211
			m_emitter.Append(String.format("new %s(this,%s,%s)",
211
			m_emitter.Append(String.format("new %s(this,%s,\"%s\")",
212 212
					GetIdentifierString(objectConstructor.type().identifier().tokenText()),
213 213
					num,
214 214
					objectConstructor.givenObjectName()));
......
223 223
	{
224 224
		if (listConstructor.hasComprehension())
225 225
		{
226
			String helpername = String.format("list_constr_helper_%s", UnsignedHelper.toString(listConstructor.hashCode()));
226
			final String helpername = String.format("list_constr_helper_%s", UnsignedHelper.toString(listConstructor.hashCode()));
227 227
			m_emitter.Append(String.format("%s(new org.momut.ooas.codegen.java.runtime.CustomList<Object>())",
228 228
					helpername));
229
			OoasCodeEmitter helperEmitter = new OoasCodeEmitter();
229
			final OoasCodeEmitter helperEmitter = new OoasCodeEmitter();
230 230
			helperEmitter.AppendLine(String.format(
231 231
					"public org.momut.ooas.codegen.java.runtime.CustomList<Object> %s (org.momut.ooas.codegen.java.runtime.CustomList<Object> newList){",
232 232
					helpername));
233 233

  
234 234

  
235
			for (Identifier sym: listConstructor.comprehensionVariables().symbolList())
235
			for (final Identifier sym: listConstructor.comprehensionVariables().symbolList())
236 236
			{
237
				JavaType atype = new JavaType();
237
				final JavaType atype = new JavaType();
238 238
				sym.type().Accept(atype);
239 239

  
240 240
				if (sym.type().IsNumeric())
......
249 249
					throw new NotImplementedException();
250 250
			}
251 251

  
252
			StringBuilder helperhelper = new StringBuilder();
252
			final StringBuilder helperhelper = new StringBuilder();
253 253

  
254 254

  
255 255
			String guardexpr = "true";
256 256
			if (listConstructor.comprehension() != null)
257 257
			{
258
				JavaExpression expr = new JavaExpression(helperhelper, m_data);
258
				final JavaExpression expr = new JavaExpression(helperhelper, m_data);
259 259
				listConstructor.comprehension().Accept(expr);
260 260
				guardexpr = expr.toString();
261 261
			}
262 262

  
263
			JavaExpression expr2 = new JavaExpression(helperhelper, m_data);
263
			final JavaExpression expr2 = new JavaExpression(helperhelper, m_data);
264 264
			listConstructor.elements().get(0).Accept(expr2);
265 265

  
266 266
			helperEmitter.AppendLine(String.format("if (%s) {", guardexpr));
267 267
			helperEmitter.AppendLine(String.format("newList.Add(%s);", expr2.toString()));
268 268
			helperEmitter.AppendLine("}");
269 269

  
270
			int count = listConstructor.comprehensionVariables().symbolList().size();
270
			final int count = listConstructor.comprehensionVariables().symbolList().size();
271 271
			for (int i = 0; i< count; i++)
272 272
				helperEmitter.AppendLine("}");
273 273

  
......
283 283
			if (listConstructor.elements().size() > 0)
284 284
			{
285 285
				m_emitter.Append("new Object[] { ");
286
				for (Expression x: listConstructor.elements())
286
				for (final Expression x: listConstructor.elements())
287 287
				{
288 288
					if (i != 0)
289 289
						m_emitter.Append(",");
......
314 314
	{
315 315
		m_emitter.Append(String.format("new %s(", GetIdentifierString(tupleConstructor.tupleType().tokenText())));
316 316
		int i = 0;
317
		for (Expression arg: tupleConstructor.values())
317
		for (final Expression arg: tupleConstructor.values())
318 318
		{
319 319
			if (i != 0)
320 320
				m_emitter.Append(",");
......
328 328
	@Override
329 329
	public void visit(QValConstructor qValConstructor)
330 330
	{
331
		StringBuilder helpers = new StringBuilder();
331
		final StringBuilder helpers = new StringBuilder();
332 332

  
333 333
		String landmarkOne = "null";
334 334
		if (qValConstructor.value().length >= 1 && qValConstructor.value()[0] != null)
335 335
		{
336
			JavaExpression lndmrk1 = new JavaExpression(helpers, m_data);
336
			final JavaExpression lndmrk1 = new JavaExpression(helpers, m_data);
337 337
			qValConstructor.value()[0].Accept(lndmrk1);
338 338
			landmarkOne = lndmrk1.toString();
339 339
		}
340 340
		String landmarkTwo = "null";
341 341
		if (qValConstructor.value().length >= 2 && qValConstructor.value()[1] != null)
342 342
		{
343
			JavaExpression lndmrk = new JavaExpression(helpers, m_data);
343
			final JavaExpression lndmrk = new JavaExpression(helpers, m_data);
344 344
			qValConstructor.value()[1].Accept(lndmrk);
345 345
			landmarkTwo = lndmrk.toString();
346 346
		}

Also available in: Unified diff