Project

General

Profile

Revision 8

Added by Willibald K. over 8 years ago

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

View differences:

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