Search in sources :

Example 6 with Pair

use of com.eprosima.idl.util.Pair in project ihmc-pub-sub by ihmcrobotics.

the class IDLParser method enum_type.

public final Enum_typeContext enum_type() throws RecognitionException {
    Enum_typeContext _localctx = new Enum_typeContext(_ctx, getState());
    enterRule(_localctx, 174, RULE_enum_type);
    String name = null;
    Vector<TypeCode> vector = null;
    EnumTypeCode enumTP = null;
    TemplateGroup enumTemplates = null;
    try {
        enterOuterAlt(_localctx, 1);
        {
            setState(1081);
            match(KW_ENUM);
            setState(1082);
            ((Enum_typeContext) _localctx).identifier = identifier();
            name = ((Enum_typeContext) _localctx).identifier.id;
            enumTP = new EnumTypeCode(ctx.getScope(), name);
            setState(1084);
            match(LEFT_BRACE);
            setState(1085);
            enumerator_list(enumTP);
            setState(1086);
            match(RIGHT_BRACE);
            if (ctx.isInScopedFile() || ctx.isScopeLimitToAll()) {
                if (tmanager != null) {
                    enumTemplates = tmanager.createTemplateGroup("enum_type");
                    enumTemplates.setAttribute("ctx", ctx);
                    enumTemplates.setAttribute("enum", enumTP);
                }
            }
            // Return the returned data.
            vector = new Vector<TypeCode>();
            vector.add(enumTP);
            ((Enum_typeContext) _localctx).returnPair = new Pair<Vector<TypeCode>, TemplateGroup>(vector, enumTemplates);
        }
    } catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    } finally {
        exitRule();
    }
    return _localctx;
}
Also used : TemplateGroup(com.eprosima.idl.generator.manager.TemplateGroup) Vector(java.util.Vector) Pair(com.eprosima.idl.util.Pair)

Example 7 with Pair

use of com.eprosima.idl.util.Pair in project ihmc-pub-sub by ihmcrobotics.

the class IDLParser method interface_decl.

public final Interface_declContext interface_decl(Vector<Annotation> annotations) throws RecognitionException {
    Interface_declContext _localctx = new Interface_declContext(_ctx, getState(), annotations);
    enterRule(_localctx, 12, RULE_interface_decl);
    Token tk = null;
    Interface interfaceObject = null;
    TemplateGroup interfaceTemplates = null;
    TemplateGroup tg = null;
    String name = null, old_scope = ctx.getScope();
    int _la;
    try {
        enterOuterAlt(_localctx, 1);
        {
            {
                setState(399);
                _la = _input.LA(1);
                if (_la == KW_ABSTRACT || _la == KW_LOCAL) {
                    {
                        setState(398);
                        _la = _input.LA(1);
                        if (!(_la == KW_ABSTRACT || _la == KW_LOCAL)) {
                            _errHandler.recoverInline(this);
                        }
                        consume();
                    }
                }
                {
                    setState(401);
                    match(KW_INTERFACE);
                }
                tk = _input.LT(1);
                setState(403);
                ((Interface_declContext) _localctx).identifier = identifier();
                name = ((Interface_declContext) _localctx).identifier.id;
                // Create the Interface object.
                interfaceObject = ctx.createInterface(name, tk);
                // Add annotations.
                for (Annotation annotation : annotations) interfaceObject.addAnnotation(ctx, annotation);
                if (ctx.isInScopedFile() || ctx.isScopeLimitToAll()) {
                    if (tmanager != null) {
                        interfaceTemplates = tmanager.createTemplateGroup("interface");
                        interfaceTemplates.setAttribute("ctx", ctx);
                        // Set the the interface object to the TemplateGroup of the module.
                        interfaceTemplates.setAttribute("interface", interfaceObject);
                    }
                }
                // Update to a new namespace.
                if (old_scope.isEmpty())
                    ctx.setScope(name);
                else
                    ctx.setScope(old_scope + "::" + name);
                setState(406);
                _la = _input.LA(1);
                if (_la == COLON) {
                    {
                        setState(405);
                        interface_inheritance_spec(interfaceObject);
                    }
                }
                setState(408);
                match(LEFT_BRACE);
                setState(409);
                ((Interface_declContext) _localctx).interface_body = interface_body(interfaceObject);
                tg = ((Interface_declContext) _localctx).interface_body.elTemplates;
                if (interfaceTemplates != null && tg != null)
                    interfaceTemplates.setAttribute("export_list", tg);
                setState(411);
                match(RIGHT_BRACE);
            }
            // Set the old namespace.
            ctx.setScope(old_scope);
            // Create the returned data.
            ((Interface_declContext) _localctx).returnPair = new Pair<Interface, TemplateGroup>(interfaceObject, interfaceTemplates);
        }
    } catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    } finally {
        exitRule();
    }
    return _localctx;
}
Also used : TemplateGroup(com.eprosima.idl.generator.manager.TemplateGroup) Pair(com.eprosima.idl.util.Pair)

Example 8 with Pair

use of com.eprosima.idl.util.Pair in project ihmc-pub-sub by ihmcrobotics.

the class IDLParser method interface_inheritance_spec.

public final Interface_inheritance_specContext interface_inheritance_spec(Interface interfaceObject) throws RecognitionException {
    Interface_inheritance_specContext _localctx = new Interface_inheritance_specContext(_ctx, getState(), interfaceObject);
    enterRule(_localctx, 22, RULE_interface_inheritance_spec);
    Vector<Pair<String, Token>> iflist = null;
    try {
        enterOuterAlt(_localctx, 1);
        {
            setState(465);
            match(COLON);
            setState(466);
            ((Interface_inheritance_specContext) _localctx).scoped_name_list = scoped_name_list();
            iflist = ((Interface_inheritance_specContext) _localctx).scoped_name_list.retlist;
            for (Pair<String, Token> pair : iflist) {
                Interface base = ctx.getInterface(pair.first());
                if (base != null) {
                    if (!_localctx.interfaceObject.addBase(base))
                        throw new ParseException(pair.second(), " is duplicated.");
                } else {
                    throw new ParseException(pair.second(), "was not defined previously");
                }
            }
        }
    } catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    } finally {
        exitRule();
    }
    return _localctx;
}
Also used : ParseException(com.eprosima.idl.parser.exception.ParseException) Pair(com.eprosima.idl.util.Pair)

Example 9 with Pair

use of com.eprosima.idl.util.Pair 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)

Example 10 with Pair

use of com.eprosima.idl.util.Pair in project ihmc-pub-sub by ihmcrobotics.

the class IDLParser method except_decl.

public final Except_declContext except_decl() throws RecognitionException {
    Except_declContext _localctx = new Except_declContext(_ctx, getState());
    enterRule(_localctx, 192, RULE_except_decl);
    String name = null;
    com.eprosima.idl.parser.tree.Exception exceptionObject = null;
    TemplateGroup exTemplates = null;
    Token tk = null;
    try {
        enterOuterAlt(_localctx, 1);
        {
            setState(1162);
            match(KW_EXCEPTION);
            tk = _input.LT(1);
            setState(1164);
            ((Except_declContext) _localctx).identifier = identifier();
            name = ((Except_declContext) _localctx).identifier.id;
            // Create the Exception object.
            exceptionObject = ctx.createException(name, tk);
            if (ctx.isInScopedFile() || ctx.isScopeLimitToAll()) {
                if (tmanager != null) {
                    exTemplates = tmanager.createTemplateGroup("exception");
                    exTemplates.setAttribute("ctx", ctx);
                    // Set the the exception object to the TemplateGroup of the module.
                    exTemplates.setAttribute("exception", exceptionObject);
                }
            } else // Its a dependency.
            {
                ctx.addIncludeDependency(ctx.getScopeFile());
            }
            setState(1167);
            match(LEFT_BRACE);
            setState(1168);
            opt_member_list(exceptionObject);
            setState(1169);
            match(RIGHT_BRACE);
            // Create the returned data.
            ((Except_declContext) _localctx).returnPair = new Pair<com.eprosima.idl.parser.tree.Exception, TemplateGroup>(exceptionObject, exTemplates);
        }
    } catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    } finally {
        exitRule();
    }
    return _localctx;
}
Also used : TemplateGroup(com.eprosima.idl.generator.manager.TemplateGroup) org.antlr.v4.runtime.tree(org.antlr.v4.runtime.tree) com.eprosima.idl.parser.tree(com.eprosima.idl.parser.tree) Pair(com.eprosima.idl.util.Pair)

Aggregations

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