io.sarl.lang.compiler
Class SarlCompiler
class SarlCompiler
extends java.lang.Object
The compiler from SARL to the target language.

This compiler provide a specific support for inline annotations. Indeed, the Xbase inline evaluation does not support variadic parameters. This SARL compiler provides a support for variadic feature calls.

Additionally, this compiler supports the Inline annotation for non-static calls, by skipping the left operand of a member feature call when the inline expression is constant. See https://github.com/eclipse/xtext-extras/pull/62.

This compiler supports also the "$0" parameter in inline expression. This parameter represents the current receiver, e.g. "this.".

The compiler supports the SARL keywords: break.

This compiler catches exceptions when generating statements for expressions in order to let the compiler to generate as much as possible.

The compiler adds a return statement when the early exit statement in SARL is not an early exist statement in Java. In this case a Java "return" statement must be added implicitly.

The roles of the different generation tools are:
Maven Group Identifier:
io.sarl.lang
Maven Artifact Identifier:
compiler
Since:
0.4
Constructor Summary
Constructor and description
new
Action Summary
Modifier and type Action and description
protected void _toJavaExpression(SarlAssertExpression,ITreeAppendable)
Generate the Java code related to the expression for the assert keyword.
protected void _toJavaExpression(SarlBreakExpression,ITreeAppendable)
Generate the Java code related to the expression for the break keyword.
protected void _toJavaExpression(SarlContinueExpression,ITreeAppendable)
Generate the Java code related to the expression for the continue keyword.
protected void _toJavaExpression(XCastedExpression,ITreeAppendable)
protected void _toJavaStatement(SarlAssertExpression,ITreeAppendable,boolean)
Generate the Java code to the preparation statements for the assert keyword.
protected void _toJavaStatement(SarlBreakExpression,ITreeAppendable,boolean)
Generate the Java code related to the preparation statements for the break keyword.
protected void _toJavaStatement(SarlContinueExpression,ITreeAppendable,boolean)
Generate the Java code related to the preparation statements for the break keyword.
protected void _toJavaStatement(XCastedExpression,ITreeAppendable,boolean)
protected void _toJavaStatement(XClosure,ITreeAppendable,boolean)
protected void appendInlineFeatureCall(XAbstractFeatureCall,ITreeAppendable)
protected boolean canBeNotStaticAnonymousClass(XClosure,LightweightTypeReference,JvmOperation)
Replies if the given closure could be represented by an not static anonymous class.
protected boolean canCompileToJavaLambda(XClosure,LightweightTypeReference,JvmOperation)
org.eclipse.xtext.xbase.compiler.output.ITreeAppendable compile(XExpression,ITreeAppendable,LightweightTypeReference,Set<E>)
protected void doConversion(LightweightTypeReference,LightweightTypeReference,ITreeAppendable,XExpression,Later)
void doInternalToJavaStatement(XExpression,ITreeAppendable,boolean)
protected java.util.Map<K,V> getReferencedLocalVariable(XExpression,boolean)
Replies all the variables that are referenced into the given expression.
protected boolean internalCanCompileToJavaExpression(XExpression,ITreeAppendable)
void internalToConvertedExpression(XExpression,ITreeAppendable)
protected boolean isAtLeastJava8(EObject)
Replies if the generation is for Java version 8 at least.
protected boolean isEarlyExit(XExpression)
protected boolean isReferenceToIt(XFeatureCall)
Replies if the given feature call has an implicit reference to the it variable.
protected boolean isVariableDeclarationRequired(XExpression,ITreeAppendable,boolean)
protected void jvmOperationCallToJavaExpression(XExpression,JvmOperation,XExpression,List<E>,ITreeAppendable)
Generate the Java expression for the given JVM operation.
protected void logInternalError(Throwable)
Log an internal error but do not fail.
protected void prepareExpression(XExpression,ITreeAppendable)
protected org.eclipse.xtext.xbase.compiler.output.ITreeAppendable toAnonymousClass(XClosure,ITreeAppendable,LightweightTypeReference,JvmOperation)
Constructor Details
new
new
Action Details
_toJavaExpression(SarlAssertExpression,ITreeAppendable)
protected def _toJavaExpression(SarlAssertExpression,ITreeAppendable)
Generate the Java code related to the expression for the assert keyword.
Parameters:
assertExpression - the expression.
appendable - the output.
_toJavaExpression(SarlBreakExpression,ITreeAppendable)
protected def _toJavaExpression(SarlBreakExpression,ITreeAppendable)
Generate the Java code related to the expression for the break keyword.
Parameters:
breakExpression - the expression.
appendable - the output.
_toJavaExpression(SarlContinueExpression,ITreeAppendable)
protected def _toJavaExpression(SarlContinueExpression,ITreeAppendable)
Generate the Java code related to the expression for the continue keyword.
Parameters:
breakExpression - the expression.
appendable - the output.
Since:
0.7
_toJavaExpression(XCastedExpression,ITreeAppendable)
protected def _toJavaExpression(XCastedExpression,ITreeAppendable)
_toJavaStatement(SarlAssertExpression,ITreeAppendable,boolean)
protected def _toJavaStatement(SarlAssertExpression,ITreeAppendable,boolean)
Generate the Java code to the preparation statements for the assert keyword.
Parameters:
assertExpression - the expression.
appendable - the output.
isReferenced - indicates if the expression is referenced.
_toJavaStatement(SarlBreakExpression,ITreeAppendable,boolean)
protected def _toJavaStatement(SarlBreakExpression,ITreeAppendable,boolean)
Generate the Java code related to the preparation statements for the break keyword.
Parameters:
breakExpression - the expression.
appendable - the output.
isReferenced - indicates if the expression is referenced.
_toJavaStatement(SarlContinueExpression,ITreeAppendable,boolean)
protected def _toJavaStatement(SarlContinueExpression,ITreeAppendable,boolean)
Generate the Java code related to the preparation statements for the break keyword.
Parameters:
breakExpression - the expression.
appendable - the output.
isReferenced - indicates if the expression is referenced.
Since:
0.7
_toJavaStatement(XCastedExpression,ITreeAppendable,boolean)
protected def _toJavaStatement(XCastedExpression,ITreeAppendable,boolean)
_toJavaStatement(XClosure,ITreeAppendable,boolean)
protected def _toJavaStatement(XClosure,ITreeAppendable,boolean)
appendInlineFeatureCall(XAbstractFeatureCall,ITreeAppendable)
protected def appendInlineFeatureCall(XAbstractFeatureCall,ITreeAppendable)
canBeNotStaticAnonymousClass(XClosure,LightweightTypeReference,JvmOperation)
protected def canBeNotStaticAnonymousClass(XClosure,LightweightTypeReference,JvmOperation) : boolean
Replies if the given closure could be represented by an not static anonymous class.
Parameters:
closure - the closure.
typeRef - the type of the closure.
operation - the operation to implement.
Returns:
true if the given closure could be represented by a not-static anonymous class.
Since:
0.8.6
canCompileToJavaLambda(XClosure,LightweightTypeReference,JvmOperation)
protected def canCompileToJavaLambda(XClosure,LightweightTypeReference,JvmOperation) : boolean
compile(XExpression,ITreeAppendable,LightweightTypeReference,Set<E>)
def compile(XExpression,ITreeAppendable,LightweightTypeReference,Set<E>) : org.eclipse.xtext.xbase.compiler.output.ITreeAppendable
doConversion(LightweightTypeReference,LightweightTypeReference,ITreeAppendable,XExpression,Later)
protected def doConversion(LightweightTypeReference,LightweightTypeReference,ITreeAppendable,XExpression,Later)
doInternalToJavaStatement(XExpression,ITreeAppendable,boolean)
def doInternalToJavaStatement(XExpression,ITreeAppendable,boolean)
getReferencedLocalVariable(XExpression,boolean)
protected def getReferencedLocalVariable(XExpression,boolean) : java.util.Map<K,V>
Replies all the variables that are referenced into the given expression.
Parameters:
expression - the expression.
onlyWritable - if true only the writable variables are replied. Otherwise, all variables are replied.
Returns:
the referenced variables.
internalCanCompileToJavaExpression(XExpression,ITreeAppendable)
protected def internalCanCompileToJavaExpression(XExpression,ITreeAppendable) : boolean
internalToConvertedExpression(XExpression,ITreeAppendable)
def internalToConvertedExpression(XExpression,ITreeAppendable)
isAtLeastJava8(EObject)
protected def isAtLeastJava8(EObject) : boolean
Replies if the generation is for Java version 8 at least.
Parameters:
context - the context.
Returns:
true if Java 8 or newer.
isEarlyExit(XExpression)
protected def isEarlyExit(XExpression) : boolean
isReferenceToIt(XFeatureCall)
protected def isReferenceToIt(XFeatureCall) : boolean
Replies if the given feature call has an implicit reference to the it variable.
Parameters:
featureCall - the feature call to test.
Returns:
true if the given feature call has an implicit reference to the it variable.
Since:
0.9
isVariableDeclarationRequired(XExpression,ITreeAppendable,boolean)
protected def isVariableDeclarationRequired(XExpression,ITreeAppendable,boolean) : boolean
jvmOperationCallToJavaExpression(XExpression,JvmOperation,XExpression,List<E>,ITreeAppendable)
protected def jvmOperationCallToJavaExpression(XExpression,JvmOperation,XExpression,List<E>,ITreeAppendable)
Generate the Java expression for the given JVM operation.
Parameters:
sourceObject - the object into the source tree that is the source for the call.
operation - the JVM operation to call.
receiver - the receiver of the call.
arguments - the arguments to pass to the called operation.
appendable - the receiver of the Java code.
logInternalError(Throwable)
protected def logInternalError(Throwable)
Log an internal error but do not fail.
Parameters:
exception - the exception to log.
prepareExpression(XExpression,ITreeAppendable)
protected def prepareExpression(XExpression,ITreeAppendable)
toAnonymousClass(XClosure,ITreeAppendable,LightweightTypeReference,JvmOperation)
protected def toAnonymousClass(XClosure,ITreeAppendable,LightweightTypeReference,JvmOperation) : org.eclipse.xtext.xbase.compiler.output.ITreeAppendable