Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XTypes v1.3 refactor #130

Merged
merged 17 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/it/java/com/eprosima/integration/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
9 changes: 2 additions & 7 deletions src/it/java/com/eprosima/integration/TestManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@ public int getValue()
private String exampleArch;
private List<String> cMakeArgs;
private boolean errorOutputOnly;
private String cdr_version_;

public TestManager(
TestLevel level,
String generatorName,
String inputPath,
String outputPath,
String cdr_version,
List<String> list_tests,
List<String> blacklist_tests)
{
Expand All @@ -59,7 +57,6 @@ public TestManager(
this.exampleArch = null;
this.cMakeArgs = new ArrayList<String>();
this.errorOutputOnly = true;
this.cdr_version_ = cdr_version;
}

public TestManager(
Expand All @@ -68,7 +65,6 @@ public TestManager(
String inputPath,
String outputPath,
String exampleArch,
String cdr_version,
List<String> list_tests,
List<String> blacklist_tests)
{
Expand All @@ -81,7 +77,6 @@ public TestManager(
this.exampleArch = exampleArch;
this.cMakeArgs = new ArrayList<String>();
this.errorOutputOnly = true;
this.cdr_version_ = cdr_version;
}

public void processIDLsDirectory(
Expand Down Expand Up @@ -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));
}
}

Expand Down
52 changes: 26 additions & 26 deletions src/main/antlr/com/eprosima/idl/parser/grammar/IDL.g4
Original file line number Diff line number Diff line change
Expand Up @@ -177,27 +177,11 @@ module returns [Pair<com.eprosima.idl.parser.tree.Module, TemplateGroup> 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
Expand Down Expand Up @@ -1172,8 +1156,10 @@ annotation_def returns [Pair<AnnotationDeclaration, TemplateGroup> 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)
{
Expand All @@ -1188,9 +1174,24 @@ annotation_def returns [Pair<AnnotationDeclaration, TemplateGroup> returnPair =
}
}

$returnPair = new Pair<AnnotationDeclaration, TemplateGroup>($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<AnnotationDeclaration, TemplateGroup>($annotation_header.annotation, annotationTemplates);
}
;

annotation_header returns [AnnotationDeclaration annotation = null]
Expand Down Expand Up @@ -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");
}
}
}
Expand Down Expand Up @@ -1772,7 +1773,7 @@ union_type [Vector<Annotation> annotations, ArrayList<Definition> 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())
{
Expand Down Expand Up @@ -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
)+
Expand Down Expand Up @@ -2229,7 +2230,6 @@ array_declarator returns [Pair<Pair<Pair<String, Token>, ContainerTypeCode>, Tem
{
arrayTemplates.setAttribute("array", typecode);
arrayTemplates.setAttribute("ctx", ctx);
arrayTemplates.setAttribute("array_type",tk.getText());
}
Pair<String, Token> p = new Pair<String, Token>(tk.getText(), tk);
Pair<Pair<String, Token>, ContainerTypeCode> pp = new Pair<Pair<String, Token>, ContainerTypeCode>(p, typecode);
Expand Down Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)+
Expand Down
Loading