use of com.eprosima.idl.parser.exception.ParseException in project ihmc-pub-sub by ihmcrobotics.
the class IDLParser method fixed_pt_type.
public final Fixed_pt_typeContext fixed_pt_type() throws RecognitionException {
Fixed_pt_typeContext _localctx = new Fixed_pt_typeContext(_ctx, getState());
enterRule(_localctx, 214, RULE_fixed_pt_type);
Token tk = _input.LT(1);
try {
enterOuterAlt(_localctx, 1);
{
setState(1269);
match(KW_FIXED);
setState(1270);
match(LEFT_ANG_BRACKET);
setState(1271);
positive_int_const();
setState(1272);
match(COMA);
setState(1273);
positive_int_const();
setState(1274);
match(RIGHT_ANG_BRACKET);
throw new ParseException(tk, ". Fixed type is not supported");
}
} catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
} finally {
exitRule();
}
return _localctx;
}
use of com.eprosima.idl.parser.exception.ParseException in project ihmc-pub-sub by ihmcrobotics.
the class IDLParser method object_type.
public final Object_typeContext object_type() throws RecognitionException {
Object_typeContext _localctx = new Object_typeContext(_ctx, getState());
enterRule(_localctx, 138, RULE_object_type);
Token tk = _input.LT(1);
try {
enterOuterAlt(_localctx, 1);
{
setState(949);
match(KW_OBJECT);
throw new ParseException(tk, ". Object type is not supported");
}
} catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
} finally {
exitRule();
}
return _localctx;
}
use of com.eprosima.idl.parser.exception.ParseException in project ihmc-pub-sub by ihmcrobotics.
the class IDLParser method annotation_member.
public final Annotation_memberContext annotation_member(AnnotationDeclaration annotation) throws RecognitionException {
Annotation_memberContext _localctx = new Annotation_memberContext(_ctx, getState(), annotation);
enterRule(_localctx, 150, RULE_annotation_member);
String literalStr = null;
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(981);
((Annotation_memberContext) _localctx).const_type = const_type();
setState(982);
((Annotation_memberContext) _localctx).simple_declarator = simple_declarator();
setState(987);
_la = _input.LA(1);
if (_la == KW_DEFAULT) {
{
setState(983);
match(KW_DEFAULT);
setState(984);
((Annotation_memberContext) _localctx).const_exp = const_exp();
literalStr = ((Annotation_memberContext) _localctx).const_exp.literalStr;
}
}
setState(989);
match(SEMICOLON);
if (!_localctx.annotation.addMember(new AnnotationMember(((Annotation_memberContext) _localctx).simple_declarator.ret.first().first(), ((Annotation_memberContext) _localctx).const_type.typecode, literalStr))) {
throw new ParseException(((Annotation_memberContext) _localctx).simple_declarator.ret.first().second(), "was defined previously");
}
}
} catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
} finally {
exitRule();
}
return _localctx;
}
use of com.eprosima.idl.parser.exception.ParseException in project ihmc-pub-sub by ihmcrobotics.
the class IDLParser method case_stmt.
public final Case_stmtContext case_stmt(UnionTypeCode unionTP) throws RecognitionException {
Case_stmtContext _localctx = new Case_stmtContext(_ctx, getState(), unionTP);
enterRule(_localctx, 170, RULE_case_stmt);
List<String> labels = new ArrayList<String>();
boolean defaul = false;
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(1069);
_errHandler.sync(this);
_la = _input.LA(1);
do {
{
setState(1069);
switch(_input.LA(1)) {
case KW_CASE:
{
setState(1061);
match(KW_CASE);
setState(1062);
((Case_stmtContext) _localctx).const_exp = const_exp();
labels.add(TemplateUtil.checkUnionLabel(unionTP.getDiscriminator(), ((Case_stmtContext) _localctx).const_exp.literalStr, ctx.getScopeFile(), _input.LT(1) != null ? _input.LT(1).getLine() - ctx.getCurrentIncludeLine() : 1));
setState(1064);
match(COLON);
}
break;
case KW_DEFAULT:
{
setState(1066);
match(KW_DEFAULT);
defaul = true;
setState(1068);
match(COLON);
}
break;
default:
throw new NoViableAltException(this);
}
}
setState(1071);
_errHandler.sync(this);
_la = _input.LA(1);
} while (_la == KW_DEFAULT || _la == KW_CASE);
setState(1073);
((Case_stmtContext) _localctx).element_spec = element_spec(labels, defaul);
setState(1074);
match(SEMICOLON);
if (((Case_stmtContext) _localctx).element_spec.ret != null) {
int ret = unionTP.addMember(((Case_stmtContext) _localctx).element_spec.ret.second());
if (ret == -1)
throw new ParseException(((Case_stmtContext) _localctx).element_spec.ret.first().second(), " is already defined.");
else if (ret == -2)
throw new ParseException(((Case_stmtContext) _localctx).element_spec.ret.first().second(), " is also a default attribute. Another was defined previously.");
}
}
} catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
} finally {
exitRule();
}
return _localctx;
}
use of com.eprosima.idl.parser.exception.ParseException in project ihmc-pub-sub by ihmcrobotics.
the class TemplateUtil method setUnionDefaultLabel.
public static void setUnionDefaultLabel(UnionTypeCode union_type, String scopeFile, int line) {
TypeCode dist_type = union_type.getDiscriminator();
List<Member> members = union_type.getMembers();
if (dist_type != null && union_type.getDefaultMember() != null) {
if (dist_type.getKind() == TypeCode.KIND_SHORT || dist_type.getKind() == TypeCode.KIND_LONG || dist_type.getKind() == TypeCode.KIND_LONGLONG || dist_type.getKind() == TypeCode.KIND_USHORT || dist_type.getKind() == TypeCode.KIND_ULONG || dist_type.getKind() == TypeCode.KIND_ULONGLONG || dist_type.getKind() == TypeCode.KIND_CHAR) {
long dvalue = -1;
boolean found = true;
List<Member> list = new ArrayList(members);
do {
++dvalue;
found = false;
for (Member member : list) {
if (member instanceof UnionMember) {
UnionMember umember = (UnionMember) member;
for (String label : umember.getLabels()) {
long value = Long.valueOf(label);
if (dvalue == value) {
found = true;
break;
}
}
}
if (found)
break;
}
} while (found);
union_type.setDefaultvalue(Long.toString(dvalue));
union_type.setJavaDefaultvalue(Long.toString(dvalue));
} else if (dist_type.getKind() == TypeCode.KIND_BOOLEAN) {
if (members.size() == 1 && ((UnionMember) members.get(0)).getLabels().size() == 1) {
if (((UnionMember) members.get(0)).getLabels().get(0).equals("true")) {
union_type.setDefaultvalue("false");
union_type.setJavaDefaultvalue("false");
} else if (((UnionMember) members.get(0)).getLabels().get(0).equals("false")) {
union_type.setDefaultvalue("true");
union_type.setJavaDefaultvalue("true");
} else {
// throw new ParseException(((UnionMember)members.get(0)).getLabels().get(0), "is not a valid label for a boolean discriminator.");
throw new ParseException(null, "is not a valid label for a boolean discriminator.");
}
} else {
if (members.size() > 2)
throw new ParseException(null, "boolean switch cannot have more than two elements.");
union_type.setDefaultvalue("false");
union_type.setJavaDefaultvalue("false");
}
} else if (dist_type.getKind() == TypeCode.KIND_ENUM) {
EnumTypeCode enume = (EnumTypeCode) dist_type;
List<Member> list = new ArrayList(members);
List<Member> enum_members = new ArrayList<Member>();
enum_members.addAll(enume.getMembers());
for (Member member : members) {
UnionMember umember = (UnionMember) member;
for (String label : umember.getInternalLabels()) {
int count = 0;
for (; count < enum_members.size(); ++count) {
if (((EnumMember) enum_members.get(count)).getName().equals(label))
break;
}
if (count < enum_members.size())
enum_members.remove(count);
}
}
if (enum_members.size() > 0) {
union_type.setDefaultvalue(enume.getScope() + "::" + enum_members.get(0).getName());
union_type.setJavaDefaultvalue(enume.javapackage + enume.getJavaScopedname() + "." + enum_members.get(0).getName());
} else
throw new ParseException(null, "All enumeration elements are used in the union");
} else {
throw new ParseException(null, "Not supported type discriminator.");
}
}
}
Aggregations