-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix 'Malformed class name' errors in typeName and related implementat…
…ions (#3533) - Provide a public simpleClassName utility to generate simple class names in a non-error prone way, particularly when generating inner class names. All typeNames are modified to now use this utility. - Mixing HasAutoTypename into anonymous bundles is now prohibited by the compiler, as this inevitably leads to name conflicts.
- Loading branch information
1 parent
556b2ca
commit 4186303
Showing
8 changed files
with
67 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package chisel3.util | ||
|
||
/* Generates a safe 'simple class name' from the given class, avoiding `Malformed class name` exceptions from `getClass.getSimpleName` | ||
* when Java 8 is used. | ||
*/ | ||
object simpleClassName { | ||
|
||
def apply[T](clazz: Class[T]): String = { | ||
/* The default class name is derived from the Java reflection derived class name. */ | ||
val baseName = clazz.getName | ||
|
||
/* A sequence of string filters applied to the name */ | ||
val filters: Seq[String => String] = | ||
Seq(((a: String) => raw"\$$+anon".r.replaceAllIn(a, "_Anon")) // Merge the "$$anon" name with previous name | ||
) | ||
|
||
filters | ||
.foldLeft(baseName) { case (str, filter) => filter(str) } // 1. Apply filters to baseName | ||
.split("\\.|\\$") // 2. Split string at '.' or '$' | ||
.filterNot(_.forall(_.isDigit)) // 3. Drop purely numeric names | ||
.last // 4. Use the last name | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters