diff --git a/src/it/java/com/eprosima/integration/Test.java b/src/it/java/com/eprosima/integration/Test.java index 630410c1..144098dd 100644 --- a/src/it/java/com/eprosima/integration/Test.java +++ b/src/it/java/com/eprosima/integration/Test.java @@ -46,15 +46,19 @@ public boolean generate( String generatorName, String inputPath, String exampleArch, - String cdr_version, boolean testFlag) { String program = "java -jar " + generatorName + ".jar"; - String flags = " -cdr " + cdr_version + " -replace -example" + " " + exampleArch + (testFlag ? " -test" : ""); + String flags = " -replace -example" + " " + exampleArch + (testFlag ? " -test -default-container-prealloc-size 50" : ""); String output = " -d " + outputPath; String idlPath = " " + inputPath + "/" + idl + ".idl"; + if (idl.equals("external") || idl.equals("declarations")) + { + flags = flags + " -no-typeobjectsupport"; + } + String command = program + flags + output + idlPath; return Command.execute(command, null, errorOutputOnly, true); @@ -63,15 +67,19 @@ public boolean generate( public boolean generate( String generatorName, String inputPath, - String cdr_version, boolean testFlag) { String program = "java -jar " + generatorName + ".jar"; - String flags = " -cdr " + cdr_version + " -replace -example" + (testFlag ? " -test" : ""); + String flags = " -replace -example" + (testFlag ? " -test -default-container-prealloc-size 50" : ""); String output = " -d " + outputPath; String idlPath = " " + inputPath + "/" + idl + ".idl"; + if (idl.equals("external") || idl.equals("declarations")) + { + flags = flags + " -no-typeobjectsupport"; + } + String command = program + flags + output + idlPath; return Command.execute(command, null, errorOutputOnly, true); } diff --git a/src/it/java/com/eprosima/integration/TestManager.java b/src/it/java/com/eprosima/integration/TestManager.java index cf98ce7c..e51c0c19 100644 --- a/src/it/java/com/eprosima/integration/TestManager.java +++ b/src/it/java/com/eprosima/integration/TestManager.java @@ -39,14 +39,12 @@ public int getValue() private String exampleArch; private List cMakeArgs; private boolean errorOutputOnly; - private String cdr_version_; public TestManager( TestLevel level, String generatorName, String inputPath, String outputPath, - String cdr_version, List list_tests, List blacklist_tests) { @@ -59,7 +57,6 @@ public TestManager( this.exampleArch = null; this.cMakeArgs = new ArrayList(); this.errorOutputOnly = true; - this.cdr_version_ = cdr_version; } public TestManager( @@ -68,7 +65,6 @@ public TestManager( String inputPath, String outputPath, String exampleArch, - String cdr_version, List list_tests, List blacklist_tests) { @@ -81,7 +77,6 @@ public TestManager( this.exampleArch = exampleArch; this.cMakeArgs = new ArrayList(); this.errorOutputOnly = true; - this.cdr_version_ = cdr_version; } public void processIDLsDirectory( @@ -164,9 +159,9 @@ public boolean generate(Test test) if (exampleArch == null) { - return printlnStatus(test.generate(generatorName, inputPath, cdr_version_, level == TestLevel.RUN)); + return printlnStatus(test.generate(generatorName, inputPath, level == TestLevel.RUN)); } else { - return printlnStatus(test.generate(generatorName, inputPath, exampleArch, cdr_version_, level == TestLevel.RUN)); + return printlnStatus(test.generate(generatorName, inputPath, exampleArch, level == TestLevel.RUN)); } } diff --git a/src/main/antlr/com/eprosima/idl/parser/grammar/IDL.g4 b/src/main/antlr/com/eprosima/idl/parser/grammar/IDL.g4 index d61a5b45..162e60be 100644 --- a/src/main/antlr/com/eprosima/idl/parser/grammar/IDL.g4 +++ b/src/main/antlr/com/eprosima/idl/parser/grammar/IDL.g4 @@ -177,27 +177,11 @@ module returns [Pair returnP if(moduleObject == null) { // Create the Module object. - moduleObject = new com.eprosima.idl.parser.tree.Module(ctx.getScopeFile(), ctx.isInScopedFile(), ctx.getScope(), name, tk); - //ctx.addPendingModule(moduleObject); + moduleObject = ctx.createModule(ctx.getScopeFile(), ctx.isInScopedFile(), ctx.getScope(), name, tk); } - // Add the module to the context. - ctx.addModule(moduleObject); - - 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); + // Add the module to the context and update to the new namespace (internally call ctx.setScope) + moduleTemplates = ctx.addModule(moduleObject); } // Each definition is stored in the Module and each TemplateGroup is set as attribute in the TemplateGroup of the module. LEFT_BRACE @@ -1172,8 +1156,10 @@ annotation_def returns [Pair returnPair = @init { TemplateGroup annotationTemplates = null; + String old_scope = ctx.getScope(); + String name = null; } - : annotation_header LEFT_BRACE annotation_body[$annotation_header.annotation] RIGHT_BRACE + : annotation_header { if($annotation_header.annotation != null) { @@ -1188,9 +1174,24 @@ annotation_def returns [Pair returnPair = } } - $returnPair = new Pair($annotation_header.annotation, annotationTemplates); + name = $annotation_header.annotation.getName(); + + // Update to a new namespace. + if(old_scope.isEmpty()) + ctx.setScope(name); + else + ctx.setScope(old_scope + "::" + name); } } + LEFT_BRACE + annotation_body[$annotation_header.annotation] + RIGHT_BRACE + { + // Set the old namespace. + ctx.setScope(old_scope); + // Create the returned data. + $returnPair = new Pair($annotation_header.annotation, annotationTemplates); + } ; annotation_header returns [AnnotationDeclaration annotation = null] @@ -1233,7 +1234,7 @@ annotation_inheritance_spec [AnnotationDeclaration annotation] } else { - System.out.println("WARNING (File " + ctx.getFilename() + ", Line " + (_input.LT(1) != null ? _input.LT(1).getLine() - ctx.getCurrentIncludeLine() : "1") + "): Annotation " + $scoped_name.pair.first() + " not supported. Ignoring..."); + throw new ParseException($scoped_name.pair.second(), "was not defined previously"); } } } @@ -1772,7 +1773,7 @@ union_type [Vector annotations, ArrayList defs] returns LEFT_BRACE switch_body[unionTP] RIGHT_BRACE { // Calculate default label. - TemplateUtil.setUnionDefaultLabel(defs, unionTP, ctx.getScopeFile(), line); + TemplateUtil.find_and_set_default_discriminator_value(defs, unionTP); if(ctx.isInScopedFile() || ctx.isScopeLimitToAll()) { @@ -1861,7 +1862,7 @@ case_stmt [UnionTypeCode unionTP] returns [TemplateGroup tg = null] } : ( KW_CASE const_exp { - labels.add(TemplateUtil.checkUnionLabel(unionTP.getDiscriminator(), $const_exp.literalStr, ctx.getScopeFile(), _input.LT(1) != null ? _input.LT(1).getLine() - ctx.getCurrentIncludeLine() : 1)); + labels.add(TemplateUtil.checkUnionLabel(unionTP.getDiscriminator().getTypecode(), $const_exp.literalStr)); } COLON | KW_DEFAULT { defaul = true; } COLON )+ @@ -2229,7 +2230,6 @@ array_declarator returns [Pair, ContainerTypeCode>, Tem { arrayTemplates.setAttribute("array", typecode); arrayTemplates.setAttribute("ctx", ctx); - arrayTemplates.setAttribute("array_type",tk.getText()); } Pair p = new Pair(tk.getText(), tk); Pair, ContainerTypeCode> pp = new Pair, ContainerTypeCode>(p, typecode); @@ -2802,7 +2802,7 @@ annotation_appl returns [Annotation annotation = null] anndecl = ctx.getAnnotationDeclaration(name); if(anndecl == null) { - System.out.println("WARNING (File " + ctx.getFilename() + ", Line " + (_input.LT(1) != null ? _input.LT(1).getLine() - ctx.getCurrentIncludeLine() : "1") + "): Annotation " + name + " not supported. Ignoring..."); + throw new ParseException($scoped_name.pair.second(), "was not defined previously"); } else { diff --git a/src/main/antlr4/kiara/com/eprosima/idl/parser/grammar/KIARAIDL.g4 b/src/main/antlr4/kiara/com/eprosima/idl/parser/grammar/KIARAIDL.g4 index 14f50c57..11516201 100644 --- a/src/main/antlr4/kiara/com/eprosima/idl/parser/grammar/KIARAIDL.g4 +++ b/src/main/antlr4/kiara/com/eprosima/idl/parser/grammar/KIARAIDL.g4 @@ -1218,7 +1218,7 @@ case_stmt [UnionTypeCode unionTP] } : ( KW_CASE const_exp { - labels.add(TemplateUtil.checkUnionLabel(unionTP.getDiscriminator(), $const_exp.literalStr, ctx.getScopeFile(), _input.LT(1) != null ? _input.LT(1).getLine() - ctx.getCurrentIncludeLine() : 1)); + labels.add(TemplateUtil.checkUnionLabel(unionTP.getDiscriminator().getTypecode(), $const_exp.literalStr, ctx.getScopeFile(), _input.LT(1) != null ? _input.LT(1).getLine() - ctx.getCurrentIncludeLine() : 1)); } COLON | KW_DEFAULT { defaul = true; } COLON )+ diff --git a/src/main/java/com/eprosima/idl/context/Context.java b/src/main/java/com/eprosima/idl/context/Context.java index baa603a5..6bbc7715 100644 --- a/src/main/java/com/eprosima/idl/context/Context.java +++ b/src/main/java/com/eprosima/idl/context/Context.java @@ -14,6 +14,30 @@ package com.eprosima.idl.context; +import java.io.File; +import java.io.StringReader; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Properties; +import java.util.Scanner; +import java.util.Stack; +import javax.script.ScriptEngineManager; +import javax.script.ScriptEngine; +import javax.script.ScriptException; +import org.antlr.v4.runtime.Token; +import org.stringtemplate.v4.STGroupFile; + +import com.eprosima.idl.generator.manager.TemplateGroup; +import com.eprosima.idl.generator.manager.TemplateManager; import com.eprosima.idl.parser.exception.ParseException; import com.eprosima.idl.parser.tree.Annotation; import com.eprosima.idl.parser.tree.AnnotationDeclaration; @@ -30,6 +54,7 @@ import com.eprosima.idl.parser.typecode.ArrayTypeCode; import com.eprosima.idl.parser.typecode.BitfieldSpec; import com.eprosima.idl.parser.typecode.BitsetTypeCode; +import com.eprosima.idl.parser.typecode.Bitmask; import com.eprosima.idl.parser.typecode.BitmaskTypeCode; import com.eprosima.idl.parser.typecode.EnumMember; import com.eprosima.idl.parser.typecode.EnumTypeCode; @@ -44,36 +69,25 @@ import com.eprosima.idl.parser.typecode.UnionTypeCode; import com.eprosima.idl.util.Pair; import com.eprosima.idl.util.Util; -import java.io.File; -import java.io.StringReader; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Properties; -import java.util.Scanner; -import java.util.Stack; -import javax.script.ScriptEngineManager; -import javax.script.ScriptEngine; -import javax.script.ScriptException; -import org.antlr.v4.runtime.Token; - - - public class Context { + /*! + * Built-in custom property to specify a TemplateGroup is using explicitly modules (in C++ when opening the + * namespace "namespace module {") + */ + public static final String using_explicitly_modules_custom_property = "using_explicitly_modules"; + public Context( + TemplateManager tmanager, String file, - ArrayList includePaths) + ArrayList includePaths, + boolean generate_typesc + ) { + tmanager_ = tmanager; + generate_typesc_ = generate_typesc; + // Detect OS m_os = System.getProperty("os.name"); m_userdir = System.getProperty("user.dir"); @@ -121,7 +135,7 @@ public Context( m_scopeFilesStack = new Stack>(); for (int i = 0; i < includePaths.size(); ++i) { - String include = (String)includePaths.get(i); + String include = includePaths.get(i); if (startsWith(include, includeFlag)) { include = include.substring(includeFlag.length()); @@ -168,25 +182,71 @@ public Context( } } - // Add here builtin annotations? (IDL 4.2 - 8.3.1 section) - AnnotationDeclaration idann = createAnnotationDeclaration(Annotation.id_str, null); - idann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_LONG), "-1")); + // Load IDL types for stringtemplates + TypeCode.ctx = this; + TypeCode.idltypesgr = new STGroupFile("com/eprosima/idl/templates/idlTypes.stg", '$', '$'); + if (generate_typesc) + { + TypeCode.cpptypesgr = new STGroupFile("com/eprosima/idl/templates/TypesCInterface.stg", '$', '$'); + } + else + { + TypeCode.cpptypesgr = new STGroupFile("com/eprosima/idl/templates/Types.stg", '$', '$'); + } + TypeCode.ctypesgr = new STGroupFile("com/eprosima/idl/templates/CTypes.stg", '$', '$'); + TypeCode.javatypesgr = new STGroupFile("com/eprosima/idl/templates/JavaTypes.stg", '$', '$'); + // Builtin annotations (IDL 4.2 - 8.3 section & XTypes 1.3 - 7.3.1.2.1 section) + + //{{{ @ami + AnnotationDeclaration amiann = createAnnotationDeclaration(Annotation.ami_str, null); + amiann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_BOOLEAN), Annotation.true_str)); + //}}} + + //{{{ @autoid AnnotationDeclaration autoidann = createAnnotationDeclaration(Annotation.autoid_str, null); EnumTypeCode autoidannenum = new EnumTypeCode(autoidann.getScopedname(), Annotation.autoid_enum_str); autoidannenum.addMember(new EnumMember(Annotation.autoid_sequential_str)); autoidannenum.addMember(new EnumMember(Annotation.autoid_hash_str)); autoidann.addMember(new AnnotationMember(Annotation.value_str, autoidannenum, Annotation.autoid_hash_str)); + //}}} + + //{{{ @bit_bound + AnnotationDeclaration bit_boundann = createAnnotationDeclaration(Annotation.bit_bound_str, null); + bit_boundann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_USHORT), Annotation.null_default_value)); + //}}} + + //{{{ @data_representation + BitmaskTypeCode data_representation_mask_bitmask = new BitmaskTypeCode(null, Annotation.data_representation_mask_str); + Bitmask xcdr1_bitmask = new Bitmask(data_representation_mask_bitmask, Annotation.xcdr1_bitflag_str); + xcdr1_bitmask.setPosition(0); + data_representation_mask_bitmask.addBitmask(xcdr1_bitmask); + Bitmask xml_bitmask = new Bitmask(data_representation_mask_bitmask, Annotation.xml_bitflag_str); + xml_bitmask.setPosition(1); + data_representation_mask_bitmask.addBitmask(xml_bitmask); + Bitmask xcdr2_bitmask = new Bitmask(data_representation_mask_bitmask, Annotation.xcdr2_bitflag_str); + xcdr2_bitmask.setPosition(2); + data_representation_mask_bitmask.addBitmask(xcdr2_bitmask); + + AnnotationDeclaration data_representation_annotation = createAnnotationDeclaration(Annotation.data_representation_str, null); + data_representation_annotation.addMember(new AnnotationMember(Annotation.allowed_kinds_str, data_representation_mask_bitmask, Annotation.empty_str)); + //}}} + + //{{{ @default + AnnotationDeclaration defaultann = createAnnotationDeclaration(Annotation.default_str, null); + defaultann.addMember(new AnnotationMember(Annotation.value_str, new AnyTypeCode(), null)); + //}}} - AnnotationDeclaration optionalann = createAnnotationDeclaration("optional", null); - optionalann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_BOOLEAN), "true")); - - AnnotationDeclaration positionann = createAnnotationDeclaration("position", null); - positionann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_USHORT), "-1")); + //{{{ @default_literal + createAnnotationDeclaration(Annotation.default_literal_str, null); + //}}} - AnnotationDeclaration valueann = createAnnotationDeclaration(Annotation.value_str, null); - valueann.addMember(new AnnotationMember(Annotation.value_str, new AnyTypeCode(), null)); + //{{{ @default_nested + AnnotationDeclaration default_nested_annotation = createAnnotationDeclaration(Annotation.default_nested_str, null); + default_nested_annotation.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_BOOLEAN), Annotation.true_str)); + //}}} + //{{{ @extensibility AnnotationDeclaration extensibilityann = createAnnotationDeclaration(Annotation.extensibility_str, null); EnumTypeCode extensibilityannenum = new EnumTypeCode(extensibilityann.getScopedname(), Annotation.extensibility_enum_str); extensibilityannenum.addMember(new EnumMember(Annotation.ex_final_str)); @@ -198,72 +258,126 @@ public Context( createAnnotationDeclaration(Annotation.final_str, null); createAnnotationDeclaration(Annotation.appendable_str, null); createAnnotationDeclaration(Annotation.mutable_str, null); + //}}} - // Create default @Key annotation. - AnnotationDeclaration keyann = createAnnotationDeclaration(Annotation.key_str, null); - keyann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_BOOLEAN), "true")); + //{{{ @external + AnnotationDeclaration externalann = createAnnotationDeclaration(Annotation.external_str, null); + externalann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_BOOLEAN), Annotation.true_str)); + //}}} - AnnotationDeclaration mustundann = createAnnotationDeclaration("must_understand", null); - mustundann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_BOOLEAN), "true")); - - createAnnotationDeclaration("default_literal", null); - - AnnotationDeclaration rangeann = createAnnotationDeclaration("range", null); - rangeann.addMember(new AnnotationMember("min", new AnyTypeCode(), null)); - //String.valueOf(Integer.MIN_VALUE))); - rangeann.addMember(new AnnotationMember("max", new AnyTypeCode(), null)); - //String.valueOf(Integer.MAX_VALUE))); + //{{{ @hashid + AnnotationDeclaration hashid_annotation = createAnnotationDeclaration(Annotation.hashid_str, null); + hashid_annotation.addMember(new AnnotationMember(Annotation.value_str, new StringTypeCode(Kind.KIND_STRING, null, null), Annotation.empty_str)); + //}}} - AnnotationDeclaration unitsann = createAnnotationDeclaration("units", null); - unitsann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_STRING), "")); + //{{{ @id + AnnotationDeclaration idann = createAnnotationDeclaration(Annotation.id_str, null); + idann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_ULONG), Annotation.null_default_value)); + //}}} - AnnotationDeclaration defaultann = createAnnotationDeclaration("default", null); - defaultann.addMember(new AnnotationMember(Annotation.value_str, new AnyTypeCode(), null)); + //{{{ @ignore_literal_names + AnnotationDeclaration ignore_literal_names_annotation = createAnnotationDeclaration(Annotation.ignore_literal_names_str, null); + ignore_literal_names_annotation.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_BOOLEAN), Annotation.true_str)); + //}}} - AnnotationDeclaration minann = createAnnotationDeclaration("min", null); - minann.addMember(new AnnotationMember(Annotation.value_str, new AnyTypeCode(), null)); + //{{{ @key + // Create default @key annotation (@Key annotation also supported and registered in parseIDL) + AnnotationDeclaration keyann = createAnnotationDeclaration(Annotation.key_str, null); + keyann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_BOOLEAN), Annotation.true_str)); + //}}} - AnnotationDeclaration maxann = createAnnotationDeclaration("max", null); + //{{{ @max + AnnotationDeclaration maxann = createAnnotationDeclaration(Annotation.max_str, null); maxann.addMember(new AnnotationMember(Annotation.value_str, new AnyTypeCode(), null)); + //}}} - AnnotationDeclaration bit_boundann = createAnnotationDeclaration("bit_bound", null); - bit_boundann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_USHORT), "-1")); - - AnnotationDeclaration externalann = createAnnotationDeclaration("external", null); - externalann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_BOOLEAN), "true")); - - AnnotationDeclaration nestedann = createAnnotationDeclaration("nested", null); - nestedann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_BOOLEAN), "true")); - - AnnotationDeclaration verbatimann = createAnnotationDeclaration("verbatim", null); - EnumTypeCode verbatimannenum = new EnumTypeCode(verbatimann.getScopedname(), "verbatimannenum"); - verbatimannenum.addMember(new EnumMember("BEGIN_FILE")); - verbatimannenum.addMember(new EnumMember("BEFORE_DECLARATION")); - verbatimannenum.addMember(new EnumMember("BEGIN_DECLARATION")); - verbatimannenum.addMember(new EnumMember("END_DECLARATION")); - verbatimannenum.addMember(new EnumMember("AFTER_DECLARATION")); - verbatimannenum.addMember(new EnumMember("END_FILE")); - verbatimann.addMember(new AnnotationMember("language", new PrimitiveTypeCode(Kind.KIND_STRING), "*")); - // c, c++, java, idl, * (any), or custom value - verbatimann.addMember(new AnnotationMember("placement", verbatimannenum, "BEFORE_DECLARATION")); - verbatimann.addMember(new AnnotationMember("text", new PrimitiveTypeCode(Kind.KIND_STRING), "")); - - AnnotationDeclaration serviceann = createAnnotationDeclaration("service", null); - serviceann.addMember(new AnnotationMember("platform", new PrimitiveTypeCode(Kind.KIND_STRING), "*")); + //{{{ @min + AnnotationDeclaration minann = createAnnotationDeclaration(Annotation.min_str, null); + minann.addMember(new AnnotationMember(Annotation.value_str, new AnyTypeCode(), null)); + //}}} + + //{{{ @must_understand + AnnotationDeclaration mustundann = createAnnotationDeclaration(Annotation.must_understand_str, null); + mustundann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_BOOLEAN), Annotation.true_str)); + //}}} + + //{{{ @nested + AnnotationDeclaration nestedann = createAnnotationDeclaration(Annotation.nested_str, null); + nestedann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_BOOLEAN), Annotation.true_str)); + //}}} + + //{{{ @non_serialized + AnnotationDeclaration non_serializedann = createAnnotationDeclaration(Annotation.non_serialized_str, null); + non_serializedann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_BOOLEAN), Annotation.true_str)); + //}}} + + //{{{ @oneway + AnnotationDeclaration onewayann = createAnnotationDeclaration(Annotation.oneway_str, null); + onewayann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_BOOLEAN), Annotation.true_str)); + //}}} + + //{{{ @optional + AnnotationDeclaration optionalann = createAnnotationDeclaration(Annotation.optional_str, null); + optionalann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_BOOLEAN), Annotation.true_str)); + //}}} + + //{{{ @position + AnnotationDeclaration positionann = createAnnotationDeclaration(Annotation.position_str, null); + positionann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_USHORT), Annotation.null_default_value)); + //}}} + + //{{{ @range + AnnotationDeclaration rangeann = createAnnotationDeclaration(Annotation.range_str, null); + rangeann.addMember(new AnnotationMember(Annotation.min_str, new AnyTypeCode(), null)); + rangeann.addMember(new AnnotationMember(Annotation.max_str, new AnyTypeCode(), null)); + //}}} + + //{{{ @service + AnnotationDeclaration serviceann = createAnnotationDeclaration(Annotation.service_str, null); + serviceann.addMember(new AnnotationMember(Annotation.platform_str, new PrimitiveTypeCode(Kind.KIND_STRING), Annotation.any_str)); // CORBA, DDS, * (any), or custom value - - AnnotationDeclaration onewayann = createAnnotationDeclaration("oneway", null); - onewayann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_BOOLEAN), "true")); - - AnnotationDeclaration amiann = createAnnotationDeclaration("ami", null); - amiann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_BOOLEAN), "true")); - - AnnotationDeclaration hashid_annotation = createAnnotationDeclaration(Annotation.hashid_str, null); - hashid_annotation.addMember(new AnnotationMember(Annotation.value_str, new StringTypeCode(Kind.KIND_STRING, null, null), "")); - - // Create default @non_serialized annotation. - AnnotationDeclaration non_serializedann = createAnnotationDeclaration("non_serialized", null); - non_serializedann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_BOOLEAN), "true")); + //}}} + + //{{{ topic + AnnotationDeclaration topic_annotation = createAnnotationDeclaration(Annotation.topic_str, null); + topic_annotation.addMember(new AnnotationMember(Annotation.name_str, new PrimitiveTypeCode(Kind.KIND_STRING), Annotation.empty_str)); + topic_annotation.addMember(new AnnotationMember(Annotation.platform_str, new PrimitiveTypeCode(Kind.KIND_STRING), Annotation.any_str)); + //}}} + + //{{{ @try_construct + EnumTypeCode try_construct_fail_action_enum = new EnumTypeCode(null, Annotation.try_construct_enum_str); + try_construct_fail_action_enum.addMember(new EnumMember(Annotation.try_construct_discard_str)); + try_construct_fail_action_enum.addMember(new EnumMember(Annotation.try_construct_use_default_str)); + try_construct_fail_action_enum.addMember(new EnumMember(Annotation.try_construct_trim_str)); + + AnnotationDeclaration try_construct_annotation = createAnnotationDeclaration(Annotation.try_construct_str, null); + try_construct_annotation.addMember(new AnnotationMember(Annotation.value_str, try_construct_fail_action_enum, Annotation.try_construct_use_default_str)); + //}}} + + //{{{ @unit + AnnotationDeclaration unitsann = createAnnotationDeclaration(Annotation.unit_str, null); + unitsann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_STRING), Annotation.empty_str)); + //}}} + + //{{{ @value + AnnotationDeclaration valueann = createAnnotationDeclaration(Annotation.value_str, null); + valueann.addMember(new AnnotationMember(Annotation.value_str, new AnyTypeCode(), null)); + //}}} + + //{{{ @verbatim + AnnotationDeclaration verbatimann = createAnnotationDeclaration(Annotation.verbatim_str, null); + EnumTypeCode verbatimannenum = new EnumTypeCode(verbatimann.getScopedname(), Annotation.placement_enum_str); + verbatimannenum.addMember(new EnumMember(Annotation.begin_file_str)); + verbatimannenum.addMember(new EnumMember(Annotation.before_declaration_str)); + verbatimannenum.addMember(new EnumMember(Annotation.begin_declaration_str)); + verbatimannenum.addMember(new EnumMember(Annotation.end_declaration_str)); + verbatimannenum.addMember(new EnumMember(Annotation.after_declaration_str)); + verbatimannenum.addMember(new EnumMember(Annotation.end_file_str)); + verbatimann.addMember(new AnnotationMember(Annotation.language_str, new PrimitiveTypeCode(Kind.KIND_STRING), Annotation.any_str)); + // c, c++, java, idl, * (any), or custom value + verbatimann.addMember(new AnnotationMember(Annotation.placement_str, verbatimannenum, Annotation.before_declaration_str)); + verbatimann.addMember(new AnnotationMember(Annotation.text_str, new PrimitiveTypeCode(Kind.KIND_STRING), Annotation.empty_str)); + //}}} } public String getFilename() @@ -373,13 +487,36 @@ public ArrayList getDefinitions() * @brief This function adds a module to the context. * This function is used in the parser. */ - public void addModule( + public TemplateGroup addModule( com.eprosima.idl.parser.tree.Module module) { + TemplateGroup moduleTemplates = null; + if (!m_modules.containsKey(module.getScopedname())) { m_modules.put(module.getScopedname(), module); } + + if(isInScopedFile() || isScopeLimitToAll()) { + if(tmanager_ != null) { + moduleTemplates = tmanager_.createTemplateGroup("module"); + moduleTemplates.setAttribute("ctx", this); + // Set the module object to the TemplateGroup of the module. + moduleTemplates.setAttribute("module", module); + } + } + + // Change context scope. + if (m_scope.isEmpty()) + { + setScope(module.getName()); + } + else + { + setScope(m_scope + "::" + module.getName()); + } + + return moduleTemplates; } public com.eprosima.idl.parser.tree.Module existsModule( @@ -529,6 +666,16 @@ public com.eprosima.idl.parser.tree.Exception getException( return returnedValue; } + public com.eprosima.idl.parser.tree.Module createModule( + String scope_file, + boolean is_in_scope, + String scope, + String name, + Token token) + { + return new com.eprosima.idl.parser.tree.Module (scope_file, is_in_scope, scope, name, token); + } + public Operation createOperation( String name, Token token) @@ -686,7 +833,7 @@ public TypeCode getTypeCode( TypeCode returnedValue = null; TypeDeclaration typedecl = m_types.get(name); - // Probar si no tiene scope, con el scope actual. + // Wether the name doesn't contain scope, test with the current scope. if (typedecl == null) { String scope = m_scope; @@ -1352,6 +1499,27 @@ public String evaluate_literal( return aux_str; } + public boolean isGenerateTypesC() + { + return generate_typesc_; + } + + /*! + * @brief Checks a custom property was enables for a TemplateGroup. + * + * There are built-in custom properties: + * - Context.using_explicitly_modules_custom_property: specifies a TemplateGroup is using explicitly modules. + */ + public boolean is_enabled_custom_property_in_current_group(String custom_property) + { + if (null != tmanager_) + { + return tmanager_.is_enabled_custom_property_in_current_group(custom_property); + } + + return false; + } + // OS String m_os = null; String m_userdir = null; @@ -1402,4 +1570,8 @@ public String evaluate_literal( private HashSet m_keywords = null; private boolean m_ignore_case = true; + + private boolean generate_typesc_ = false; + + protected TemplateManager tmanager_ = null; } diff --git a/src/main/java/com/eprosima/idl/generator/manager/TemplateGroup.java b/src/main/java/com/eprosima/idl/generator/manager/TemplateGroup.java index 3827bc08..0bea45b2 100644 --- a/src/main/java/com/eprosima/idl/generator/manager/TemplateGroup.java +++ b/src/main/java/com/eprosima/idl/generator/manager/TemplateGroup.java @@ -31,42 +31,44 @@ public class TemplateGroup { - private Map m_templates = new HashMap(); + private Map m_templates = new HashMap(); private Map> m_extensionstemplates = new HashMap>(); private TemplateErrorListener error_listener_ = null; + private TemplateManager manager_ = null; public TemplateGroup(TemplateManager manager) { + manager_ = manager; error_listener_ = new TemplateErrorListener(manager); } - public void addTemplate(String groupname, ST template) + public void addTemplate(String groupname, TemplateST template) { m_templates.put(groupname, template); } - public void addTemplate(String groupname, ST template, List extensionstemplates) + public void addTemplate(String groupname, TemplateST template, List extensionstemplates) { addTemplate(groupname, template); - m_extensionstemplates.put(groupname + "_" + template.getName(), extensionstemplates); + m_extensionstemplates.put(groupname + "_" + template.get_st().getName(), extensionstemplates); } - public ST getTemplate(String groupname) + public TemplateST getTemplate(String groupname) { - ST template = m_templates.get(groupname); + TemplateST template = m_templates.get(groupname); //If there is extensiones, add them before return the template. - if(m_extensionstemplates.containsKey(groupname + "_" + template.getName())) + if(m_extensionstemplates.containsKey(groupname + "_" + template.get_st().getName())) { List extemplates = new ArrayList(); - List extensions = m_extensionstemplates.get(groupname + "_" + template.getName()); + List extensions = m_extensionstemplates.get(groupname + "_" + template.get_st().getName()); for(ST extension : extensions) { extemplates.add(extension); } - template.add("extensions", extemplates); + template.get_st().add("extensions", extemplates); } return template; @@ -76,23 +78,30 @@ public void setAttribute(String attribute, TemplateGroup tg) { if(tg != null) { - Set> set = m_templates.entrySet(); - Iterator> it = set.iterator(); + Set> set = m_templates.entrySet(); + Iterator> it = set.iterator(); while(it.hasNext()) { - Map.Entry m = it.next(); + Map.Entry m = it.next(); // Call setAttribute - ST template = tg.getTemplate(m.getKey()); + TemplateST template = tg.getTemplate(m.getKey()); if(template != null) { - Log.printDebug("setting attribute (TemplateGroup) to template group " + m.getKey() + " from " + template.getName() + " to " + m.getValue().getName()); + // Before render, set the current TemplateSTGroup in TemplateManager. + manager_.set_current_template_stgroup(m.getValue().get_template_stgroup()); + + Log.printDebug("setting attribute (TemplateGroup) to template group " + m.getKey() + " from " + + template.get_st().getName() + " to " + m.getValue().get_st().getName()); StringWriter out = new StringWriter(); STWriter wr = new AutoIndentWriter(out); - template.write(wr, error_listener_); - m.getValue().add(attribute, out.toString()); + template.get_st().write(wr, error_listener_); + m.getValue().get_st().add(attribute, out.toString()); + + // Unset the current TemplateSTGroup in TemplateManager. + manager_.set_current_template_stgroup(null); } } } @@ -100,19 +109,20 @@ public void setAttribute(String attribute, TemplateGroup tg) public void setAttribute(String attribute, Object obj1) { - Set> set = m_templates.entrySet(); - Iterator> it = set.iterator(); + Set> set = m_templates.entrySet(); + Iterator> it = set.iterator(); while(it.hasNext()) { - Map.Entry m = it.next(); + Map.Entry m = it.next(); // Call setAttribute - Log.printDebug("setting attribute (obj1) to template group " + m.getKey() + " to " + m.getValue().getName()); - ST template = m.getValue(); - template.add(attribute, obj1); + Log.printDebug("setting attribute (obj1) to template group " + m.getKey() + " to " + + m.getValue().get_st().getName()); + TemplateST template = m.getValue(); + template.get_st().add(attribute, obj1); // Update extensions - List extensions = m_extensionstemplates.get(m.getKey() + "_" + template.getName()); + List extensions = m_extensionstemplates.get(m.getKey() + "_" + template.get_st().getName()); if(extensions != null) { for(ST extension : extensions) diff --git a/src/main/java/com/eprosima/idl/generator/manager/TemplateManager.java b/src/main/java/com/eprosima/idl/generator/manager/TemplateManager.java index e443ea9a..ea852eb0 100644 --- a/src/main/java/com/eprosima/idl/generator/manager/TemplateManager.java +++ b/src/main/java/com/eprosima/idl/generator/manager/TemplateManager.java @@ -14,10 +14,6 @@ package com.eprosima.idl.generator.manager; -import com.eprosima.idl.generator.manager.TemplateGroup; -import com.eprosima.idl.parser.typecode.TypeCode; -import com.eprosima.idl.context.Context; - import java.util.Iterator; import java.util.Map; import java.util.HashMap; @@ -31,51 +27,38 @@ public class TemplateManager { - private Map m_groups = new HashMap(); + private Map m_groups = new HashMap(); private boolean st_error_ = false; - public TemplateManager(String stackTemplateNames, Context ctx, boolean generate_typesc) - { - // Load IDL types for stringtemplates - TypeCode.idltypesgr = new STGroupFile("com/eprosima/idl/templates/idlTypes.stg", '$', '$'); - if (generate_typesc) - { - TypeCode.cpptypesgr = new STGroupFile("com/eprosima/idl/templates/TypesCInterface.stg", '$', '$'); - } - else - { - TypeCode.cpptypesgr = new STGroupFile("com/eprosima/idl/templates/Types.stg", '$', '$'); - } - TypeCode.ctypesgr = new STGroupFile("com/eprosima/idl/templates/CTypes.stg", '$', '$'); - TypeCode.javatypesgr = new STGroupFile("com/eprosima/idl/templates/JavaTypes.stg", '$', '$'); - TypeCode.ctx = ctx; - } + private TemplateSTGroup current_template_stgroup_ = null; - public void addGroup(String groupname) + public TemplateSTGroup addGroup(String groupname) { - STGroup group = new STGroupFile(groupname, '$', '$'); + TemplateSTGroup group = new TemplateSTGroup(groupname); m_groups.put(groupname, group); + return group; } - public void addGroupFromString(String groupname, String text) + public TemplateSTGroup addGroupFromString(String groupname, String text) { - STGroup group = new STGroupString(groupname, text, '$', '$'); + TemplateSTGroup group = new TemplateSTGroup(groupname, text); m_groups.put(groupname, group); + return group; } public TemplateGroup createTemplateGroup(String templatename) { TemplateGroup tg = new TemplateGroup(this); - Set> set = m_groups.entrySet(); - Iterator> it = set.iterator(); + Set> set = m_groups.entrySet(); + Iterator> it = set.iterator(); while(it.hasNext()) { - Map.Entry m = it.next(); + Map.Entry m = it.next(); // Obtain instance - ST template = m.getValue().getInstanceOf(templatename); + TemplateST template = new TemplateST(m.getValue(), templatename); tg.addTemplate(m.getKey(), template); } @@ -97,4 +80,19 @@ public boolean get_st_error() { return st_error_; } + + public void set_current_template_stgroup(TemplateSTGroup template_stgroup) + { + current_template_stgroup_ = template_stgroup; + } + + public boolean is_enabled_custom_property_in_current_group(String custom_property) + { + if (null != current_template_stgroup_) + { + return current_template_stgroup_.is_enabled_custom_property(custom_property); + } + + return false; + } } diff --git a/src/main/java/com/eprosima/idl/generator/manager/TemplateST.java b/src/main/java/com/eprosima/idl/generator/manager/TemplateST.java new file mode 100644 index 00000000..cf8f06f0 --- /dev/null +++ b/src/main/java/com/eprosima/idl/generator/manager/TemplateST.java @@ -0,0 +1,39 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.eprosima.idl.generator.manager; + +import org.stringtemplate.v4.*; + +public class TemplateST +{ + public TemplateST(TemplateSTGroup parent_group, String template_name) + { + parent_group_ = parent_group; + st_ = parent_group_.get_stgroup().getInstanceOf(template_name); + } + + public ST get_st() + { + return st_; + } + + public TemplateSTGroup get_template_stgroup() + { + return parent_group_; + } + + private ST st_ = null; + private TemplateSTGroup parent_group_ = null; +}; diff --git a/src/main/java/com/eprosima/idl/generator/manager/TemplateSTGroup.java b/src/main/java/com/eprosima/idl/generator/manager/TemplateSTGroup.java new file mode 100644 index 00000000..61168b88 --- /dev/null +++ b/src/main/java/com/eprosima/idl/generator/manager/TemplateSTGroup.java @@ -0,0 +1,57 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.eprosima.idl.generator.manager; + +import org.stringtemplate.v4.*; +import java.util.ArrayList; + +public class TemplateSTGroup +{ + public TemplateSTGroup(String groupname) + { + st_group_ = new STGroupFile(groupname, '$', '$'); + } + + public TemplateSTGroup(String groupname, String text) + { + st_group_ = new STGroupString(groupname, text, '$', '$'); + } + + public STGroup get_stgroup() + { + return st_group_; + } + + /*! + * @brief Checks a custom property was added in this template group. + */ + public boolean is_enabled_custom_property(String custom_property) + { + return custom_properties.contains(custom_property); + } + + /*! + * @brief Enables a custom property. + */ + public void enable_custom_property(String custom_property) + { + custom_properties.add(custom_property); + } + + private STGroup st_group_ = null; + + //! List of custom properties added by the user. + ArrayList custom_properties = new ArrayList(); +}; diff --git a/src/main/java/com/eprosima/idl/generator/manager/TemplateUtil.java b/src/main/java/com/eprosima/idl/generator/manager/TemplateUtil.java index 8ccefcfc..7cdb34f6 100644 --- a/src/main/java/com/eprosima/idl/generator/manager/TemplateUtil.java +++ b/src/main/java/com/eprosima/idl/generator/manager/TemplateUtil.java @@ -35,24 +35,38 @@ else if(type.startsWith("std::vector")) return type; } - public static void setUnionDefaultLabel(ArrayList defs, UnionTypeCode union_type, String scopeFile, int line) + /*! + * This function tries to find a default discriminator value for the union following the guidelines extracted from + * the standard. + * + * \b 6.14.2 Mapping for Union Types \b + * "If there is a default case specified, the union is initialized to this default case. + * In case the union has an implicit default member it is initialized to that case. + * In all other cases it is initialized to the first discriminant value specified in IDL" + */ + public static void find_and_set_default_discriminator_value(ArrayList defs, UnionTypeCode union_type) { - TypeCode dist_type = union_type.getDiscriminator(); List members = union_type.getMembers(); + TypeCode disc_type = union_type.getDiscriminator().getTypecode(); - if(dist_type != null && union_type.getDefaultMember() != null) + if (Kind.KIND_ALIAS == disc_type.getKind()) { - if(dist_type.getKind() == Kind.KIND_OCTET || - dist_type.getKind() == Kind.KIND_INT8 || - dist_type.getKind() == Kind.KIND_SHORT || - dist_type.getKind() == Kind.KIND_LONG || - dist_type.getKind() == Kind.KIND_LONGLONG || - dist_type.getKind() == Kind.KIND_UINT8 || - dist_type.getKind() == Kind.KIND_USHORT || - dist_type.getKind() == Kind.KIND_ULONG || - dist_type.getKind() == Kind.KIND_ULONGLONG || - dist_type.getKind() == Kind.KIND_CHAR || - dist_type.getKind() == Kind.KIND_WCHAR) + disc_type = ((AliasTypeCode)disc_type).getContentTypeCode(); + } + + if(disc_type != null) + { + if(disc_type.getKind() == Kind.KIND_OCTET || + disc_type.getKind() == Kind.KIND_INT8 || + disc_type.getKind() == Kind.KIND_SHORT || + disc_type.getKind() == Kind.KIND_LONG || + disc_type.getKind() == Kind.KIND_LONGLONG || + disc_type.getKind() == Kind.KIND_UINT8 || + disc_type.getKind() == Kind.KIND_USHORT || + disc_type.getKind() == Kind.KIND_ULONG || + disc_type.getKind() == Kind.KIND_ULONGLONG || + disc_type.getKind() == Kind.KIND_CHAR || + disc_type.getKind() == Kind.KIND_WCHAR) { long dvalue = -1; boolean found = true; @@ -79,15 +93,17 @@ public static void setUnionDefaultLabel(ArrayList defs, UnionTypeCod catch(NumberFormatException nfe) { // It could be a const - for (Definition def : defs) + if (null != defs) { - if (def.isIsConstDeclaration()) + for (Definition def : defs) { - ConstDeclaration decl = (ConstDeclaration)def; - if (decl.getName().equals(label)) + if (def.isIsConstDeclaration()) { - value = Long.decode(decl.getValue()); - //System.out.println("Label " + label + " has value " + value); + ConstDeclaration decl = (ConstDeclaration)def; + if (decl.getName().equals(label)) + { + value = Long.decode(decl.getValue()); + } } } } @@ -109,9 +125,9 @@ public static void setUnionDefaultLabel(ArrayList defs, UnionTypeCod union_type.setDefaultvalue(Long.toString(dvalue)); union_type.setJavaDefaultvalue(Long.toString(dvalue)); } - else if(dist_type.getKind() == Kind.KIND_BOOLEAN) + else if(disc_type.getKind() == Kind.KIND_BOOLEAN) { - if(members.size() == 1 && ((UnionMember)members.get(0)).getLabels().size() == 1) + if(1 == members.size() && 1 == ((UnionMember)members.get(0)).getLabels().size()) { if(((UnionMember)members.get(0)).getLabels().get(0).equals("true")) { @@ -125,23 +141,24 @@ else if(((UnionMember)members.get(0)).getLabels().get(0).equals("false")) } else { - //TODO - //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 + else if(2 == members.size() && 1 == ((UnionMember)members.get(0)).getLabels().size() && + 1 == ((UnionMember)members.get(1)).getLabels().size()) { - if(members.size() > 2) - throw new ParseException(null, "boolean switch cannot have more than two elements."); - union_type.setDefaultvalue("false"); - union_type.setJavaDefaultvalue("false"); + union_type.setDefaultvalue(((UnionMember)members.get(0)).getLabels().get(0)); + union_type.setJavaDefaultvalue(((UnionMember)members.get(0)).getLabels().get(0)); + } + else + { + throw new ParseException(null, "boolean switch is malformed."); } } - else if(dist_type.getKind() == Kind.KIND_ENUM) + else if(disc_type.getKind() == Kind.KIND_ENUM) { - EnumTypeCode enume = (EnumTypeCode)dist_type; + EnumTypeCode enume = (EnumTypeCode)disc_type; List list = new ArrayList(members); List enum_members = new ArrayList(); enum_members.addAll(enume.getMembers()); @@ -167,11 +184,14 @@ else if(dist_type.getKind() == Kind.KIND_ENUM) if(enum_members.size() > 0) { - union_type.setDefaultvalue(enume.getScope() + "::" + enum_members.get(0).getName()); + union_type.setDefaultvalue(enume.getScopedname() + "::" + 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 if (0 < members.size() && 0 < ((UnionMember)members.get(0)).getLabels().size()) + { + union_type.setDefaultvalue(((UnionMember)members.get(0)).getLabels().get(0)); + union_type.setJavaDefaultvalue(((UnionMember)members.get(0)).getLabels().get(0)); + } } else { @@ -180,14 +200,13 @@ else if(dist_type.getKind() == Kind.KIND_ENUM) } } - public static String checkUnionLabel(TypeCode dist_type, String label, String scopeFile, int line) + public static String checkUnionLabel(TypeCode disc_type, String label) { - // TODO Faltan tipos: short, unsigneds... - if(dist_type != null) + if(disc_type != null) { - if(dist_type.getKind() == Kind.KIND_ENUM) + if(disc_type.getKind() == Kind.KIND_ENUM) { - EnumTypeCode enume = (EnumTypeCode)dist_type; + EnumTypeCode enume = (EnumTypeCode)disc_type; if(enume.getScope() != null) { @@ -195,8 +214,6 @@ public static String checkUnionLabel(TypeCode dist_type, String label, String sc { if(!label.startsWith(enume.getScope())) { - //TODO - //throw new ParseException(label, "was not declared previously"); throw new ParseException(null, "was not declared previously"); } else @@ -209,11 +226,24 @@ public static String checkUnionLabel(TypeCode dist_type, String label, String sc { if(label.contains("::")) { - //TODO - //throw new ParseException(label, "was not declared previously"); throw new ParseException(null, "was not declared previously"); } } + + boolean found = false; + for(Member member : enume.getMembers()) + { + if (label.equals(member.getName())) + { + found = true; + break; + } + } + + if (!found) + { + throw new ParseException(null, "Invalid enumerator label"); + } } } diff --git a/src/main/java/com/eprosima/idl/parser/tree/Annotation.java b/src/main/java/com/eprosima/idl/parser/tree/Annotation.java index 2a0fa3a4..e509d102 100644 --- a/src/main/java/com/eprosima/idl/parser/tree/Annotation.java +++ b/src/main/java/com/eprosima/idl/parser/tree/Annotation.java @@ -18,18 +18,44 @@ import java.util.HashMap; import java.util.Collection; +import com.eprosima.idl.parser.exception.RuntimeGenerationException; +import com.eprosima.idl.parser.typecode.TypeCode; + public class Annotation { + public static final String null_default_value = "0"; + public static final String true_str = "true"; + public static final String capitalized_true_str = "TRUE"; + public static final String empty_str = ""; + public static final String any_str = "*"; + + public static final String ami_str = "ami"; + + //{{{ @autoid public static final String autoid_str = "autoid"; public static final String autoid_enum_str = "AutoidKind"; public static final String autoid_sequential_str = "SEQUENTIAL"; public static final String autoid_sequential_value_str = "0"; public static final String autoid_hash_str = "HASH"; + public static final String autoid_hash_value_str = "1"; + //}}} - public static final String hashid_str = "hashid"; - public static final String id_str = "id"; - public static final String key_str = "key"; + public static final String bit_bound_str = "bit_bound"; + + //{{{ @data_representation + public static final String data_representation_mask_str = "DataRepresentationMask"; + public static final String xcdr1_bitflag_str = "XCDR1"; + public static final String xml_bitflag_str = "XML"; + public static final String xcdr2_bitflag_str = "XCDR2"; + public static final String data_representation_str = "data_representation"; + public static final String allowed_kinds_str = "allowed_kinds"; + //}}} + public static final String default_str = "default"; + public static final String default_literal_str = "default_literal"; + public static final String default_nested_str = "default_nested"; + + //{{{ @extensibility public static final String extensibility_str = "extensibility"; public static final String extensibility_enum_str = "ExtensibilityKind"; public static final String final_str = "final"; @@ -41,9 +67,63 @@ public class Annotation public static final String ex_appendable_val = "1"; public static final String ex_mutable_str = "MUTABLE"; public static final String ex_mutable_val = "2"; + //}}} + + public static final String external_str = "external"; + public static final String hashid_str = "hashid"; + public static final String id_str = "id"; + public static final String ignore_literal_names_str = "ignore_literal_names"; + + ///{{{ @key + public static final String key_str = "key"; + public static final String eprosima_key_str = "Key"; + //}}} + + public static final String max_str = "max"; + public static final String min_str = "min"; + public static final String must_understand_str = "must_understand"; + public static final String nested_str = "nested"; + public static final String non_serialized_str = "non_serialized"; + public static final String oneway_str = "oneway"; + public static final String optional_str = "optional"; + public static final String position_str = "position"; + public static final String range_str = "range"; + //{{{ @service + public static final String service_str = "service"; + public static final String platform_str = "platform"; + //}}} + + //{{{ @topic + public static final String topic_str = "topic"; + public static final String name_str = "name"; + //}}} + + //{{{ @try_construct + public static final String try_construct_str = "try_construct"; + public static final String try_construct_enum_str = "TryConstructFailAction"; + public static final String try_construct_discard_str = "DISCARD"; + public static final String try_construct_use_default_str = "USE_DEFAULT"; + public static final String try_construct_trim_str = "TRIM"; + //}}} + + public static final String unit_str = "unit"; public static final String value_str = "value"; + //{{{ @verbatim + public static final String verbatim_str = "verbatim"; + public static final String placement_enum_str = "PlacementKind"; + public static final String begin_file_str = "BEGIN_FILE"; + public static final String before_declaration_str = "BEFORE_DECLARATION"; + public static final String begin_declaration_str = "BEGIN_DECLARATION"; + public static final String end_declaration_str = "END_DECLARATION"; + public static final String after_declaration_str = "AFTER_DECLARATION"; + public static final String end_file_str = "END_FILE"; + public static final String language_str = "language"; + public static final String placement_str = "placement"; + public static final String text_str = "text"; + //}}} + public Annotation(AnnotationDeclaration declaration) { m_declaration = declaration; @@ -66,10 +146,57 @@ public String getName() return null; } + /*! + * @brief Returns the full scoped name of the type, unless the developer uses + * `TemplateSTGroup.enable_using_explicitly_modules()`, by removing from the full scoped name the current + * `Context` scope. + */ + public String getScopedname() throws RuntimeGenerationException + { + String scoped_name = getFullScopedname(); + + if (!com.eprosima.idl.parser.typecode.TypeCode.ctx.is_enabled_custom_property_in_current_group(com.eprosima.idl.parser.typecode.TypeCode.ctx.using_explicitly_modules_custom_property)) + { + return scoped_name; + } + + String current_scope = com.eprosima.idl.parser.typecode.TypeCode.ctx.getScope(); + + if(current_scope.isEmpty() || !scoped_name.startsWith(current_scope + "::")) + { + return scoped_name; + } + + return scoped_name.replace(current_scope + "::", ""); + } + + /*! + * @brief Return the scoped name of the type. + */ + public String getFullScopedname() throws RuntimeGenerationException + { + if(m_declaration == null) + { + throw new RuntimeGenerationException("Annotation declaration not initialized"); + } + return m_declaration.getScopedname(); + } + + public String getROS2Scopedname() throws RuntimeGenerationException + { + if(m_declaration == null) + { + throw new RuntimeGenerationException("Annotation declaration not initialized"); + } + return m_declaration.getROS2Scopedname(); + } + public boolean addValue(String value) { if(m_members.size() != 1) + { return false; + } ((AnnotationMember)m_members.values().toArray()[0]).setValue(value); @@ -83,16 +210,25 @@ public boolean addValue(String attribute, String value) if(member != null) { member.setValue(value); + // Check that in case of an Enum the set value is in the enumeration. + // ParseException is thrown otherwise. + member.getEnumStringValue(); } else + { return false; + } return true; } - public String getValue() + public String getValue() throws RuntimeGenerationException { - if(m_members.size() != 1) return null; + if(m_members.size() != 1) + { + throw new RuntimeGenerationException("Error in annotation " + getName() + + ": accessing value of a multiple parameter exception"); + } return ((AnnotationMember)m_members.values().toArray()[0]).getValue(); } @@ -112,6 +248,81 @@ public Collection getValueList() return m_members.values(); } + public boolean isIsVerbatim() + { + return getName().equals(Annotation.verbatim_str); + } + + public boolean isIsUnit() + { + return getName().equals(Annotation.unit_str); + } + + public boolean isIsMax() + { + return getName().equals(Annotation.max_str); + } + + public boolean isIsMin() + { + return getName().equals(Annotation.min_str); + } + + public boolean isIsRange() + { + return getName().equals(Annotation.range_str); + } + + public boolean isIsHashId() + { + return getName().equals(Annotation.hashid_str); + } + + public boolean isIsBuiltin() + { + if (getName().equals(Annotation.ami_str) || + getName().equals(Annotation.appendable_str) || + getName().equals(Annotation.autoid_str) || + getName().equals(Annotation.bit_bound_str) || + getName().equals(Annotation.data_representation_str) || + getName().equals(Annotation.default_str) || + getName().equals(Annotation.default_literal_str) || + getName().equals(Annotation.default_nested_str) || + getName().equals(Annotation.eprosima_key_str) || + getName().equals(Annotation.extensibility_str) || + getName().equals(Annotation.external_str) || + getName().equals(Annotation.final_str) || + getName().equals(Annotation.hashid_str) || + getName().equals(Annotation.id_str) || + getName().equals(Annotation.ignore_literal_names_str) || + getName().equals(Annotation.key_str) || + getName().equals(Annotation.max_str) || + getName().equals(Annotation.min_str) || + getName().equals(Annotation.must_understand_str) || + getName().equals(Annotation.mutable_str) || + getName().equals(Annotation.nested_str) || + getName().equals(Annotation.non_serialized_str) || + getName().equals(Annotation.oneway_str) || + getName().equals(Annotation.optional_str) || + getName().equals(Annotation.position_str) || + getName().equals(Annotation.range_str) || + getName().equals(Annotation.service_str) || + getName().equals(Annotation.topic_str) || + getName().equals(Annotation.try_construct_str) || + getName().equals(Annotation.unit_str) || + getName().equals(Annotation.value_str) || + getName().equals(Annotation.verbatim_str)) + { + return true; + } + return false; + } + + public int getValuesSize() + { + return m_members.size(); + } + private HashMap m_members = null; private AnnotationDeclaration m_declaration = null; } diff --git a/src/main/java/com/eprosima/idl/parser/tree/AnnotationDeclaration.java b/src/main/java/com/eprosima/idl/parser/tree/AnnotationDeclaration.java index 74aab890..60ce4d4f 100644 --- a/src/main/java/com/eprosima/idl/parser/tree/AnnotationDeclaration.java +++ b/src/main/java/com/eprosima/idl/parser/tree/AnnotationDeclaration.java @@ -42,6 +42,11 @@ public List getMembers() return new ArrayList(m_members.values()); } + public int getMembersSize() + { + return m_members.values().size(); + } + public void addMembers(AnnotationDeclaration annotation) { m_members.putAll(annotation.m_members); @@ -49,6 +54,9 @@ public void addMembers(AnnotationDeclaration annotation) public boolean addMember(AnnotationMember member) { + // Check that in case of an Enum the given value is in the enumeration. + // ParseException is thrown otherwise. + member.getEnumStringValue(); if(!m_members.containsKey(member.getName())) { m_members.put(member.getName(), member); diff --git a/src/main/java/com/eprosima/idl/parser/tree/AnnotationMember.java b/src/main/java/com/eprosima/idl/parser/tree/AnnotationMember.java index 5f2d9365..0984b852 100644 --- a/src/main/java/com/eprosima/idl/parser/tree/AnnotationMember.java +++ b/src/main/java/com/eprosima/idl/parser/tree/AnnotationMember.java @@ -14,6 +14,7 @@ package com.eprosima.idl.parser.tree; +import com.eprosima.idl.parser.exception.ParseException; import com.eprosima.idl.parser.typecode.Member; import com.eprosima.idl.parser.typecode.EnumMember; import com.eprosima.idl.parser.typecode.EnumTypeCode; @@ -51,20 +52,26 @@ public TypeCode getTypecode() public String getValue() { - if (m_typecode.isIsType_c()) // Enum + if (m_typecode.isIsEnumType()) { EnumTypeCode enumTC = (EnumTypeCode)m_typecode; int idx = 0; + int default_idx = 0; for (Member m : enumTC.getMembers()) { if (m.getName().equals(m_value)) { return Integer.toString(idx); } + else if (m.isAnnotationDefaultLiteral()) + { + default_idx = idx; + } idx++; } + return Integer.toString(default_idx); } - if (m_typecode.isIsType_d()) // String + else if (m_typecode.isIsStringType() || m_typecode.isIsWStringType()) { if (m_value != null) { @@ -73,8 +80,13 @@ public String getValue() return m_value.substring(1, m_value.length() - 1); } } + if (m_typecode.isIsWStringType()) + { + return "L\"\""; + } + return ""; } - if (m_typecode.isPrimitiveType()) + else if (m_typecode.isPrimitiveType()) { if (m_value != null) { @@ -86,6 +98,31 @@ public String getValue() return m_value; } } + return m_typecode.getInitialValue(); + } + return m_value; + } + + public String getEnumStringValue() + { + if (m_value != null && m_typecode.isIsEnumType()) + { + EnumTypeCode enumTC = (EnumTypeCode)m_typecode; + for (Member m : enumTC.getMembers()) + { + String value = m_value; + if (value.startsWith("\"") && value.endsWith("\"")) + { + value = value.substring(1, value.length() - 1); + } + String[] value_with_scopes = value.split("::"); + value = value_with_scopes[value_with_scopes.length - 1]; + if (m.getName().equals(value)) + { + return value; + } + } + throw new ParseException(null, m_value + " is not a valid label for " + m_name); } return m_value; } @@ -95,6 +132,31 @@ public void setValue(String value) m_value = value; } + public boolean isIsVerbatimPlacement() + { + return getName().equals(Annotation.placement_str); + } + + public boolean isIsVerbatimLanguage() + { + return getName().equals(Annotation.language_str); + } + + public boolean isIsVerbatimText() + { + return getName().equals(Annotation.text_str); + } + + public boolean isIsMax() + { + return getName().equals(Annotation.max_str); + } + + public boolean isIsMin() + { + return getName().equals(Annotation.min_str); + } + private String m_name = null; private TypeCode m_typecode = null; diff --git a/src/main/java/com/eprosima/idl/parser/tree/TreeNode.java b/src/main/java/com/eprosima/idl/parser/tree/TreeNode.java index 981efe24..3fead6fb 100644 --- a/src/main/java/com/eprosima/idl/parser/tree/TreeNode.java +++ b/src/main/java/com/eprosima/idl/parser/tree/TreeNode.java @@ -51,7 +51,9 @@ public String getName() public String getScopedname() { if(m_scope == null || m_scope.isEmpty()) + { return m_name; + } return m_scope + "::" + m_name; } @@ -59,7 +61,9 @@ public String getScopedname() public String getROS2Scopedname() { if(m_scope == null || m_scope.isEmpty()) + { return m_name; + } return m_scope + "::dds_::" + m_name + "_"; } @@ -67,7 +71,9 @@ public String getROS2Scopedname() public String getCScopedname() { if(m_scope.isEmpty()) + { return m_name; + } return m_scope.replace("::", "_") + "_" + m_name; } @@ -75,7 +81,9 @@ public String getCScopedname() public String getJavaScopedname() { if(m_scope.isEmpty()) + { return m_name; + } return m_scope.replace("::", ".") + "." + m_name; } @@ -94,9 +102,13 @@ public String getFormatedScopedname() String ret = null; if(m_scope == null || m_scope.isEmpty()) + { ret = m_name; + } else + { ret = m_scope + "::" + m_name; + } return ret.replaceAll("::", "_"); } @@ -110,7 +122,9 @@ public boolean getHasScope() public void addAnnotation(Context ctx, Annotation annotation) { if(annotation != null) + { m_annotations.put(annotation.getName(), annotation); + } } @Override diff --git a/src/main/java/com/eprosima/idl/parser/typecode/AliasTypeCode.java b/src/main/java/com/eprosima/idl/parser/typecode/AliasTypeCode.java index aba59733..244695ab 100644 --- a/src/main/java/com/eprosima/idl/parser/typecode/AliasTypeCode.java +++ b/src/main/java/com/eprosima/idl/parser/typecode/AliasTypeCode.java @@ -14,6 +14,7 @@ package com.eprosima.idl.parser.typecode; +import com.eprosima.idl.parser.exception.RuntimeGenerationException; import com.eprosima.idl.util.Pair; import java.util.List; import org.stringtemplate.v4.ST; @@ -130,9 +131,36 @@ public String getName() return m_name; } + /*! + * @brief Returns the full scoped name of the type, unless the developer uses + * `TemplateSTGroup.enable_custom_proeprty("using_explicitly_modules")`, by removing from the full scoped name the + * current `Context` scope. + */ public String getScopedname() { - if (m_scope.isEmpty()) + String scoped_name = getFullScopedname(); + + if (!ctx.is_enabled_custom_property_in_current_group(ctx.using_explicitly_modules_custom_property)) + { + return scoped_name; + } + + String current_scope = ctx.getScope(); + + if(current_scope.isEmpty() || !scoped_name.startsWith(current_scope + "::")) + { + return scoped_name; + } + + return scoped_name.replace(current_scope + "::", ""); + } + + /*! + * @brief Return the scoped name of the type. + */ + public String getFullScopedname() + { + if(m_scope.isEmpty()) { return m_name; } @@ -150,6 +178,16 @@ public String getROS2Scopedname() return m_scope + "::dds_::" + m_name + "_"; } + public String getCScopedname() + { + if(m_scope.isEmpty()) + { + return m_name; + } + + return m_scope.replace("::", "_") + "_" + m_name; + } + public String getScope() { return m_scope; @@ -222,7 +260,7 @@ public String getInitialValue() return super.getContentTypeCode().getInitialValue(); } - /*** Functions to know the type in string templates ***/ + //{{{ Functions to know the type in string templates @Override public boolean isIsType_d() { @@ -270,6 +308,12 @@ public boolean isIsBitmaskType() return super.getContentTypeCode().isIsBitmaskType(); } + @Override + public boolean isIsEnumType() + { + return super.getContentTypeCode().isIsEnumType(); + } + public boolean isIsType_10() { return true; @@ -281,9 +325,9 @@ public String getTypeIdentifier() return "EK_MINIMAL"; } - /*** End of functions to know the type in string templates ***/ + //}}} - /*** Functions that alias has to export because some typecodes have them*/ + //{{{ Functions that alias has to export because some typecodes have them public String getMaxsize() { return super.getContentTypeCode().getMaxsize(); @@ -294,17 +338,34 @@ public String getSize() return super.getContentTypeCode().getSize(); } - public List getDimensions() + public String getEvaluatedMaxsize() throws RuntimeGenerationException + { + return super.getContentTypeCode().getEvaluatedMaxsize(); + } + + public List getDimensions() throws RuntimeGenerationException { if (super.getContentTypeCode() instanceof ArrayTypeCode) { return ((ArrayTypeCode) super.getContentTypeCode()).getDimensions(); } - return null; + throw new RuntimeGenerationException("Error in alias " + m_name + + ": trying accessing dimensions for a non-array type"); + } + + public List getEvaluatedDimensions() throws RuntimeGenerationException + { + if (super.getContentTypeCode() instanceof ArrayTypeCode) + { + return ((ArrayTypeCode) super.getContentTypeCode()).getEvaluatedDimensions(); + } + + throw new RuntimeGenerationException("Error in alias " + m_name + + ": trying accessing dimensions for a non-array type"); } - public int getFullBitSize() + public int getFullBitSize() // Function for alias when enclosed type is a BitsetTypeCode { int returnedValue = 0; @@ -316,7 +377,31 @@ public int getFullBitSize() return returnedValue; } - /*** End of functions that alias has to export because some typecodes have them*/ + public TypeCode getInheritance() // Function for alias when enclosed type is a StructTypeCode + { + TypeCode returnedValue = null; + + if (getContentTypeCode() instanceof StructTypeCode) + { + returnedValue = ((StructTypeCode)getContentTypeCode()).getInheritance(); + } + + return returnedValue; + } + + public List getMembers() // Function for alias when enclosed type is a StructTypeCode + { + List returnedValue = null; + + if (getContentTypeCode() instanceof StructTypeCode) + { + returnedValue = ((StructTypeCode)getContentTypeCode()).getMembers(); + } + + return returnedValue; + } + + //}}} private String m_name = null; diff --git a/src/main/java/com/eprosima/idl/parser/typecode/ArrayTypeCode.java b/src/main/java/com/eprosima/idl/parser/typecode/ArrayTypeCode.java index ad307726..987a1095 100644 --- a/src/main/java/com/eprosima/idl/parser/typecode/ArrayTypeCode.java +++ b/src/main/java/com/eprosima/idl/parser/typecode/ArrayTypeCode.java @@ -36,7 +36,15 @@ public boolean isIsType_f() @Override public String getTypeIdentifier() { - return "TI_PLAIN_ARRAY_SMALL"; + String type_id = "TI_PLAIN_ARRAY_SMALL"; + for (int count = 0; count < evaluated_dimensions_.size(); ++count) + { + if (Integer.parseInt(evaluated_dimensions_.get(count)) >= 256) + { + return "TI_PLAIN_ARRAY_LARGE"; + } + } + return type_id; } @Override @@ -185,6 +193,11 @@ public List getEvaluatedDimensions() return evaluated_dimensions_; } + public int getEvaluatedDimensionsSize() + { + return evaluated_dimensions_.size(); + } + public String getSize() { String ret = ""; diff --git a/src/main/java/com/eprosima/idl/parser/typecode/BitfieldSpec.java b/src/main/java/com/eprosima/idl/parser/typecode/BitfieldSpec.java index 262654e5..9355b067 100644 --- a/src/main/java/com/eprosima/idl/parser/typecode/BitfieldSpec.java +++ b/src/main/java/com/eprosima/idl/parser/typecode/BitfieldSpec.java @@ -26,7 +26,7 @@ public static int generateKind( } else if (size <= 8) { - return Kind.KIND_CHAR; + return Kind.KIND_OCTET; } else if (size <= 16) { diff --git a/src/main/java/com/eprosima/idl/parser/typecode/BitmaskTypeCode.java b/src/main/java/com/eprosima/idl/parser/typecode/BitmaskTypeCode.java index 224c4414..aea27586 100644 --- a/src/main/java/com/eprosima/idl/parser/typecode/BitmaskTypeCode.java +++ b/src/main/java/com/eprosima/idl/parser/typecode/BitmaskTypeCode.java @@ -20,6 +20,7 @@ import java.util.Set; import com.eprosima.idl.parser.exception.ParseException; +import com.eprosima.idl.parser.exception.RuntimeGenerationException; import com.eprosima.idl.parser.tree.Annotation; import com.eprosima.idl.context.Context; @@ -133,8 +134,15 @@ public boolean addBitmask( { if (bitmask.getAnnotations().get("position") != null) { - // Position from attribute - return addBitmask(bitmask, Integer.parseInt(bitmask.getAnnotations().get("position").getValue())); + try + { + // Position from attribute + return addBitmask(bitmask, Integer.parseInt(bitmask.getAnnotations().get("position").getValue())); + } + catch (RuntimeGenerationException ex) + { + // Should not be called as @position annotation has only one parameter + } } // Position autoassigned return addBitmask(bitmask, m_current_base); @@ -232,17 +240,24 @@ public void addAnnotation( super.addAnnotation(ctx, annotation); if (annotation.getName().equals("bit_bound")) { - m_bit_bound = Integer.parseInt(annotation.getValue()); - // Sanity check - Set keys = m_bitmasks.keySet(); - for (String key : keys) { - int position = m_bitmasks.get(key).getPosition(); - if (position < 0 || position >= m_bit_bound) - { - throw new ParseException(null, "Bitmask member "+ key +" out of bounds. Requested position: " - + position + " with @bit_bound value: " + m_bit_bound); + try + { + m_bit_bound = Integer.parseInt(annotation.getValue()); + // Sanity check + Set keys = m_bitmasks.keySet(); + for (String key : keys) { + int position = m_bitmasks.get(key).getPosition(); + if (position < 0 || position >= m_bit_bound) + { + throw new ParseException(null, "Bitmask member "+ key +" out of bounds. Requested position: " + + position + " with @bit_bound value: " + m_bit_bound); + } } } + catch (RuntimeGenerationException ex) + { + // Should not be called as @bit_bound annotation only has one parameter + } } } diff --git a/src/main/java/com/eprosima/idl/parser/typecode/BitsetTypeCode.java b/src/main/java/com/eprosima/idl/parser/typecode/BitsetTypeCode.java index 55fcaca0..baf7f6df 100644 --- a/src/main/java/com/eprosima/idl/parser/typecode/BitsetTypeCode.java +++ b/src/main/java/com/eprosima/idl/parser/typecode/BitsetTypeCode.java @@ -104,7 +104,12 @@ public List getAllBitfields() // Alias for getBitfields(true) for stg public boolean addBitfield( Bitfield bitfield) { - if (!m_bitfields.containsKey(bitfield.getName())) + if (null == bitfield.getName()) + { + m_current_base += bitfield.getSpec().getBitSize(); + return true; + } + if (!m_bitfields.containsKey(bitfield.getName()) ) { m_bitfields.put(bitfield.getName(), bitfield); bitfield.setBasePosition(m_current_base); @@ -161,13 +166,7 @@ public TypeCode getEnclosedInheritance() public int getBitSize() { - int size = 0; - - for (Bitfield bf : m_bitfields.values()) - { - size += bf.getSpec().getBitSize(); - } - return size; + return m_current_base; } public int getFullBitSize() @@ -179,11 +178,7 @@ public int getFullBitSize() size += enclosed_super_type_.getFullBitSize(); } - for (Bitfield bf : m_bitfields.values()) - { - size += bf.getSpec().getBitSize(); - } - return size; + return m_current_base + size; } private BitsetTypeCode enclosed_super_type_ = null; diff --git a/src/main/java/com/eprosima/idl/parser/typecode/CollectionElement.java b/src/main/java/com/eprosima/idl/parser/typecode/CollectionElement.java new file mode 100644 index 00000000..2bbd8317 --- /dev/null +++ b/src/main/java/com/eprosima/idl/parser/typecode/CollectionElement.java @@ -0,0 +1,41 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.eprosima.idl.parser.typecode; + +public class CollectionElement extends MemberAppliedAnnotations +{ + public CollectionElement() + { + super(); + } + + public CollectionElement(TypeCode typecode) + { + super(); + typecode_ = typecode; + } + + public TypeCode getTypecode() + { + return typecode_; + } + + public void setTypecode(TypeCode typecode) + { + typecode_ = typecode; + } + + private TypeCode typecode_ = null; +} diff --git a/src/main/java/com/eprosima/idl/parser/typecode/ContainerTypeCode.java b/src/main/java/com/eprosima/idl/parser/typecode/ContainerTypeCode.java index 49610017..d740d275 100644 --- a/src/main/java/com/eprosima/idl/parser/typecode/ContainerTypeCode.java +++ b/src/main/java/com/eprosima/idl/parser/typecode/ContainerTypeCode.java @@ -18,6 +18,8 @@ public abstract class ContainerTypeCode extends TypeCode { + public static String default_unbounded_max_size = "0"; + protected ContainerTypeCode(int kind) { super(kind); @@ -34,7 +36,7 @@ protected ContainerTypeCode(int kind) public TypeCode getContentTypeCode() { - return m_contentTypeCode; + return collection_element_.getTypecode(); } public Definition getContentDefinition() @@ -44,7 +46,7 @@ public Definition getContentDefinition() public void setContentTypeCode(TypeCode contentTypeCode) { - m_contentTypeCode = contentTypeCode; + collection_element_.setTypecode(contentTypeCode); } public void setContentDefinition(Definition contentDefinition) @@ -56,13 +58,17 @@ public int getDepth() { int ret = 1; - if (m_contentTypeCode.isPrimitive()) { - return ret; - } else { - if (m_contentTypeCode instanceof ContainerTypeCode) { - ret += ((ContainerTypeCode) m_contentTypeCode).getDepth(); - } - } + if (collection_element_.getTypecode().isPrimitive()) + { + return ret; + } + else + { + if (collection_element_.getTypecode() instanceof ContainerTypeCode) + { + ret += ((ContainerTypeCode) collection_element_.getTypecode()).getDepth(); + } + } return ret; } @@ -70,9 +76,9 @@ public int getDepth() @Override public boolean isIsPlain() { - if (m_contentTypeCode != null) + if (collection_element_.getTypecode() != null) { - return m_contentTypeCode.isIsPlain(); + return collection_element_.getTypecode().isIsPlain(); } return false; } @@ -80,13 +86,13 @@ public boolean isIsPlain() @Override public boolean isIsBounded() { - if (m_contentTypeCode != null) + if (collection_element_.getTypecode() != null) { - return m_contentTypeCode.isIsBounded(); + return collection_element_.getTypecode().isIsBounded(); } return false; } - private TypeCode m_contentTypeCode = null; + private CollectionElement collection_element_ = new CollectionElement(); private Definition m_contentDefinition = null; } diff --git a/src/main/java/com/eprosima/idl/parser/typecode/EnumTypeCode.java b/src/main/java/com/eprosima/idl/parser/typecode/EnumTypeCode.java index 56551700..cfd107b1 100644 --- a/src/main/java/com/eprosima/idl/parser/typecode/EnumTypeCode.java +++ b/src/main/java/com/eprosima/idl/parser/typecode/EnumTypeCode.java @@ -99,7 +99,7 @@ public String getInitialValue() { if (getMembers().size() > 0) { - return (getScope() != null ? getScope() + "::" : "") + getMembers().get(0).getName(); + return getScopedname() + "::" + getMembers().get(0).getName(); } return ""; @@ -133,5 +133,11 @@ public boolean isIsPlain() { return true; } + + public int getBitBound() + { + // TODO: pending @bit_bound annotation application to enum types + return 32; + } } diff --git a/src/main/java/com/eprosima/idl/parser/typecode/MapTypeCode.java b/src/main/java/com/eprosima/idl/parser/typecode/MapTypeCode.java index bebb2667..9b685181 100644 --- a/src/main/java/com/eprosima/idl/parser/typecode/MapTypeCode.java +++ b/src/main/java/com/eprosima/idl/parser/typecode/MapTypeCode.java @@ -37,6 +37,10 @@ public boolean isIsType_19() @Override public String getTypeIdentifier() { + if (!isUnbound() && Integer.parseInt(evaluated_maxsize_) >= 256) + { + return "TI_PLAIN_MAP_LARGE"; + } return "TI_PLAIN_MAP_SMALL"; } @@ -92,16 +96,18 @@ public String getIdlTypename() return st.render(); } + @Override public String getMaxsize() { if (m_maxsize == null) { - return "100"; + return default_unbounded_max_size; } return m_maxsize; } + @Override public String getEvaluatedMaxsize() { if (evaluated_maxsize_ == null) @@ -156,12 +162,25 @@ public void setValueDefinition( m_valueDefinition = valueDefinition; } + /** + * This API is to check if this specific collection has a bound set. + * It does not check if the complete collection is bounded or not. + */ + public boolean isUnbound() + { + return null == m_maxsize; + } + @Override public boolean isIsPlain() { return false; } + /** + * This API is to check if ultimately the collection element is bounded. + * In order to check if this specific collection has bounds, please use isUnbound API. + */ @Override public boolean isIsBounded() { diff --git a/src/main/java/com/eprosima/idl/parser/typecode/Member.java b/src/main/java/com/eprosima/idl/parser/typecode/Member.java index 5d86762c..3d07cb80 100644 --- a/src/main/java/com/eprosima/idl/parser/typecode/Member.java +++ b/src/main/java/com/eprosima/idl/parser/typecode/Member.java @@ -16,25 +16,19 @@ import com.eprosima.idl.parser.exception.RuntimeGenerationException; import com.eprosima.idl.parser.tree.Annotation; -import com.eprosima.idl.parser.tree.Notebook; -import com.eprosima.idl.context.Context; -import java.util.Map; -import java.util.HashMap; -import java.util.Collection; - -public class Member implements Notebook +public class Member extends MemberAppliedAnnotations { public Member() { - m_annotations = new HashMap(); + super(); } public Member(TypeCode typecode, String name) { + super(); m_typecode = typecode; m_name = name; - m_annotations = new HashMap(); } public String getName() @@ -73,140 +67,6 @@ public void setTypecode(TypeCode typecode) m_typecode = typecode; } - @Override - public void addAnnotation(Context ctx, Annotation annotation) - { - if(annotation != null) - { - m_annotations.put(annotation.getName(), annotation); - } - } - - @Override - public Map getAnnotations() - { - return m_annotations; - } - - public Collection getAnnotationList() - { - return m_annotations.values(); - } - - public boolean isAnnotationOptional() - { - Annotation ann = m_annotations.get("optional"); - if (ann != null) - { - return ann.getValue().toUpperCase().equals("TRUE"); - } - return false; - } - - public boolean isAnnotationExternal() - { - Annotation ann = m_annotations.get("external"); - if (ann != null) - { - return ann.getValue().toUpperCase().equals("TRUE"); - } - return false; - } - - public boolean isAnnotationMustUnderstand() - { - Annotation ann = m_annotations.get("must_understand"); - if (ann != null) - { - return ann.getValue().toUpperCase().equals("TRUE"); - } - return false; - } - - public boolean isAnnotationNonSerialized() - { - Annotation ann = m_annotations.get("non_serialized"); - if (ann != null) - { - return ann.getValue().toUpperCase().equals("TRUE"); - } - return false; - } - - public boolean isAnnotationKey() - { - Annotation ann = m_annotations.get("key"); - if (ann == null) - { - ann = m_annotations.get("Key"); // Try old way - } - if (ann != null) - { - return ann.getValue().toUpperCase().equals("TRUE"); - } - return false; - } - - public Short getAnnotationBitBound() - { - Annotation ann = m_annotations.get("bit_bound"); - if (ann != null) - { - String value = ann.getValue(); - if (value.equals("-1")) - { - return null; - } - return Short.parseShort(value); - } - return null; - } - - public boolean isAnnotationDefaultLiteral() - { - return m_annotations.get("default_literal") != null; - } - - public String getAnnotationValue() - { - Annotation ann = m_annotations.get("value"); - if (ann != null) - { - return ann.getValue(); - } - return null; - } - - public Short getAnnotationPosition() - { - Annotation ann = m_annotations.get("position"); - if (ann != null) - { - String value = ann.getValue(); - if (value.equals("-1")) - { - return null; - } - return Short.parseShort(value); - } - return null; - } - - public boolean isAnnotationDefault() - { - return m_annotations.get("default") != null; - } - - public String getAnnotationDefaultValue() - { - Annotation ann = m_annotations.get("default"); - if (ann != null) - { - return ann.getValue(); - } - return ""; - } - public boolean isIsPlain() { if (m_typecode != null && !isAnnotationOptional()) @@ -225,40 +85,6 @@ public boolean isIsBounded() return false; } - public boolean isAnnotationId() - { - return null != m_annotations.get(Annotation.id_str); - } - - public String getAnnotationIdValue() throws RuntimeGenerationException - { - Annotation ann = m_annotations.get(Annotation.id_str); - if (ann == null) - { - throw new RuntimeGenerationException("Error in member " + m_name + ": @" + Annotation.id_str + - " annotation not found."); - } - - return ann.getValue(); - } - - public boolean isAnnotationHashid() - { - return null != m_annotations.get(Annotation.hashid_str); - } - - public String getAnnotationHashidValue() throws RuntimeGenerationException - { - Annotation ann = m_annotations.get(Annotation.hashid_str); - if (ann == null) - { - throw new RuntimeGenerationException("Error in member " + m_name + ": @" + Annotation.hashid_str + - " annotation not found."); - } - - return ann.getValue(); - } - /*! * Sets the member's id. * @@ -300,12 +126,44 @@ public int getIndex() return index_; } + public boolean isAnnotationId() + { + return null != getAnnotations().get(Annotation.id_str); + } + + public String getAnnotationIdValue() throws RuntimeGenerationException + { + Annotation ann = getAnnotations().get(Annotation.id_str); + if (ann == null) + { + throw new RuntimeGenerationException("Error in member " + m_name + ": @" + Annotation.id_str + + " annotation not found."); + } + + return ann.getValue(); + } + + public boolean isAnnotationHashid() + { + return null != getAnnotations().get(Annotation.hashid_str); + } + + public String getAnnotationHashidValue() throws RuntimeGenerationException + { + Annotation ann = getAnnotations().get(Annotation.hashid_str); + if (ann == null) + { + throw new RuntimeGenerationException("Error in member " + m_name + ": @" + Annotation.hashid_str + + " annotation not found."); + } + + return ann.getValue(); + } + private String m_name = null; private TypeCode m_typecode = null; - private HashMap m_annotations = null; - public static final int MEMBER_ID_INVALID = 0x0FFFFFFF; private int id_ = MEMBER_ID_INVALID; diff --git a/src/main/java/com/eprosima/idl/parser/typecode/MemberAppliedAnnotations.java b/src/main/java/com/eprosima/idl/parser/typecode/MemberAppliedAnnotations.java new file mode 100644 index 00000000..b9008733 --- /dev/null +++ b/src/main/java/com/eprosima/idl/parser/typecode/MemberAppliedAnnotations.java @@ -0,0 +1,320 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.eprosima.idl.parser.typecode; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import com.eprosima.idl.context.Context; +import com.eprosima.idl.parser.exception.RuntimeGenerationException; +import com.eprosima.idl.parser.tree.Annotation; +import com.eprosima.idl.parser.tree.Notebook; + +public class MemberAppliedAnnotations implements Notebook +{ + public enum TryConstructFailAction + { + INVALID(0), + DISCARD(1), + USE_DEFAULT(2), + TRIM(3); + + private int value_ = 0; + + private TryConstructFailAction(int value) + { + value_ = value; + } + + public int get_value() + { + return value_; + } + }; + + public static TryConstructFailAction default_try_construct = TryConstructFailAction.DISCARD; + + @Override + public void addAnnotation(Context ctx, Annotation annotation) + { + if(annotation != null) + { + m_annotations.put(annotation.getName(), annotation); + } + } + + @Override + public Map getAnnotations() + { + return m_annotations; + } + + public Collection getAnnotationList() + { + return m_annotations.values(); + } + + //{{{ Auxiliary function to check which built-in annotation is the instance. + + public boolean isAnnotationBitBound() + { + return m_annotations.get(Annotation.bit_bound_str) != null; + } + + public Short getAnnotationBitBoundValue() throws RuntimeGenerationException + { + try + { + if (isAnnotationBitBound()) + { + return Short.parseShort(m_annotations.get(Annotation.bit_bound_str).getValue()); + } + } + catch (RuntimeGenerationException ex) + { + // Should never be called because isAnnotationBitBound() was previously called. + } + return 0; + } + + public boolean isAnnotationDefault() + { + return m_annotations.get(Annotation.default_str) != null; + } + + public String getAnnotationDefaultValue() throws RuntimeGenerationException + { + Annotation ann = m_annotations.get(Annotation.default_str); + if (ann != null) + { + return ann.getValue(); + } + throw new RuntimeGenerationException("Error getting @" + Annotation.default_str + + " annotation value: annotation not found"); + } + + public boolean isAnnotationDefaultLiteral() + { + return m_annotations.get(Annotation.default_literal_str) != null; + } + + public boolean isAnnotationExternal() + { + Annotation ann = m_annotations.get(Annotation.external_str); + if (ann != null) + { + try + { + return ann.getValue().toUpperCase().equals(Annotation.capitalized_true_str); + } + catch (RuntimeGenerationException ex) + { + // Should not be called as @external annotation has only one parameter + } + } + return false; + } + + public boolean isAnnotationHashid() + { + return m_annotations.get(Annotation.hashid_str) != null; + } + + public boolean isAnnotationId() + { + return m_annotations.get(Annotation.id_str) != null; + } + + public boolean isAnnotationKey() + { + Annotation ann = m_annotations.get(Annotation.key_str); + if (ann == null) + { + ann = m_annotations.get(Annotation.eprosima_key_str); // Try old way + } + if (ann != null) + { + try + { + return ann.getValue().toUpperCase().equals(Annotation.capitalized_true_str); + } + catch (RuntimeGenerationException ex) + { + // Should not be called as @key annotation has only one parameter + } + } + return false; + } + + public boolean isAnnotationMustUnderstand() + { + Annotation ann = m_annotations.get(Annotation.must_understand_str); + if (ann != null) + { + try + { + return ann.getValue().toUpperCase().equals(Annotation.capitalized_true_str); + } + catch (RuntimeGenerationException ex) + { + // Should not be called as @must_understand annotation has only one parameter + } + } + return false; + } + + public boolean isAnnotationNonSerialized() + { + Annotation ann = m_annotations.get(Annotation.non_serialized_str); + if (ann != null) + { + try + { + return ann.getValue().toUpperCase().equals(Annotation.capitalized_true_str); + } + catch (RuntimeGenerationException ex) + { + // Should not be called as @non_serialized annotation has only one parameter + } + } + return false; + } + + public boolean isAnnotationOptional() + { + Annotation ann = m_annotations.get(Annotation.optional_str); + if (ann != null) + { + try + { + return ann.getValue().toUpperCase().equals(Annotation.capitalized_true_str); + } + catch (RuntimeGenerationException ex) + { + // Should not be called as @optional annotation only has one parameter + } + } + return false; + } + + public boolean isAnnotationPosition() + { + return m_annotations.get(Annotation.position_str) != null; + } + + public Short getAnnotationPositionValue() + { + try + { + if (isAnnotationPosition()) + { + return Short.parseShort(m_annotations.get(Annotation.position_str).getValue()); + } + } + catch (RuntimeGenerationException ex) + { + // Should never be called because isAnnotationPosition() was previously called. + } + return 0; + } + + //{{{ @try_construct + public boolean isAnnotationTryConstruct() + { + return m_annotations.containsKey(Annotation.try_construct_str); + } + + void calculate_try_construct() throws RuntimeGenerationException + { + if (TryConstructFailAction.INVALID == try_construct_) + { + if (isAnnotationTryConstruct()) + { + if (m_annotations.get(Annotation.try_construct_str).getValue().equals(Annotation.try_construct_discard_str)) + { + try_construct_ = TryConstructFailAction.DISCARD; + } + else if (m_annotations.get(Annotation.try_construct_str).getValue().equals(Annotation.try_construct_use_default_str)) + { + try_construct_ = TryConstructFailAction.USE_DEFAULT; + } + else if (m_annotations.get(Annotation.try_construct_str).getValue().equals(Annotation.try_construct_trim_str)) + { + try_construct_ = TryConstructFailAction.TRIM; + } + else + { + throw new RuntimeGenerationException("try_construct annotation does not have a recognized value"); + } + } + else + { + try_construct_ = default_try_construct; + } + } + } + + public TryConstructFailAction get_try_construct() throws RuntimeGenerationException + { + calculate_try_construct(); + return try_construct_; + } + + public boolean isAnnotationDiscard() throws RuntimeGenerationException + { + calculate_try_construct(); + return TryConstructFailAction.DISCARD == try_construct_; + } + + public boolean isAnnotationUseDefault() throws RuntimeGenerationException + { + calculate_try_construct(); + return TryConstructFailAction.USE_DEFAULT == try_construct_; + } + + public boolean isAnnotationTrim() throws RuntimeGenerationException + { + calculate_try_construct(); + return TryConstructFailAction.TRIM == try_construct_; + } + //}}} + + public boolean isAnnotationValue() + { + return m_annotations.get(Annotation.value_str) != null; + } + + public String getAnnotationValueValue() + { + try + { + if (isAnnotationValue()) + { + return m_annotations.get(Annotation.value_str).getValue(); + } + } + catch (RuntimeGenerationException ex) + { + // Should never be called because isAnnotationValue() was previously called. + } + return ""; + } + //}}} + + private HashMap m_annotations = new HashMap(); + + private TryConstructFailAction try_construct_ = TryConstructFailAction.INVALID; +} diff --git a/src/main/java/com/eprosima/idl/parser/typecode/MemberedTypeCode.java b/src/main/java/com/eprosima/idl/parser/typecode/MemberedTypeCode.java index 3e6084b0..34a31486 100644 --- a/src/main/java/com/eprosima/idl/parser/typecode/MemberedTypeCode.java +++ b/src/main/java/com/eprosima/idl/parser/typecode/MemberedTypeCode.java @@ -39,10 +39,39 @@ public String getName() return m_name; } + /*! + * @brief Returns the full scoped name of the type, unless the developer uses + * `TemplateSTGroup.enable_custom_proeprty("using_explicitly_modules")`, by removing from the full scoped name the + * current `Context` scope. + */ public String getScopedname() + { + String scoped_name = getFullScopedname(); + + if (!ctx.is_enabled_custom_property_in_current_group(ctx.using_explicitly_modules_custom_property)) + { + return scoped_name; + } + + String current_scope = ctx.getScope(); + + if(current_scope.isEmpty() || !scoped_name.startsWith(current_scope + "::")) + { + return scoped_name; + } + + return scoped_name.replace(current_scope + "::", ""); + } + + /*! + * @brief Return the scoped name of the type. + */ + public String getFullScopedname() { if(m_scope.isEmpty()) + { return m_name; + } return m_scope + "::" + m_name; } @@ -50,7 +79,9 @@ public String getScopedname() public String getROS2Scopedname() { if(m_scope.isEmpty()) + { return m_name; + } return m_scope + "::dds_::" + m_name + "_"; } @@ -58,7 +89,9 @@ public String getROS2Scopedname() public String getCScopedname() { if(m_scope.isEmpty()) + { return m_name; + } return m_scope.replace("::", "_") + "_" + m_name; } @@ -66,7 +99,9 @@ public String getCScopedname() public String getJavaScopedname() { if(m_scope.isEmpty()) + { return m_name; + } return m_scope.replace("::", ".") + "." + m_name; } @@ -74,7 +109,9 @@ public String getJavaScopedname() public String getJniScopedname() { if(m_scope.isEmpty()) + { return m_name; + } return m_scope.replace("::", "/") + "/" + m_name; } @@ -94,86 +131,97 @@ public List getMembers() return new ArrayList(m_members.values()); } + public int getMembersSize() + { + return m_members.size(); + } + public boolean addMember( Member member) throws ParseException { - // Check annotations. - if (member.isAnnotationOptional() && Kind.KIND_STRUCT != getKind()) + //{{{ Check annotations. + if (member.isAnnotationBitBound() && ( + Kind.KIND_ENUM != getKind() && Kind.KIND_BITMASK != getKind())) { throw new ParseException(null, "Error in member " + member.getName() + - ": @optional annotations only supported for structure's members."); + ": @" + Annotation.bit_bound_str + + " annotations only supported for enumeration's members or bitmask's members."); } - if (member.isAnnotationExternal() && ( - Kind.KIND_STRUCT != getKind() && Kind.KIND_UNION != getKind())) + if (member.isAnnotationDefaultLiteral() && Kind.KIND_ENUM != getKind()) { throw new ParseException(null, "Error in member " + member.getName() + - ": @external annotations only supported for structure's members or union's members."); + ": @" + Annotation.default_literal_str + " annotations only supported for enumeration's members."); } - if (member.isAnnotationMustUnderstand() && Kind.KIND_STRUCT != getKind()) + if (member.isAnnotationExternal() && ( + Kind.KIND_STRUCT != getKind() && Kind.KIND_UNION != getKind())) { throw new ParseException(null, "Error in member " + member.getName() + - ": @must_understand annotations only supported for structure's members."); + ": @" + Annotation.external_str + + " annotations only supported for structure's members or union's members."); } - if (member.isAnnotationNonSerialized() && Kind.KIND_STRUCT != getKind()) + if (member.isAnnotationHashid() && ( + Kind.KIND_STRUCT != getKind() && Kind.KIND_UNION != getKind())) { throw new ParseException(null, "Error in member " + member.getName() + - ": @non_serialized annotations only supported for structure's members."); + ": @" + Annotation.hashid_str + + "annotations only supported for structure's members or union's members."); } - if (member.isAnnotationKey() && Kind.KIND_STRUCT != getKind()) + if (member.isAnnotationId() && ( + Kind.KIND_STRUCT != getKind() && Kind.KIND_UNION != getKind())) { throw new ParseException(null, "Error in member " + member.getName() + - ": @" + Annotation.key_str + " annotations only supported for structure's members (Union discriminator still pending implementation)."); + ": @" + Annotation.id_str + + " annotations only supported for structure's members or union's members."); } - if (null != member.getAnnotationBitBound() && ( - Kind.KIND_ENUM != getKind() && Kind.KIND_BITMASK != getKind())) + if (member.isAnnotationKey() && Kind.KIND_STRUCT != getKind()) { throw new ParseException(null, "Error in member " + member.getName() + - ": @bit_bound annotations only supported for enumeration's members or bitmask's members."); + ": @" + Annotation.key_str + + " annotations only supported for structure's members (Union discriminator still pending implementation)."); } - if (member.isAnnotationDefaultLiteral() && Kind.KIND_ENUM != getKind()) + if (member.isAnnotationMustUnderstand() && Kind.KIND_STRUCT != getKind()) { throw new ParseException(null, "Error in member " + member.getName() + - ": @default_literal annotations only supported for enumeration's members."); + ": @" + Annotation.must_understand_str + " annotations only supported for structure's members."); } - if (null != member.getAnnotationValue() && Kind.KIND_ENUM != getKind()) + if (member.isAnnotationNonSerialized() && Kind.KIND_STRUCT != getKind()) { throw new ParseException(null, "Error in member " + member.getName() + - ": @value annotations only supported for enumeration's members."); + ": @" + Annotation.non_serialized_str + " annotations only supported for structure's members."); } - if (null != member.getAnnotationPosition() && Kind.KIND_BITMASK != getKind()) + if (member.isAnnotationOptional() && Kind.KIND_STRUCT != getKind()) { throw new ParseException(null, "Error in member " + member.getName() + - ": @position annotations only supported for bitmask's members."); + ": @" + Annotation.optional_str +" annotations only supported for structure's members."); } - if(member.isAnnotationKey() && member.isAnnotationNonSerialized()) + if (member.isAnnotationPosition() && Kind.KIND_BITMASK != getKind()) { throw new ParseException(null, "Error in member " + member.getName() + - ": @" + Annotation.key_str + " and @non_serialized annotations are incompatible."); + ": @" + Annotation.position_str + " annotations only supported for bitmask's members."); } - if(member.isAnnotationKey() && member.isAnnotationOptional()) + if (member.isAnnotationValue() && Kind.KIND_ENUM != getKind()) { throw new ParseException(null, "Error in member " + member.getName() + - ": @" + Annotation.key_str + " and @optional annotations are incompatible."); + ": @" + Annotation.value_str + " annotations only supported for enumeration's members."); } - if (member.isAnnotationId() && ( - Kind.KIND_STRUCT != getKind() && Kind.KIND_UNION != getKind())) + + if(member.isAnnotationKey() && member.isAnnotationNonSerialized()) { throw new ParseException(null, "Error in member " + member.getName() + - ": @" + Annotation.id_str + - " annotations only supported for structure's members or union's members."); + ": @" + Annotation.key_str + " and @" + Annotation.non_serialized_str + + " annotations are incompatible."); } - if (member.isAnnotationHashid() && ( - Kind.KIND_STRUCT != getKind() && Kind.KIND_UNION != getKind())) + if(member.isAnnotationKey() && member.isAnnotationOptional()) { throw new ParseException(null, "Error in member " + member.getName() + - ": @" + Annotation.hashid_str + - "annotations only supported for structure's members or union's members."); + ": @" + Annotation.key_str + " and @" + Annotation.optional_str + " annotations are incompatible."); } if (member.isAnnotationId() && member.isAnnotationHashid()) { throw new ParseException(null, "Error in member " + member.getName() + ": @" + Annotation.id_str + " and @" + Annotation.hashid_str + " annotations cannot be together."); } + //}}} if(!m_members.containsKey(member.getName())) { @@ -236,7 +284,7 @@ else if (!isAnnotationAutoid() || getAnnotationAutoidValue().equals(Annotation.a } catch (RuntimeGenerationException ex) { - // Should be never called because was previously called isAnnotationId() or similar. + // Should never be called because isAnnotationId() or similar was previously called. } } @@ -360,6 +408,18 @@ public String getAnnotationAutoidValue() throws RuntimeGenerationException return ann.getValue(); } + public boolean isNonForwardedContent() + { + for (Member member : m_members.values()) + { + if (member.getTypecode().isForwarded()) + { + return false; + } + } + return true; + } + private String m_name = null; private String m_scope = null; diff --git a/src/main/java/com/eprosima/idl/parser/typecode/PrimitiveTypeCode.java b/src/main/java/com/eprosima/idl/parser/typecode/PrimitiveTypeCode.java index c1d1c92d..4e65c099 100644 --- a/src/main/java/com/eprosima/idl/parser/typecode/PrimitiveTypeCode.java +++ b/src/main/java/com/eprosima/idl/parser/typecode/PrimitiveTypeCode.java @@ -182,10 +182,94 @@ public boolean isIsType_13() return getKind() == Kind.KIND_LONGDOUBLE; } + @Override + public boolean isIsCharType() + { + return getKind() == Kind.KIND_CHAR; + } + @Override public boolean isIsWCharType() { return getKind() == Kind.KIND_WCHAR; } + @Override + public boolean isIsBooleanType() + { + return getKind() == Kind.KIND_BOOLEAN; + } + + @Override + public boolean isIsByteType() + { + return getKind() == Kind.KIND_OCTET; + } + + @Override + public boolean isIsInt8Type() + { + return getKind() == Kind.KIND_INT8; + } + + @Override + public boolean isIsUint8Type() + { + return getKind() == Kind.KIND_UINT8; + } + + @Override + public boolean isIsInt16Type() + { + return getKind() == Kind.KIND_SHORT; + } + + @Override + public boolean isIsUint16Type() + { + return getKind() == Kind.KIND_USHORT; + } + + @Override + public boolean isIsInt32Type() + { + return getKind() == Kind.KIND_LONG; + } + + @Override + public boolean isIsUint32Type() + { + return getKind() == Kind.KIND_ULONG; + } + + @Override + public boolean isIsInt64Type() + { + return getKind() == Kind.KIND_LONGLONG; + } + + @Override + public boolean isIsUint64Type() + { + return getKind() == Kind.KIND_ULONGLONG; + } + + @Override + public boolean isIsFloat32Type() + { + return getKind() == Kind.KIND_FLOAT; + } + + @Override + public boolean isIsFloat64Type() + { + return getKind() == Kind.KIND_DOUBLE; + } + + @Override + public boolean isIsFloat128Type() + { + return getKind() == Kind.KIND_LONGDOUBLE; + } + } diff --git a/src/main/java/com/eprosima/idl/parser/typecode/SequenceTypeCode.java b/src/main/java/com/eprosima/idl/parser/typecode/SequenceTypeCode.java index 2e45983f..c761383d 100644 --- a/src/main/java/com/eprosima/idl/parser/typecode/SequenceTypeCode.java +++ b/src/main/java/com/eprosima/idl/parser/typecode/SequenceTypeCode.java @@ -39,6 +39,10 @@ public boolean isIsType_e() @Override public String getTypeIdentifier() { + if (!isUnbound() && Integer.parseInt(evaluated_maxsize_) >= 256) + { + return "TI_PLAIN_SEQUENCE_LARGE"; + } return "TI_PLAIN_SEQUENCE_SMALL"; } @@ -113,12 +117,13 @@ public String getMaxsize() { if (m_maxsize == null) { - return "100"; + return default_unbounded_max_size; } return m_maxsize; } + @Override public String getEvaluatedMaxsize() { if (evaluated_maxsize_ == null) @@ -129,6 +134,10 @@ public String getEvaluatedMaxsize() return evaluated_maxsize_; } + /** + * This API is to check if this specific collection has a bound set. + * It does not check if the complete collection is bounded or not. + */ public boolean isUnbound() { return null == m_maxsize; @@ -140,6 +149,10 @@ public boolean isIsPlain() return false; } + /** + * This API is to check if ultimately the collection element is bounded. + * In order to check if this specific collection has bounds, please use isUnbound API. + */ @Override public boolean isIsBounded() { diff --git a/src/main/java/com/eprosima/idl/parser/typecode/SetTypeCode.java b/src/main/java/com/eprosima/idl/parser/typecode/SetTypeCode.java index 8fb32b78..58e4b6b6 100644 --- a/src/main/java/com/eprosima/idl/parser/typecode/SetTypeCode.java +++ b/src/main/java/com/eprosima/idl/parser/typecode/SetTypeCode.java @@ -92,7 +92,7 @@ public String getMaxsize() { if (m_maxsize == null) { - return "100"; + return default_unbounded_max_size; } return m_maxsize; diff --git a/src/main/java/com/eprosima/idl/parser/typecode/StringTypeCode.java b/src/main/java/com/eprosima/idl/parser/typecode/StringTypeCode.java index 7f1366be..2f17f3fe 100644 --- a/src/main/java/com/eprosima/idl/parser/typecode/StringTypeCode.java +++ b/src/main/java/com/eprosima/idl/parser/typecode/StringTypeCode.java @@ -42,9 +42,23 @@ public String getTypeIdentifier() switch (getKind()) { case Kind.KIND_STRING: - return "TI_STRING8_SMALL"; + if (isIsBounded() && Integer.parseInt(evaluated_maxsize_) >= 256) + { + return "TI_STRING8_LARGE"; + } + else + { + return "TI_STRING8_SMALL"; + } case Kind.KIND_WSTRING: - return "TI_STRING16_SMALL"; + if (isIsBounded() && Integer.parseInt(evaluated_maxsize_) >= 256) + { + return "TI_STRING16_LARGE"; + } + else + { + return "TI_STRING16_SMALL"; + } default: return "TK_None"; } @@ -96,6 +110,7 @@ public String getIdlTypename() return getIdlTypenameFromStringTemplate().toString(); } + @Override public String getMaxsize() { if (m_maxsize == null) @@ -106,6 +121,7 @@ public String getMaxsize() return m_maxsize; } + @Override public String getEvaluatedMaxsize() { if (evaluated_maxsize_ == null) diff --git a/src/main/java/com/eprosima/idl/parser/typecode/StructTypeCode.java b/src/main/java/com/eprosima/idl/parser/typecode/StructTypeCode.java index c7520f1c..89642bf0 100644 --- a/src/main/java/com/eprosima/idl/parser/typecode/StructTypeCode.java +++ b/src/main/java/com/eprosima/idl/parser/typecode/StructTypeCode.java @@ -22,6 +22,7 @@ import com.eprosima.idl.context.Context; import com.eprosima.idl.parser.exception.ParseException; +import com.eprosima.idl.parser.exception.RuntimeGenerationException; import com.eprosima.idl.parser.tree.Annotation; import com.eprosima.idl.parser.tree.Inherits; @@ -92,7 +93,6 @@ public void addInheritance( TypeCode parent) throws ParseException { String name = parent.getClass().getSimpleName(); - System.out.println("type = " + name); if (super_type_ == null && parent instanceof StructTypeCode) { @@ -163,6 +163,17 @@ public List getMembers( return allMembers; } + public Member getFirstMember() throws RuntimeGenerationException + { + List members = getMembers(); + if (members.size() == 0) + { + throw new RuntimeGenerationException("Error in structure " + super.getName() + + ": trying accesing first member of an empty structure"); + } + return members.get(0); + } + public List getAllMembers() // Alias for getMembers(true) for stg { return getMembers(true); @@ -238,6 +249,17 @@ public boolean addMember( return super.addMember(member); } + @Override + public boolean isNonForwardedContent() + { + boolean ret_code = true; + if (enclosed_super_type_ != null) + { + ret_code &= enclosed_super_type_.isNonForwardedContent(); + } + return ret_code &= super.isNonForwardedContent(); + } + @Override protected boolean check_unique_member_id( Member member) diff --git a/src/main/java/com/eprosima/idl/parser/typecode/TypeCode.java b/src/main/java/com/eprosima/idl/parser/typecode/TypeCode.java index 6707c208..55d5c0b8 100644 --- a/src/main/java/com/eprosima/idl/parser/typecode/TypeCode.java +++ b/src/main/java/com/eprosima/idl/parser/typecode/TypeCode.java @@ -14,16 +14,16 @@ package com.eprosima.idl.parser.typecode; -import com.eprosima.idl.parser.tree.Annotation; -import com.eprosima.idl.parser.tree.Notebook; -import com.eprosima.idl.context.Context; - -import java.util.Map; -import java.util.HashMap; import java.util.Collection; +import java.util.HashMap; +import java.util.Map; import org.stringtemplate.v4.ST; import org.stringtemplate.v4.STGroup; +import com.eprosima.idl.context.Context; +import com.eprosima.idl.parser.exception.RuntimeGenerationException; +import com.eprosima.idl.parser.tree.Annotation; +import com.eprosima.idl.parser.tree.Notebook; public abstract class TypeCode implements Notebook @@ -130,7 +130,7 @@ public String getFormatedCppTypename() } /*! - * @brief + * @brief Return the `getCppTypename()` without the scope. */ public String getNoScopedCppTypename() { @@ -161,6 +161,11 @@ public String getMaxsize() return null; } + public String getEvaluatedMaxsize() throws RuntimeGenerationException + { + throw new RuntimeGenerationException("Non-collection types does not have an evaluated max size"); + } + /*! * @brief This function returns the size of the datatype. By default is null string. * @return The size of the datatype. @@ -222,6 +227,76 @@ public boolean isIsType_13() return false; } + public boolean isIsBooleanType() + { + return false; + } + + public boolean isIsByteType() + { + return false; + } + + public boolean isIsInt8Type() + { + return false; + } + + public boolean isIsUint8Type() + { + return false; + } + + public boolean isIsInt16Type() + { + return false; + } + + public boolean isIsUint16Type() + { + return false; + } + + public boolean isIsInt32Type() + { + return false; + } + + public boolean isIsUint32Type() + { + return false; + } + + public boolean isIsInt64Type() + { + return false; + } + + public boolean isIsUint64Type() + { + return false; + } + + public boolean isIsFloat32Type() + { + return false; + } + + public boolean isIsFloat64Type() + { + return false; + } + + public boolean isIsFloat128Type() + { + return false; + } + + public boolean isIsEnumType() + { + return false; + } + public boolean isIsBitmaskType() { return false; @@ -242,12 +317,12 @@ public boolean isIsWStringType() return false; } - public boolean isIsWCharType() + public boolean isIsCharType() { return false; } - public boolean isIsEnumType() + public boolean isIsWCharType() { return false; } @@ -365,35 +440,42 @@ void calculate_extensibility( { if (ExtensibilityKind.NOT_APPLIED == extensibility_) { - if (m_annotations.containsKey(Annotation.final_str) || - (m_annotations.containsKey(Annotation.extensibility_str) && - m_annotations.get(Annotation.extensibility_str).getValue().equals(Annotation.ex_final_val))) + try { - extensibility_ = ExtensibilityKind.FINAL; - } - else if (m_annotations.containsKey(Annotation.appendable_str) || - (m_annotations.containsKey(Annotation.extensibility_str) && - m_annotations.get(Annotation.extensibility_str).getValue().equals(Annotation.ex_appendable_val))) - { - extensibility_ = ExtensibilityKind.APPENDABLE; - } - else if (m_annotations.containsKey(Annotation.mutable_str) || - (m_annotations.containsKey(Annotation.extensibility_str) && - m_annotations.get(Annotation.extensibility_str).getValue().equals(Annotation.ex_mutable_val))) - { - extensibility_ = ExtensibilityKind.MUTABLE; - } - else - { - if (ExtensibilityKind.NOT_APPLIED != base_ext) + if (m_annotations.containsKey(Annotation.final_str) || + (m_annotations.containsKey(Annotation.extensibility_str) && + m_annotations.get(Annotation.extensibility_str).getValue().equals(Annotation.ex_final_val))) + { + extensibility_ = ExtensibilityKind.FINAL; + } + else if (m_annotations.containsKey(Annotation.appendable_str) || + (m_annotations.containsKey(Annotation.extensibility_str) && + m_annotations.get(Annotation.extensibility_str).getValue().equals(Annotation.ex_appendable_val))) + { + extensibility_ = ExtensibilityKind.APPENDABLE; + } + else if (m_annotations.containsKey(Annotation.mutable_str) || + (m_annotations.containsKey(Annotation.extensibility_str) && + m_annotations.get(Annotation.extensibility_str).getValue().equals(Annotation.ex_mutable_val))) { - extensibility_ = base_ext; + extensibility_ = ExtensibilityKind.MUTABLE; } else { - extensibility_ = default_extensibility; + if (ExtensibilityKind.NOT_APPLIED != base_ext) + { + extensibility_ = base_ext; + } + else + { + extensibility_ = default_extensibility; + } } } + catch (RuntimeGenerationException ex) + { + // Should not be called as @extensibility annotation has only one parameter + } } } @@ -427,12 +509,49 @@ public boolean isAnnotationMutable() return ExtensibilityKind.MUTABLE == extensibility_; } + public boolean isAnnotationExtensibilityNotApplied() + { + if (!m_annotations.containsKey(Annotation.final_str) && + !m_annotations.containsKey(Annotation.appendable_str) && + !m_annotations.containsKey(Annotation.mutable_str) && + !m_annotations.containsKey(Annotation.extensibility_str)) + { + return true; + } + return false; + } + public boolean isAnnotationNested() { - Annotation ann = m_annotations.get("nested"); + Annotation ann = m_annotations.get(Annotation.nested_str); if (ann != null) { - return ann.getValue().toUpperCase().equals("TRUE"); + try + { + return ann.getValue().toUpperCase().equals(Annotation.capitalized_true_str); + } + catch (RuntimeGenerationException ex) + { + // Should not be called as @nested annotation has only one parameter + } + } + return false; + } + + public boolean isAnnotationAutoidHash() + { + Annotation ann = m_annotations.get(Annotation.autoid_str); + if (ann != null) + { + try + { + return (ann.getValue().toUpperCase().equals(Annotation.autoid_hash_value_str) || + ann.getValue().isEmpty()); + } + catch (RuntimeGenerationException ex) + { + // Should not be called as @autoid annotation has only one parameter + } } return false; } @@ -470,4 +589,5 @@ public void setDefined() private boolean m_defined = false; private ExtensibilityKind extensibility_ = ExtensibilityKind.NOT_APPLIED; + } diff --git a/src/main/java/com/eprosima/idl/parser/typecode/UnionMember.java b/src/main/java/com/eprosima/idl/parser/typecode/UnionMember.java index 5cbb2ecf..cd8cdeae 100644 --- a/src/main/java/com/eprosima/idl/parser/typecode/UnionMember.java +++ b/src/main/java/com/eprosima/idl/parser/typecode/UnionMember.java @@ -35,6 +35,11 @@ public List getLabels() return m_labels; } + public int getLabelsSize() + { + return m_labels.size(); + } + public void setLabels(List labels) { m_labels = labels; @@ -55,11 +60,6 @@ public boolean isDefault() return m_default; } - public boolean isPrintable() - { - return m_default || (null != m_labels && 0 < m_labels.size()); - } - private List m_internallabels = null; private List m_labels = null; private List m_javalabels = null; diff --git a/src/main/java/com/eprosima/idl/parser/typecode/UnionTypeCode.java b/src/main/java/com/eprosima/idl/parser/typecode/UnionTypeCode.java index cfbb4311..9a32cb03 100644 --- a/src/main/java/com/eprosima/idl/parser/typecode/UnionTypeCode.java +++ b/src/main/java/com/eprosima/idl/parser/typecode/UnionTypeCode.java @@ -34,7 +34,7 @@ public UnionTypeCode( String name) { super(Kind.KIND_UNION, scope, name); - m_discriminatorTypeCode = null; + discriminator_ = null; } public UnionTypeCode( @@ -43,7 +43,7 @@ public UnionTypeCode( TypeCode discriminatorTypeCode) { super(Kind.KIND_UNION, scope, name); - m_discriminatorTypeCode = discriminatorTypeCode; + discriminator_ = new UnionMember(discriminatorTypeCode, "discriminator", null, false); ++last_index_; ++last_id_; } @@ -51,7 +51,7 @@ public UnionTypeCode( public void setDiscriminatorType( TypeCode discriminatorTypeCode) throws RuntimeGenerationException { - m_discriminatorTypeCode = discriminatorTypeCode; + discriminator_ = new UnionMember(discriminatorTypeCode, "discriminator", null, false); ++last_index_; ++last_id_; if(last_id_ != 0) @@ -101,16 +101,17 @@ public int addMember( List labels = null; List javalabels = null; - if (Kind.KIND_ENUM == m_discriminatorTypeCode.getKind() || - Kind.KIND_BITMASK == m_discriminatorTypeCode.getKind()) + if (Kind.KIND_ENUM == discriminator_.getTypecode().getKind() || + Kind.KIND_BITMASK == discriminator_.getTypecode().getKind()) { - MemberedTypeCode enum_type = (MemberedTypeCode)m_discriminatorTypeCode; + MemberedTypeCode enum_type = (MemberedTypeCode)discriminator_.getTypecode(); labels = new ArrayList(); javalabels = new ArrayList(); for (int count = 0; count < internal_labels.size(); ++count) { - labels.add(enum_type.getScope() + "::" + internal_labels.get(count)); + labels.add((Kind.KIND_ENUM == discriminator_.getTypecode().getKind() ? + enum_type.getScopedname() + "::" : "")+ internal_labels.get(count)); javalabels.add(javapackage + enum_type.getJavaScopedname() + "." + internal_labels.get(count)); } } @@ -199,9 +200,9 @@ public String getJavaDefaultvalue() } // Used in stringtemplates - public TypeCode getDiscriminator() + public UnionMember getDiscriminator() { - return m_discriminatorTypeCode; + return discriminator_; } // Used in stringtemplates @@ -232,33 +233,6 @@ public boolean isIsPlain() return false; } - // Add member and the default one at the end. - public List getMembersDefaultAtEnd() - { - int position = 0; - List ret_members = new ArrayList(); - Member default_member = null; - - for (Member m : getMembers()) - { - if (position == m_defaultindex) - { - default_member = m; - } - else - { - ret_members.add(m); - } - } - - if (null != default_member) - { - ret_members.add(default_member); - } - - return ret_members; - } - @Override public void addAnnotation( Context ctx, @@ -270,7 +244,7 @@ public void addAnnotation( super.addAnnotation(ctx, annotation); } - private TypeCode m_discriminatorTypeCode = null; + private UnionMember discriminator_ = null; private int m_defaultindex = -1; diff --git a/src/main/java/com/eprosima/idl/test/TestIDLParser.java b/src/main/java/com/eprosima/idl/test/TestIDLParser.java index 99b63981..f7ce31d5 100644 --- a/src/main/java/com/eprosima/idl/test/TestIDLParser.java +++ b/src/main/java/com/eprosima/idl/test/TestIDLParser.java @@ -19,6 +19,7 @@ import com.eprosima.idl.context.Context; +import com.eprosima.idl.generator.manager.TemplateManager; import com.eprosima.idl.parser.grammar.IDLLexer; import com.eprosima.idl.parser.grammar.IDLParser; import com.eprosima.idl.parser.tree.Annotation; @@ -75,7 +76,8 @@ public void parse(String idlFileName) { return; } - Context context = new Context(idlFileName, m_includePaths); + TemplateManager tmanager = new TemplateManager(); + Context context = new Context(tmanager, idlFileName, m_includePaths, false); try { @@ -322,7 +324,7 @@ public void parseStruct(StructTypeCode struct) { } public void parseUnion(UnionTypeCode union) { - System.out.println("Start Union: " + union.getName() + " (" + union.getDiscriminator().getTypeIdentifier() + ")"); + System.out.println("Start Union: " + union.getName() + " (" + union.getDiscriminator().getTypecode().getTypeIdentifier() + ")"); for (Member member: union.getMembers()) { parseUnionMember((UnionMember)member); } diff --git a/src/main/java/com/eprosima/solution/Project.java b/src/main/java/com/eprosima/solution/Project.java index c7e90e4e..d3bf69b1 100644 --- a/src/main/java/com/eprosima/solution/Project.java +++ b/src/main/java/com/eprosima/solution/Project.java @@ -30,6 +30,7 @@ public Project(String name, String file, LinkedHashSet dependencies) m_commonsrcfiles = new ArrayList(); m_commonincludefiles = new ArrayList(); m_commontestingfiles = new ArrayList(); + m_typeobjecttestingfiles = new ArrayList(); } public void setParent(Solution sol) @@ -82,6 +83,16 @@ public ArrayList getCommonTestingFiles() return m_commontestingfiles; } + public void addTypeObjectTestingFile(String file) + { + m_typeobjecttestingfiles.add(file); + } + + public ArrayList getTypeObjectTestingFiles() + { + return m_typeobjecttestingfiles; + } + /*! * @brief Used in string templates. */ @@ -135,6 +146,7 @@ public ArrayList getFullDependencies() private ArrayList m_commonsrcfiles = null; private ArrayList m_commonincludefiles = null; private ArrayList m_commontestingfiles = null; + private ArrayList m_typeobjecttestingfiles = null; private LinkedHashSet m_dependencies = null; String m_guid = null; Solution m_parent = null; diff --git a/src/main/java/com/eprosima/solution/Solution.java b/src/main/java/com/eprosima/solution/Solution.java index ff3d2757..dce12d1f 100644 --- a/src/main/java/com/eprosima/solution/Solution.java +++ b/src/main/java/com/eprosima/solution/Solution.java @@ -14,6 +14,7 @@ package com.eprosima.solution; +import com.eprosima.idl.parser.exception.RuntimeGenerationException; import com.eprosima.log.ColorMessage; import java.util.ArrayList; @@ -105,6 +106,19 @@ public ArrayList getProjects() return m_cacheprojects; } + /*! + * @brief Only valid if one IDL is passed to Fast DDS-Gen. Used only in testing environment. + */ + public Project getMainProject() throws RuntimeGenerationException + { + ArrayList projects = getProjects(); + if (projects.isEmpty()) + { + throw new RuntimeGenerationException("Error: no projects have been defined"); + } + return (Project)projects.get(projects.size() - 1); + } + public boolean existsProject(String name) { boolean ret = false;