Commit cccdb14e authored by Hernan Ponce de Leon's avatar Hernan Ponce de Leon
Browse files

Merge branch '3481-moduloOperator' into 'master'

3481 modulo operator

See merge request af3/af3!57
parents 6c62220d 419077e8
ArrayToCHeaderTransformation.java d656d0ff5ed03f108eb543d77789e7f0e4bbd21c GREEN
CReplacementVisitor.java 835e0b5d373e99a9d7f34c61f68b9643c7ada99e GREEN
CReplacementVisitor.java 44eadd0a6a257e6ce1d656e28016c0818f73c69f GREEN
DataDictionaryToCSourcePackageTransformation.java b15e9f1ae8b3d5ac18017a141607f93d0e6adb5e GREEN
EnumerationToCHeaderTransformation.java 99055f3848aad7b8fd9fd958ac7a837f44703b65 GREEN
FunctionDefinitionToCFunctionDeclarationTransformation.java 5e60a0edd88d602a0a524749ccdf8d6e22a8d885 GREEN
......
......@@ -15,7 +15,9 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.expression.generator.c;
import static org.fortiss.af3.expression.model.terms.EOperator.INDEX;
import static org.fortiss.af3.expression.model.terms.EOperator.MEMBER;
import static org.fortiss.af3.expression.model.terms.EOperator.MODULO;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.arrayAccess;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.assignment;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.createVar;
......@@ -34,7 +36,6 @@ import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.expression.generator.TermReplacementVisitor;
import org.fortiss.af3.expression.model.definitions.FunctionDefinition;
import org.fortiss.af3.expression.model.terms.ArrayConst;
import org.fortiss.af3.expression.model.terms.EOperator;
import org.fortiss.af3.expression.model.terms.FunctionCall;
import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.expression.model.terms.PredefinedFunction;
......@@ -63,17 +64,26 @@ public class CReplacementVisitor extends TermReplacementVisitor {
/** {@inheritDoc} */
@Override
protected ITerm applyToFunctionCall(FunctionCall call) {
if(call.getFunction() instanceof PredefinedFunction &&
EOperator.INDEX.equals(((PredefinedFunction)call.getFunction()).getOperator())) {
// get(0) to apply the replacement on the function itself
FunctionCall contentAccess =
structAccess((IExpressionTerm)applyInternal(call.getArguments().get(0)),
"content");
// get(1) to apply the replacement on the argument of the function
FunctionCall indexAccess =
arrayAccess(contentAccess, (IExpressionTerm)applyInternal(call.getArguments()
.get(1)));
return indexAccess;
if(call.getFunction() instanceof PredefinedFunction) {
if(INDEX.equals(((PredefinedFunction)call.getFunction()).getOperator())) {
// get(0) to apply the replacement on the function itself
FunctionCall contentAccess =
structAccess((IExpressionTerm)applyInternal(call.getArguments().get(0)),
"content");
// get(1) to apply the replacement on the argument of the function
FunctionCall indexAccess =
arrayAccess(contentAccess, (IExpressionTerm)applyInternal(call
.getArguments().get(1)));
return indexAccess;
}
if(MODULO.equals(((PredefinedFunction)call.getFunction()).getOperator())) {
// Change the modulo to fmod
FunctionCall fmod = funcCall("fmod");
// Modulo operator has 2 arguments.
fmod.getArguments().add(applyInternal(call.getArguments().get(0)));
fmod.getArguments().add(applyInternal(call.getArguments().get(1)));
return fmod;
}
}
return super.applyToFunctionCall(call);
}
......
......@@ -23,7 +23,8 @@ endif
# The flags which are passed to the compiler and the linker.
CCFLAGS+=-std=c99 -Wall -pedantic -c \${patsubst %,-I%,\${subst :, ,\${IPATH}}}
LDFLAGS+=-std=c99 -Wall -pedantic
LDFLAGS+=
LIBS+= -lm
# The default rules, i.e. the entry point.
all: \${BPATH}
......@@ -47,6 +48,6 @@ clean:
# The rule for linking an application.
\${BPATH}/%.run:
@echo "linking application '\${@}' ..."
@\${CROSSLD} \${LDFLAGS} -o \${@} \$(filter %.o %.a, \${^})
@\${CROSSLD} \${LDFLAGS} -o \${@} \$(filter %.o %.a, \${^}) \${LIBS}
>>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment