TelluIoT / ThingML

The ThingML modelling language
https://github.com/TelluIoT/ThingML
Apache License 2.0
102 stars 32 forks source link

Function call in property/variable initialization #141

Closed ffleurey closed 7 years ago

ffleurey commented 7 years ago

Seem to be be not understood properly by the checker (ClassCastException suspected)

brice-morin commented 7 years ago

Actually, the checker is not responsible. The problem is in the C compiler, where context.getConcreteThing() returns null...

public void generate(FunctionCallExpression expression, StringBuilder builder, Context ctx) {

        CCompilerContext context = (CCompilerContext) ctx;

        builder.append(context.getCName(expression.getFunction(), context.getConcreteThing()));

        builder.append("(_instance");
        for (Expression p : expression.getParameters()) {
            builder.append(", ");
            generate(p, builder, context);
        }
        builder.append(")");
    }
brice-morin commented 7 years ago

The dirty hack is:

        //FIXME: @ffleurey, @Lyadis this is a dirty hack... I get we should set the concreteThing in the context somewhere before...
        Thing concreteThing = context.getConcreteThing();
        if (concreteThing == null) {
            concreteThing = (Thing) expression.getFunction().eContainer();
        }
brice-morin commented 7 years ago

Seems like @Lyadis 's fix works 👍