diff options
| author | Jim Lawson | 2019-03-18 12:17:33 -0700 |
|---|---|---|
| committer | GitHub | 2019-03-18 12:17:33 -0700 |
| commit | 2c449c5d6e23dcbb60e8c64cab6b6f4ba6ae313f (patch) | |
| tree | 3daffa8eb0f57faf31d3977700be38f5be31e59a /chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala | |
| parent | cfb2f08db9d9df121a82f138dd71297dbcea66cc (diff) | |
Split #974 into two PRs - scalastyle updates (#1037)
* Update style warnings now that subprojects are aggregated.
Use "scalastyle-test-config.xml" for scalastyle config in tests.
Enable "_" in method names and accept method names ending in "_=".
Re-sync scalastyle-test-config.xml with scalastyle-config.xml
* Remove bogus tests that crept in with git add
* Add missing import.
Diffstat (limited to 'chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala')
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala index fa23ddaa..65939ef7 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala @@ -16,7 +16,7 @@ import chisel3.SourceInfoDoc * of) other Data objects. */ sealed abstract class Aggregate extends Data { - private[chisel3] override def bind(target: Binding, parentDirection: SpecifiedDirection) { + private[chisel3] override def bind(target: Binding, parentDirection: SpecifiedDirection) { // scalastyle:ignore cyclomatic.complexity line.size.limit binding = target val resolvedDirection = SpecifiedDirection.fromParent(parentDirection, specifiedDirection) @@ -58,7 +58,7 @@ sealed abstract class Aggregate extends Data { } case _ => val childWithDirections = getElements zip getElements.map(_.direction) - throw Binding.MixedDirectionAggregateException(s"Aggregate '$this' can't have elements that are both directioned and undirectioned: $childWithDirections") + throw Binding.MixedDirectionAggregateException(s"Aggregate '$this' can't have elements that are both directioned and undirectioned: $childWithDirections") // scalastyle:ignore line.size.limit } } } @@ -111,17 +111,19 @@ trait VecFactory extends SourceInfoDoc { } /** Truncate an index to implement modulo-power-of-2 addressing. */ - private[core] def truncateIndex(idx: UInt, n: Int)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): UInt = { + private[core] def truncateIndex(idx: UInt, n: Int)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): UInt = { // scalastyle:ignore line.size.limit + // scalastyle:off if.brace val w = BigInt(n-1).bitLength if (n <= 1) 0.U else if (idx.width.known && idx.width.get <= w) idx else if (idx.width.known) idx(w-1,0) else (idx | 0.U(w.W))(w-1,0) + // scalastyle:on if.brace } } object Vec extends VecFactory - +// scalastyle:off line.size.limit /** A vector (array) of [[Data]] elements. Provides hardware versions of various * collection transformation functions found in software array implementations. * @@ -148,6 +150,7 @@ object Vec extends VecFactory * - when multiple conflicting assignments are performed on a Vec element, the last one takes effect (unlike Mem, where the result is undefined) * - Vecs, unlike classes in Scala's collection library, are propagated intact to FIRRTL as a vector type, which may make debugging easier */ +// scalastyle:on line.size.limit sealed class Vec[T <: Data] private[core] (gen: => T, val length: Int) extends Aggregate with VecLike[T] { override def toString: String = { @@ -195,7 +198,7 @@ sealed class Vec[T <: Data] private[core] (gen: => T, val length: Int) } // TODO: eliminate once assign(Seq) isn't ambiguous with assign(Data) since Vec extends Seq and Data - def <> (that: Vec[T])(implicit sourceInfo: SourceInfo, moduleCompileOptions: CompileOptions): Unit = this bulkConnect that.asInstanceOf[Data] + def <> (that: Vec[T])(implicit sourceInfo: SourceInfo, moduleCompileOptions: CompileOptions): Unit = this bulkConnect that.asInstanceOf[Data] // scalastyle:ignore line.size.limit /** Strong bulk connect, assigning elements in this Vec from elements in a Seq. * @@ -258,9 +261,11 @@ sealed class Vec[T <: Data] private[core] (gen: => T, val length: Int) * Results in "Vec(elt0, elt1, ...)" */ def toPrintable: Printable = { + // scalastyle:off if.brace val elts = if (length == 0) List.empty[Printable] else self flatMap (e => List(e.toPrintable, PString(", "))) dropRight 1 + // scalastyle:on if.brace PString("Vec(") + Printables(elts) + PString(")") } } @@ -332,7 +337,7 @@ object VecInit extends SourceInfoDoc { def tabulate[T <: Data](n: Int)(gen: (Int) => T): Vec[T] = macro VecTransform.tabulate /** @group SourceInfoTransformMacro */ - def do_tabulate[T <: Data](n: Int)(gen: (Int) => T)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Vec[T] = + def do_tabulate[T <: Data](n: Int)(gen: (Int) => T)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Vec[T] = // scalastyle:ignore line.size.limit apply((0 until n).map(i => gen(i))) } @@ -494,11 +499,13 @@ abstract class Record(private[chisel3] implicit val compileOptions: CompileOptio // Helper because Bundle elements are reversed before printing private[chisel3] def toPrintableHelper(elts: Seq[(String, Data)]): Printable = { + // scalastyle:off if.brace val xs = if (elts.isEmpty) List.empty[Printable] // special case because of dropRight below else elts flatMap { case (name, data) => List(PString(s"$name -> "), data.toPrintable, PString(", ")) } dropRight 1 // Remove trailing ", " + // scalastyle:on if.brace PString(s"$className(") + Printables(xs) + PString(")") } /** Default "pretty-print" implementation @@ -612,6 +619,7 @@ abstract class Bundle(implicit compileOptions: CompileOptions) extends Record { } } ListMap(nameMap.toSeq sortWith { case ((an, a), (bn, b)) => (a._id > b._id) || ((a eq b) && (an > bn)) }: _*) + // scalastyle:ignore method.length } /** @@ -638,7 +646,7 @@ abstract class Bundle(implicit compileOptions: CompileOptions) extends Record { private val _containingModule: Option[BaseModule] = Builder.currentModule private val _containingBundles: Seq[Bundle] = Builder.updateBundleStack(this) - override def cloneType : this.type = { + override def cloneType : this.type = { // scalastyle:ignore cyclomatic.complexity method.length // This attempts to infer constructor and arguments to clone this Bundle subtype without // requiring the user explicitly overriding cloneType. import scala.language.existentials @@ -718,7 +726,7 @@ abstract class Bundle(implicit compileOptions: CompileOptions) extends Record { Some(ctor.newInstance().asInstanceOf[this.type]) case (argType :: Nil, Some((_, outerInstance))) => if (outerInstance == null) { - Builder.deprecated(s"chisel3.1 autoclonetype failed, falling back to 3.0 behavior using null as the outer instance." + + Builder.deprecated(s"chisel3.1 autoclonetype failed, falling back to 3.0 behavior using null as the outer instance." + // scalastyle:ignore line.size.limit s" Autoclonetype failure reason: ${outerClassError.get}", Some(s"$clazz")) Some(ctor.newInstance(outerInstance).asInstanceOf[this.type]) @@ -745,7 +753,7 @@ abstract class Bundle(implicit compileOptions: CompileOptions) extends Record { // Get constructor parameters and accessible fields val classSymbol = classSymbolOption.getOrElse(autoClonetypeError(s"scala reflection failed." + " This is known to occur with inner classes on anonymous outer classes." + - " In those cases, autoclonetype only works with no-argument constructors, or you can define a custom cloneType.")) + " In those cases, autoclonetype only works with no-argument constructors, or you can define a custom cloneType.")) // scalastyle:ignore line.size.limit val decls = classSymbol.typeSignature.decls val ctors = decls.collect { case meth: MethodSymbol if meth.isConstructor => meth } @@ -795,8 +803,10 @@ abstract class Bundle(implicit compileOptions: CompileOptions) extends Record { val accessorsName = accessors.filter(_.isStable).map(_.name.toString) val paramsDiff = ctorParamsNames.toSet -- accessorsName.toSet if (!paramsDiff.isEmpty) { + // scalastyle:off line.size.limit autoClonetypeError(s"constructor has parameters (${paramsDiff.toList.sorted.mkString(", ")}) that are not both immutable and accessible." + " Either make all parameters immutable and accessible (vals) so cloneType can be inferred, or define a custom cloneType method.") + // scalastyle:on line.size.limit } // Get all the argument values @@ -813,8 +823,10 @@ abstract class Bundle(implicit compileOptions: CompileOptions) extends Record { case (paramName, paramVal: Data) if paramVal.topBindingOpt.isDefined => paramName } if (boundDataParamNames.nonEmpty) { + // scalastyle:off line.size.limit autoClonetypeError(s"constructor parameters (${boundDataParamNames.sorted.mkString(", ")}) have values that are hardware types, which is likely to cause subtle errors." + " Use chisel types instead: use the value before it is turned to a hardware type (with Wire(...), Reg(...), etc) or use chiselTypeOf(...) to extract the chisel type.") + // scalastyle:on line.size.limit } // Clone unbound parameters in case they are being used as bundle fields. @@ -833,9 +845,11 @@ abstract class Bundle(implicit compileOptions: CompileOptions) extends Record { clone._outerInst = this._outerInst if (!clone.typeEquivalent(this)) { + // scalastyle:off line.size.limit autoClonetypeError(s"Automatically cloned $clone not type-equivalent to base $this." + " Constructor argument values were inferred: ensure that variable names are consistent and have the same value throughout the constructor chain," + " and that the constructor is deterministic.") + // scalastyle:on line.size.limit } clone @@ -848,4 +862,6 @@ abstract class Bundle(implicit compileOptions: CompileOptions) extends Record { * the fields in the order they were defined */ override def toPrintable: Printable = toPrintableHelper(elements.toList.reverse) + // scalastyle:off method.length } +// scalastyle:off file.size.limit |
