Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Small factorization in TemplateProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
vsonnier committed Feb 27, 2015
1 parent 67ce22a commit 2673ab3
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 111 deletions.
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Stable version is published on Maven:
<dependency>
<groupId>com.github.vsonnier</groupId>
<artifactId>hppcrt</artifactId>
<version>0.6.7</version>
<version>0.6.8</version>
</dependency>
````

Expand Down
4 changes: 2 additions & 2 deletions hppcrt-benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<parent>
<groupId>com.github.vsonnier</groupId>
<artifactId>hppcrt-parent</artifactId>
<version>0.6.8-SNAPSHOT</version>
<version>0.6.8</version>
<relativePath>../pom.xml</relativePath>
</parent>

<!-- Project info. -->
<groupId>com.github.vsonnier</groupId>
<artifactId>hppcrt-benchmarks</artifactId>
<version>0.6.8-SNAPSHOT</version>
<version>0.6.8</version>
<packaging>jar</packaging>

<name>HPPC-RT Benchmarks</name>
Expand Down
4 changes: 2 additions & 2 deletions hppcrt-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<parent>
<groupId>com.github.vsonnier</groupId>
<artifactId>hppcrt-parent</artifactId>
<version>0.6.8-SNAPSHOT</version>
<version>0.6.8</version>
<relativePath>../pom.xml</relativePath>
</parent>

<!-- Project info. -->
<groupId>com.github.vsonnier</groupId>
<artifactId>hppcrt</artifactId>
<version>0.6.8-SNAPSHOT</version>
<version>0.6.8</version>
<packaging>jar</packaging>

<name>HPPC-RT Collections</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
* and will indeed be replaced by a (VType) instantiation
* of KTypeArrays.
*/
/*! ${TemplateOptions.doNotGenerateKType("all")} !*/
/*! ${TemplateOptions.doNotGenerateVType("all")} !*/
/*! ${TemplateOptions.doNotGenerate()} !*/
/*! ${TemplateOptions.generatedAnnotation} !*/
public final class VTypeArrays
{
Expand Down
4 changes: 2 additions & 2 deletions hppcrt-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<parent>
<groupId>com.github.vsonnier</groupId>
<artifactId>hppcrt-parent</artifactId>
<version>0.6.8-SNAPSHOT</version>
<version>0.6.8</version>
<relativePath>../pom.xml</relativePath>
</parent>

<!-- Project info. -->
<groupId>com.github.vsonnier</groupId>
<artifactId>hppcrt-examples</artifactId>
<version>0.6.8-SNAPSHOT</version>
<version>0.6.8</version>
<packaging>jar</packaging>

<name>HPPC-RT Examples</name>
Expand Down
4 changes: 2 additions & 2 deletions hppcrt-templateprocessor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<parent>
<groupId>com.github.vsonnier</groupId>
<artifactId>hppcrt-parent</artifactId>
<version>0.6.8-SNAPSHOT</version>
<version>0.6.8</version>
<relativePath>../pom.xml</relativePath>
</parent>

<!-- Project info. -->
<groupId>com.github.vsonnier</groupId>
<artifactId>hppcrt-templateprocessor</artifactId>
<version>0.6.8-SNAPSHOT</version>
<version>0.6.8</version>
<packaging>jar</packaging>

<name>HPPC-RT Template Processor</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,92 +253,46 @@ public boolean inlineVTypeGenericAndPrimitive(final String callName, final Strin
}

public boolean inlineKTypeWithFullSpecialization(
final String callName, String args,

final String callName, final String args,
final String genericCallBody,
final String integerCallBody,
final String longCallBody,
final String floatCallBody,
final String doubleCallBody,
final String booleanCallBody) {

//Rebuild the arguments with a pattern understandable by the matcher
args = args.replace("(", "").trim();
args = args.replace(")", "").trim();

//Pick the ones matching TemplateOptions current Type(s) :
String body = "";

if (this.ktype == Type.GENERIC) {
body = genericCallBody;

}
else if (this.ktype == Type.BYTE) {
body = integerCallBody;

}
else if (this.ktype == Type.CHAR) {
body = integerCallBody;

}
else if (this.ktype == Type.SHORT) {
body = integerCallBody;

}
else if (this.ktype == Type.INT) {
body = integerCallBody;

}
else if (this.ktype == Type.LONG) {
body = longCallBody;

}
else if (this.ktype == Type.FLOAT) {
body = floatCallBody;

}
else if (this.ktype == Type.DOUBLE) {
body = doubleCallBody;

}
else if (this.ktype == Type.BOOLEAN) {
body = booleanCallBody;
}

//Update Pattern cache
if (!this.inlineKTypeDefinitions.containsKey(callName)) {
this.inlineKTypeDefinitions.put(callName, new InlinedMethodDef(callName));
}

//the method has no arguments
if (args.isEmpty()) {

this.inlineKTypeDefinitions.get(callName).setBody(body);

if (this.verbose) {

System.out.println("TemplateOptions : " + toString() + " captured the inlined KType function def '" +
callName + "' with no argument : " +
this.inlineKTypeDefinitions.get(callName));
}
}
else {

final String[] argsArray = args.split(",");

this.inlineKTypeDefinitions.get(callName).setBody(TemplateOptions.reformatArguments(body, argsArray));

if (this.verbose) {
return internalInlineWithFullSpecialization(this.ktype, this.inlineKTypeDefinitions,
callName, args,
genericCallBody,
integerCallBody,
longCallBody,
floatCallBody,
doubleCallBody,
booleanCallBody);
}

System.out.println("TemplateOptions : " + toString() + " captured the inlined KType function def '" +
callName + "' with multiple arguments : " +
this.inlineKTypeDefinitions.get(callName));
}
}
public boolean inlineVTypeWithFullSpecialization(
final String callName, final String args,
final String genericCallBody,
final String integerCallBody,
final String longCallBody,
final String floatCallBody,
final String doubleCallBody,
final String booleanCallBody) {

return false;
return internalInlineWithFullSpecialization(this.vtype, this.inlineVTypeDefinitions,
callName, args,
genericCallBody,
integerCallBody,
longCallBody,
floatCallBody,
doubleCallBody,
booleanCallBody);
}

public boolean inlineVTypeWithFullSpecialization(
private boolean internalInlineWithFullSpecialization(final Type t,
final HashMap<String, InlinedMethodDef> inlineDefs,
final String callName, String args,
final String genericCallBody,
final String integerCallBody,
Expand All @@ -354,71 +308,65 @@ public boolean inlineVTypeWithFullSpecialization(
//Pick the ones matching TemplateOptions current Type(s) :
String body = "";

if (this.vtype == Type.GENERIC) {
if (t == Type.GENERIC) {
body = genericCallBody;

}
else if (this.vtype == Type.BYTE) {
else if (t == Type.BYTE) {
body = integerCallBody;

}
else if (this.vtype == Type.CHAR) {
else if (t == Type.CHAR) {
body = integerCallBody;

}
else if (this.vtype == Type.SHORT) {
else if (t == Type.SHORT) {
body = integerCallBody;

}
else if (this.vtype == Type.INT) {
else if (t == Type.INT) {
body = integerCallBody;

}
else if (this.vtype == Type.LONG) {
else if (t == Type.LONG) {
body = longCallBody;

}
else if (this.vtype == Type.FLOAT) {
else if (t == Type.FLOAT) {
body = floatCallBody;

}
else if (this.vtype == Type.DOUBLE) {
else if (t == Type.DOUBLE) {
body = doubleCallBody;

}
else if (this.vtype == Type.BOOLEAN) {
else if (t == Type.BOOLEAN) {
body = booleanCallBody;
}

//Update Pattern cache
if (!this.inlineVTypeDefinitions.containsKey(callName)) {
this.inlineVTypeDefinitions.put(callName, new InlinedMethodDef(callName));
if (!inlineDefs.containsKey(callName)) {
inlineDefs.put(callName, new InlinedMethodDef(callName));
}

//the method has no arguments
if (args.isEmpty()) {

this.inlineVTypeDefinitions.get(callName).setBody(body);
inlineDefs.get(callName).setBody(body);

if (this.verbose) {

System.out.println("TemplateOptions : " + toString() + " captured the inlined VType function def '" +
callName + "' with no argument : " +
this.inlineVTypeDefinitions.get(callName));
}
}
else {

final String[] argsArray = args.split(",");

this.inlineVTypeDefinitions.get(callName).setBody(TemplateOptions.reformatArguments(body, argsArray));
inlineDefs.get(callName).setBody(TemplateOptions.reformatArguments(body, argsArray));
}

if (this.verbose) {
if (this.verbose) {

System.out.println("TemplateOptions : " + toString() + " captured the inlined VType function def '" +
callName + "' with multiple arguments : " +
this.inlineVTypeDefinitions.get(callName));
}
System.out.println("TemplateOptions : " + toString() + " captured the inlined function name '" +
callName + "' of type '" + t + "' as '" +
inlineDefs.get(callName) + "'");
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<!-- Project info. -->
<groupId>com.github.vsonnier</groupId>
<artifactId>hppcrt-parent</artifactId>
<version>0.6.8-SNAPSHOT</version>
<version>0.6.8</version>
<packaging>pom</packaging>

<name>HPPC-RT (parent POM)</name>
Expand Down

0 comments on commit 2673ab3

Please sign in to comment.