Search in sources :

Example 11 with ParseException

use of com.eprosima.idl.parser.exception.ParseException in project ihmc-pub-sub by ihmcrobotics.

the class IDLParser method op_decl.

public final Op_declContext op_decl(Vector<Annotation> annotations) throws RecognitionException {
    Op_declContext _localctx = new Op_declContext(_ctx, getState(), annotations);
    enterRule(_localctx, 196, RULE_op_decl);
    Operation operationObject = null;
    TemplateGroup operationTemplates = null;
    if (tmanager != null) {
        operationTemplates = tmanager.createTemplateGroup("operation");
    }
    TemplateGroup tpl = null;
    String name = "";
    Token tk = null, tkoneway = null;
    TypeCode retType = null;
    Vector<Pair<String, Token>> exceptions = null;
    int _la;
    try {
        enterOuterAlt(_localctx, 1);
        {
            setState(1183);
            _la = _input.LA(1);
            if (_la == KW_ONEWAY) {
                {
                    setState(1180);
                    ((Op_declContext) _localctx).op_attribute = op_attribute();
                    tkoneway = ((Op_declContext) _localctx).op_attribute.token;
                }
            }
            setState(1185);
            ((Op_declContext) _localctx).op_type_spec = op_type_spec();
            retType = ((Op_declContext) _localctx).op_type_spec.typecode;
            tk = _input.LT(1);
            name += tk.getText();
            setState(1188);
            match(ID);
            // Create the Operation object.
            operationObject = ctx.createOperation(name, tk);
            // Add annotations.
            for (Annotation annotation : annotations) operationObject.addAnnotation(ctx, annotation);
            if (operationTemplates != null) {
                operationTemplates.setAttribute("ctx", ctx);
                // Set the the interface object to the TemplateGroup of the module.
                operationTemplates.setAttribute("operation", operationObject);
            }
            // Set return type
            operationObject.setRettype(retType);
            // Set oneway
            if (tkoneway != null) {
                operationObject.setOneway(true);
                if (retType != null) {
                    throw new ParseException(tkoneway, ". Oneway function cannot have a return type.");
                }
            }
            setState(1190);
            ((Op_declContext) _localctx).parameter_decls = parameter_decls(operationObject);
            tpl = ((Op_declContext) _localctx).parameter_decls.tpl;
            setState(1196);
            _la = _input.LA(1);
            if (_la == KW_RAISES) {
                {
                    setState(1192);
                    ((Op_declContext) _localctx).raises_expr = raises_expr();
                    exceptions = ((Op_declContext) _localctx).raises_expr.exlist;
                    // Search global exceptions and add them to the operation.
                    for (Pair<String, Token> pair : exceptions) {
                        com.eprosima.idl.parser.tree.Exception exception = ctx.getException(pair.first());
                        if (exception != null)
                            operationObject.addException(exception);
                        else
                            operationObject.addUnresolvedException(pair.first());
                    }
                }
            }
            setState(1199);
            _la = _input.LA(1);
            if (_la == KW_CONTEXT) {
                {
                    setState(1198);
                    context_expr();
                }
            }
            if (operationTemplates != null) {
                // Store the parameter list template group in the operation template group.
                operationTemplates.setAttribute("param_list", tpl);
            }
            // Create the returned data.
            ((Op_declContext) _localctx).returnPair = new Pair<Operation, TemplateGroup>(operationObject, operationTemplates);
        }
    } catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    } finally {
        exitRule();
    }
    return _localctx;
}
Also used : org.antlr.v4.runtime.tree(org.antlr.v4.runtime.tree) com.eprosima.idl.parser.tree(com.eprosima.idl.parser.tree) TemplateGroup(com.eprosima.idl.generator.manager.TemplateGroup) ParseException(com.eprosima.idl.parser.exception.ParseException) Pair(com.eprosima.idl.util.Pair)

Aggregations

ParseException (com.eprosima.idl.parser.exception.ParseException)11 Pair (com.eprosima.idl.util.Pair)2 ArrayList (java.util.ArrayList)2 TemplateGroup (com.eprosima.idl.generator.manager.TemplateGroup)1 com.eprosima.idl.parser.tree (com.eprosima.idl.parser.tree)1 org.antlr.v4.runtime.tree (org.antlr.v4.runtime.tree)1