Search in sources :

Example 1 with Pair

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

the class IDLParser method union_type.

public final Union_typeContext union_type() throws RecognitionException {
    Union_typeContext _localctx = new Union_typeContext(_ctx, getState());
    enterRule(_localctx, 162, RULE_union_type);
    String name = null;
    int line = 0;
    TypeCode dist_type = null;
    Vector<TypeCode> vector = null;
    UnionTypeCode unionTP = null;
    TemplateGroup unionTemplates = null;
    try {
        enterOuterAlt(_localctx, 1);
        {
            setState(1025);
            match(KW_UNION);
            setState(1026);
            ((Union_typeContext) _localctx).identifier = identifier();
            name = ((Union_typeContext) _localctx).identifier.id;
            setState(1028);
            match(KW_SWITCH);
            setState(1029);
            match(LEFT_BRACKET);
            setState(1030);
            ((Union_typeContext) _localctx).switch_type_spec = switch_type_spec();
            dist_type = ((Union_typeContext) _localctx).switch_type_spec.typecode;
            setState(1032);
            match(RIGHT_BRACKET);
            // TODO Check supported types for discriminator: long, enumeration, etc...
            unionTP = new UnionTypeCode(ctx.getScope(), name, dist_type);
            line = _input.LT(1) != null ? _input.LT(1).getLine() - ctx.getCurrentIncludeLine() : 1;
            setState(1034);
            match(LEFT_BRACE);
            setState(1035);
            switch_body(unionTP);
            setState(1036);
            match(RIGHT_BRACE);
            // Calculate default label.
            TemplateUtil.setUnionDefaultLabel(unionTP, ctx.getScopeFile(), line);
            if (ctx.isInScopedFile() || ctx.isScopeLimitToAll()) {
                if (tmanager != null) {
                    unionTemplates = tmanager.createTemplateGroup("union_type");
                    unionTemplates.setAttribute("ctx", ctx);
                    unionTemplates.setAttribute("union", unionTP);
                }
            }
            // Return the returned data.
            vector = new Vector<TypeCode>();
            vector.add(unionTP);
            ((Union_typeContext) _localctx).returnPair = new Pair<Vector<TypeCode>, TemplateGroup>(vector, unionTemplates);
        }
    } 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 2 with Pair

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

the class IDLParser method param_decl.

public final Param_declContext param_decl() throws RecognitionException {
    Param_declContext _localctx = new Param_declContext(_ctx, getState());
    enterRule(_localctx, 206, RULE_param_decl);
    TemplateGroup paramTemplate = null;
    if (tmanager != null) {
        paramTemplate = tmanager.createTemplateGroup("param");
    }
    TypeCode typecode = null;
    String literalStr = _input.LT(1).getText();
    int _la;
    try {
        enterOuterAlt(_localctx, 1);
        {
            setState(1231);
            _la = _input.LA(1);
            if (!(((((_la - 39)) & ~0x3f) == 0 && ((1L << (_la - 39)) & ((1L << (KW_OUT - 39)) | (1L << (KW_IN - 39)) | (1L << (KW_INOUT - 39)))) != 0))) {
                _errHandler.recoverInline(this);
            }
            consume();
            setState(1232);
            ((Param_declContext) _localctx).param_type_spec = param_type_spec();
            typecode = ((Param_declContext) _localctx).param_type_spec.typecode;
            setState(1234);
            ((Param_declContext) _localctx).simple_declarator = simple_declarator();
            if (typecode != null) {
                Param param = null;
                if (literalStr.equals("in"))
                    param = ctx.createParam(((Param_declContext) _localctx).simple_declarator.ret.first().first(), typecode, Param.Kind.IN_PARAM);
                else if (literalStr.equals("out"))
                    param = ctx.createParam(((Param_declContext) _localctx).simple_declarator.ret.first().first(), typecode, Param.Kind.OUT_PARAM);
                else if (literalStr.equals("inout"))
                    param = ctx.createParam(((Param_declContext) _localctx).simple_declarator.ret.first().first(), typecode, Param.Kind.INOUT_PARAM);
                if (paramTemplate != null) {
                    paramTemplate.setAttribute("parameter", param);
                }
                ((Param_declContext) _localctx).returnPair = new Pair<Param, TemplateGroup>(param, paramTemplate);
            }
        }
    } 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 3 with Pair

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

the class IDLParser method const_decl.

public final Const_declContext const_decl() throws RecognitionException {
    Const_declContext _localctx = new Const_declContext(_ctx, getState());
    enterRule(_localctx, 58, RULE_const_decl);
    ConstDeclaration constDecl = null;
    TypeCode typecode = null;
    String constName = null, constValue = null;
    TemplateGroup constTemplates = null;
    if (tmanager != null) {
        constTemplates = tmanager.createTemplateGroup("const_decl");
    }
    Token tk = null;
    String comments = null;
    try {
        enterOuterAlt(_localctx, 1);
        {
            setState(610);
            match(KW_CONST);
            setState(611);
            ((Const_declContext) _localctx).const_type = const_type();
            typecode = ((Const_declContext) _localctx).const_type.typecode;
            tk = _input.LT(1);
            setState(613);
            ((Const_declContext) _localctx).identifier = identifier();
            constName = ((Const_declContext) _localctx).identifier.id;
            setState(615);
            match(EQUAL);
            setState(616);
            ((Const_declContext) _localctx).const_exp = const_exp();
            constValue = ((Const_declContext) _localctx).const_exp.literalStr;
            if (typecode != null) {
                comments = ctx.lookForComments(_input, tk, 50);
                String modifiedName = constName.contains("__") ? constName.substring(constName.indexOf("__") + 2) : constName;
                constDecl = new ConstDeclaration(ctx.getScopeFile(), ctx.isInScopedFile(), ctx.getScope(), modifiedName, typecode, constValue, tk, comments);
                constDeclarations.add(constDecl);
                if (constTemplates != null) {
                    constTemplates.setAttribute("ctx", ctx);
                    constTemplates.setAttribute("const", constDecl);
                }
                ((Const_declContext) _localctx).returnPair = new Pair<ConstDeclaration, TemplateGroup>(constDecl, constTemplates);
            }
        }
    } 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 4 with Pair

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

the class IDLParser method type_declarator.

public final Type_declaratorContext type_declarator() throws RecognitionException {
    Type_declaratorContext _localctx = new Type_declaratorContext(_ctx, getState());
    enterRule(_localctx, 88, RULE_type_declarator);
    Vector<TypeCode> vector = null;
    AliasTypeCode typedefTypecode = null;
    TemplateGroup typedefTemplates = null;
    if (tmanager != null) {
        typedefTemplates = tmanager.createTemplateGroup("typedef_decl");
    }
    try {
        enterOuterAlt(_localctx, 1);
        {
            setState(796);
            ((Type_declaratorContext) _localctx).type_spec = type_spec();
            setState(797);
            ((Type_declaratorContext) _localctx).declarators = declarators();
            if (((Type_declaratorContext) _localctx).type_spec.typecode != null) {
                vector = new Vector<TypeCode>();
                for (int count = 0; count < ((Type_declaratorContext) _localctx).declarators.ret.size(); ++count) {
                    typedefTypecode = new AliasTypeCode(ctx.getScope(), ((Type_declaratorContext) _localctx).declarators.ret.get(count).first().first());
                    if (((Type_declaratorContext) _localctx).declarators.ret.get(count).second() != null) {
                        // Array declaration
                        ((Type_declaratorContext) _localctx).declarators.ret.get(count).second().setContentTypeCode(((Type_declaratorContext) _localctx).type_spec.typecode);
                        typedefTypecode.setContentTypeCode(((Type_declaratorContext) _localctx).declarators.ret.get(count).second());
                    } else {
                        // Simple declaration
                        typedefTypecode.setContentTypeCode(((Type_declaratorContext) _localctx).type_spec.typecode);
                    }
                    if (typedefTemplates != null) {
                        typedefTemplates.setAttribute("typedefs", typedefTypecode);
                    }
                    vector.add(typedefTypecode);
                }
                if (typedefTemplates != null) {
                    typedefTemplates.setAttribute("ctx", ctx);
                }
                ((Type_declaratorContext) _localctx).returnPair = new Pair<Vector<TypeCode>, TemplateGroup>(vector, typedefTemplates);
            }
        }
    } 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 5 with Pair

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

the class IDLParser method module.

public final ModuleContext module() throws RecognitionException {
    ModuleContext _localctx = new ModuleContext(_ctx, getState());
    enterRule(_localctx, 6, RULE_module);
    Module moduleObject = null;
    TemplateGroup moduleTemplates = null;
    TemplateGroup tg = null;
    // Store old namespace.
    String name = null, old_scope = ctx.getScope();
    Token tk = null;
    try {
        enterOuterAlt(_localctx, 1);
        {
            {
                setState(375);
                match(KW_MODULE);
            }
            tk = _input.LT(1);
            setState(377);
            ((ModuleContext) _localctx).identifier = identifier();
            name = ((ModuleContext) _localctx).identifier.id;
            // Check if the module already was defined.
            moduleObject = ctx.existsModule(ctx.getScope() + "::" + name);
            if (moduleObject != null) {
                // Add the module to the context.
                ctx.addModule(moduleObject);
            } else {
                // Create the Module object.
                moduleObject = new Module(ctx.getScopeFile(), ctx.isInScopedFile(), ctx.getScope(), name, tk);
            }
            if (ctx.isInScopedFile() || ctx.isScopeLimitToAll()) {
                if (tmanager != null) {
                    moduleTemplates = tmanager.createTemplateGroup("module");
                    moduleTemplates.setAttribute("ctx", ctx);
                    // Set the module object to the TemplateGroup of the module.
                    moduleTemplates.setAttribute("module", moduleObject);
                }
            }
            // Update to a new namespace.
            if (old_scope.isEmpty())
                ctx.setScope(name);
            else
                ctx.setScope(old_scope + "::" + name);
            setState(379);
            match(LEFT_BRACE);
            setState(380);
            ((ModuleContext) _localctx).definition_list = definition_list(moduleObject);
            tg = ((ModuleContext) _localctx).definition_list.dlTemplates;
            if (moduleTemplates != null && tg != null)
                moduleTemplates.setAttribute("definition_list", tg);
            setState(382);
            match(RIGHT_BRACE);
            // Set the old namespace.
            ctx.setScope(old_scope);
            // Create the returned data.
            ((ModuleContext) _localctx).returnPair = new Pair<Module, TemplateGroup>(moduleObject, moduleTemplates);
        }
    } 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)

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