public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* [patch] Kawac ant task FileNameMapper name mangling
@ 2015-06-03  3:59 Jamison Hope
  2015-06-04  6:59 ` Per Bothner
  0 siblings, 1 reply; 2+ messages in thread
From: Jamison Hope @ 2015-06-03  3:59 UTC (permalink / raw)
  To: kawa@sourceware.org list

[-- Attachment #1: Type: text/plain, Size: 429 bytes --]

The attached patch fixes the expected class file name for source files
with hyphenated names by mangling "-" to "$Mn".

Previously, the simple glob mapped *.scm to *.class, which meant that
for string-cursors.scm it was looking for "string-cursors.class", not
finding it, and always concluding that it was out-of-date.  (Likewise
for case-lambda.scm and process-context.scm.)

--
Jamison Hope
The PTR Group
www.theptrgroup.com



[-- Attachment #2: gnu-kawa-ant-Kawac-name-mangling.patch --]
[-- Type: application/octet-stream, Size: 2475 bytes --]

Index: gnu/kawa/ant/ChangeLog
===================================================================
--- gnu/kawa/ant/ChangeLog	(revision 8487)
+++ gnu/kawa/ant/ChangeLog	(working copy)
@@ -1,3 +1,9 @@
+2015-06-02  Jamison Hope  <jrh@theptrgroup.com>
+
+	* Kawac.java (getMapper): Add file name mangling step to replace
+	"-" with "$Mn", so that Kawac looks for the right class files for
+	hyphenated source file names.
+
 2014-01-05  Per Bothner  <per@bothner.com>
 
 	* Makefile.am: Merge into ../../../gnu/Makefile.am and remove.
Index: gnu/kawa/ant/Kawac.java
===================================================================
--- gnu/kawa/ant/Kawac.java	(revision 8487)
+++ gnu/kawa/ant/Kawac.java	(working copy)
@@ -37,6 +37,7 @@
 import org.apache.tools.ant.types.selectors.SelectSelector;
 import org.apache.tools.ant.types.selectors.SizeSelector;
 import org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector;
+import org.apache.tools.ant.util.ChainedMapper;
 import org.apache.tools.ant.util.CompositeMapper;
 import org.apache.tools.ant.util.FileNameMapper;
 import org.apache.tools.ant.util.GlobPatternMapper;
@@ -755,6 +756,30 @@
     }
   }
 
+  private static class MangleFileNameMapper implements FileNameMapper {
+    // A simplified version of Language.mangleNameIfNeeded().
+    private String mangleNameIfNeeded(String name) {
+      if (name == null || !name.contains("-")) return name;
+      int len = name.length();
+      StringBuffer mangled = new StringBuffer(len);
+      for (int i  = 0; i < len; ++i) {
+        char ch = name.charAt(i);
+        if (ch == '-') mangled.append("$Mn");
+        else mangled.append(ch);
+      }
+      return mangled.toString();
+    }
+
+    public String[] mapFileName(String sourceFileName) {
+      String mangled = mangleNameIfNeeded(sourceFileName);
+      if (mangled == null) return null;
+      return new String[] { mangled };
+    }
+    public void setFrom(String from) {}
+    public void setTo(String to) {}
+    public static MangleFileNameMapper INSTANCE = new MangleFileNameMapper();
+  }
+
   /**
    * Compares the language property to each of the given strings, and
    * returns true if there is a match.
@@ -805,7 +830,10 @@
     GlobPatternMapper m = new GlobPatternMapper();
     m.setFrom("*" + ext);
     m.setTo("*.class");
-    return m;
+    ChainedMapper c = new ChainedMapper();
+    c.add(m);
+    c.add(MangleFileNameMapper.INSTANCE);
+    return c;
   }
 
   /**

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [patch] Kawac ant task FileNameMapper name mangling
  2015-06-03  3:59 [patch] Kawac ant task FileNameMapper name mangling Jamison Hope
@ 2015-06-04  6:59 ` Per Bothner
  0 siblings, 0 replies; 2+ messages in thread
From: Per Bothner @ 2015-06-04  6:59 UTC (permalink / raw)
  To: kawa

On 06/02/2015 08:59 PM, Jamison Hope wrote:
> The attached patch fixes the expected class file name for source files
> with hyphenated names by mangling "-" to "$Mn".

Thanks - I checked this in.

(One option I've considered is to *not* mangle class names, at least
ones that are valid JVM names - which includes ones with hyphens.
The disadvantage is you wouldn't be able to refer to these classes
from Java, except by using reflection.)
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-06-04  6:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-03  3:59 [patch] Kawac ant task FileNameMapper name mangling Jamison Hope
2015-06-04  6:59 ` Per Bothner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).