Skip to content

Commit

Permalink
Merge pull request #9 from gbonnefille/master
Browse files Browse the repository at this point in the history
Fix stub generator
  • Loading branch information
freyssin authored May 31, 2017
2 parents 6a3c37e + a61fc0d commit 28f9d09
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions generator/src/main/java/fr/cnes/mo/stubgen/GeneratorC.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import esa.mo.tools.stubgen.StubUtils;
import esa.mo.tools.stubgen.specification.AttributeTypeDetails;
import esa.mo.tools.stubgen.specification.CompositeField;
import esa.mo.tools.stubgen.specification.InteractionPatternEnum;
import esa.mo.tools.stubgen.specification.OperationSummary;
import esa.mo.tools.stubgen.specification.ServiceSummary;
import esa.mo.tools.stubgen.specification.StdStrings;
Expand Down Expand Up @@ -3221,12 +3222,17 @@ private void addXregisterGenericFunction(OpStageContext opStageCtxt) throws IOEx

areaC.addStatement("int rc = 0;");

areaC.addStatement("mal_subscription_t *subscription = (mal_subscription_t *)arg->value.composite_value;");
if (opStageCtxt.opStage.equals("register"))
{
areaC.addStatement("mal_subscription_t *subscription = (mal_subscription_t *)arg->value.composite_value;");
} else {
areaC.addStatement("mal_identifier_list_t *subscription = (mal_identifier_list_t *)arg->value.list_value;");
}

areaC.addStatement("void *cursor = mal_encoder_new_cursor(encoder);");

areaC.addSingleLineComment("Length");
areaC.addStatement("rc = mal_register_add_encoding_length(encoder, subscription, cursor);");
areaC.addStatement("rc = mal_" + opStageCtxt.opStage + "_add_encoding_length(encoder, subscription, cursor);");
areaC.addStatement("if (rc < 0)", 1);
areaC.addStatement("return rc;", -1);

Expand All @@ -3243,7 +3249,7 @@ private void addXregisterGenericFunction(OpStageContext opStageCtxt) throws IOEx


areaC.addSingleLineComment("Encoding");
areaC.addStatement("rc = mal_register_encode(cursor, encoder, subscription);");
areaC.addStatement("rc = mal_" + opStageCtxt.opStage + "_encode(cursor, encoder, subscription);");
areaC.addStatement("if (rc < 0)", 1);
areaC.addStatement("return rc;", -1);

Expand Down Expand Up @@ -3818,7 +3824,9 @@ else if (paramDetails.isPresenceFlag)
// (element != NULL)
isPresent = "(element != NULL)";
}
addMalbinaryEncodingLengthPresenceFlag(areaC, isPresent);
if (opStageContext.opContext.operation.getPattern() != InteractionPatternEnum.PUBSUB_OP) {
addMalbinaryEncodingLengthPresenceFlag(areaC, isPresent);
} // No presence flag for PUBSUB notify
areaC.addStatement("if (" + isPresent + ")");
areaC.openBlock();
if (paramDetails.isAbstractAttribute)
Expand Down Expand Up @@ -4132,7 +4140,9 @@ else if (paramDetails.isPresenceFlag)
// bool presence_flag = (element != NULL);
areaC.addStatement("bool presence_flag = (element != NULL);");
}
addMalbinaryEncodingEncodePresenceFlag(areaC, "presence_flag");
if (opStageContext.opContext.operation.getPattern() != InteractionPatternEnum.PUBSUB_OP) {
addMalbinaryEncodingEncodePresenceFlag(areaC, "presence_flag");
} // No presence flag for PUBSUB notify
areaC.addStatement("if (presence_flag)");
areaC.openBlock();
if (paramDetails.isAbstractAttribute)
Expand Down Expand Up @@ -4411,7 +4421,12 @@ else if (paramDetails.isPresenceFlag)
areaC.openBlock();
// use a local variable as the flag should not be set while the element has not been successfully decoded
areaC.addStatement("bool presence_flag;");
addMalbinaryEncodingDecodePresenceFlag(areaC, "presence_flag");
if (opStageContext.opContext.operation.getPattern() == InteractionPatternEnum.PUBSUB_OP) {
// There is no nullable argument in PUBSUB notify
areaC.addStatement("presence_flag = true;");
} else {
addMalbinaryEncodingDecodePresenceFlag(areaC, "presence_flag");
}
areaC.addStatement("if (presence_flag)");
areaC.openBlock();
if (paramDetails.isAbstract)
Expand Down Expand Up @@ -4917,7 +4932,9 @@ private void generatePubSubEncodingRelatedParameters(OperationContext opContext,
generatePubSubEncodingRelatedParameters(opStageCtxt);
}

//generate all PubSub encoding code related to the parameters
/*
* generate all PubSub encoding code related to the parameters
*/
private void generatePubSubEncodingRelatedParameters(OpStageContext opStageCtxt) throws IOException {
// generate all encoding code related to the parameters
List<TypeInfo> parameters = opStageCtxt.parameters;
Expand Down Expand Up @@ -4951,7 +4968,8 @@ private void generatePubSubEncodingRelatedParameters(OpStageContext opStageCtxt)
throw new IllegalArgumentException("illegal list type " + paramType.toString() + " for parameter " + param.getFieldName() + " in operation " + opStageCtxt.qfOpStageNameL);
}
paramType.setList(true);

paramDetails.isList = true;

if (isAbstract(paramType))
{
paramDetails.isAbstract = true;
Expand Down

0 comments on commit 28f9d09

Please sign in to comment.