Skip to content

Commit

Permalink
Add attrDebugNeeded() that checks if Identifier needs _debug
Browse files Browse the repository at this point in the history
  • Loading branch information
generalmimon committed Oct 15, 2023
1 parent e9ed1c2 commit b9bc788
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ class CppCompiler(
outSrc.puts(s"return ${nonOwningPointer(instName, attrType)};")

override def instanceCalculate(instName: Identifier, dataType: DataType, value: Ast.expr): Unit = {
if (config.readStoresPos)
if (attrDebugNeeded(instName))
attrDebugStart(instName, dataType, None, NoRepeat)
val valExpr = expression(value)
val isOwningInExpr = dataType match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,7 @@ class JavaCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)

override def attrDebugStart(attrId: Identifier, attrType: DataType, ios: Option[String], rep: RepeatSpec): Unit = {
ios.foreach { (io) =>
val name = attrId match {
case _: RawIdentifier | _: SpecialIdentifier => return
case _ => idToStr(attrId)
}
val name = idToStr(attrId)
rep match {
case NoRepeat =>
out.puts("_attrStart.put(\"" + name + "\", " + io + ".pos());")
Expand All @@ -322,10 +319,7 @@ class JavaCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
}

override def attrDebugEnd(attrId: Identifier, attrType: DataType, io: String, rep: RepeatSpec): Unit = {
val name = attrId match {
case _: RawIdentifier | _: SpecialIdentifier => return
case _ => idToStr(attrId)
}
val name = idToStr(attrId)
rep match {
case NoRepeat =>
out.puts("_attrEnd.put(\"" + name + "\", " + io + ".pos());")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,6 @@ class JavaScriptCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
out.puts(s"$io.alignToByte();")

override def attrDebugStart(attrId: Identifier, attrType: DataType, io: Option[String], rep: RepeatSpec): Unit = {
if (!attrDebugNeeded(attrId))
return

val debugName = attrDebugName(attrId, rep, false)

val ioProps = io match {
Expand All @@ -279,8 +276,6 @@ class JavaScriptCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
}

override def attrDebugEnd(attrId: Identifier, attrType: DataType, io: String, rep: RepeatSpec): Unit = {
if (!attrDebugNeeded(attrId))
return
val debugName = attrDebugName(attrId, rep, true)

out.puts(s"$debugName.end = $io.pos;")
Expand Down Expand Up @@ -580,12 +575,6 @@ class JavaScriptCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
out.puts("}")
}

private
def attrDebugNeeded(attrId: Identifier) = attrId match {
case _: NamedIdentifier | _: NumberedIdentifier | _: InstanceIdentifier => true
case _: RawIdentifier | _: SpecialIdentifier => false
}

def attrDebugName(attrId: Identifier, rep: RepeatSpec, end: Boolean) = {
val arrIndexExpr = rep match {
case NoRepeat => ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,7 @@ class PythonCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)

override def attrDebugStart(attrId: Identifier, attrType: DataType, ios: Option[String], rep: RepeatSpec): Unit = {
ios.foreach { (io) =>
val name = attrId match {
case _: RawIdentifier | _: SpecialIdentifier => return
case _ => idToStr(attrId)
}
val name = idToStr(attrId)
rep match {
case NoRepeat =>
out.puts(s"self._debug['$name']['start'] = $io.pos()")
Expand All @@ -291,10 +288,7 @@ class PythonCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
}

override def attrDebugEnd(attrId: Identifier, attrType: DataType, io: String, rep: RepeatSpec): Unit = {
val name = attrId match {
case _: RawIdentifier | _: SpecialIdentifier => return
case _ => idToStr(attrId)
}
val name = idToStr(attrId)
rep match {
case NoRepeat =>
out.puts(s"self._debug['$name']['end'] = $io.pos()")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,7 @@ class RubyCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)

override def attrDebugStart(attrId: Identifier, attrType: DataType, ios: Option[String], rep: RepeatSpec): Unit = {
ios.foreach { (io) =>
val name = attrId match {
case _: RawIdentifier | _: SpecialIdentifier => return
case _ => idToStr(attrId)
}
val name = idToStr(attrId)
rep match {
case NoRepeat =>
out.puts(s"(@_debug['$name'] ||= {})[:start] = $io.pos")
Expand All @@ -259,10 +256,7 @@ class RubyCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
}

override def attrDebugEnd(attrId: Identifier, attrType: DataType, io: String, rep: RepeatSpec): Unit = {
val name = attrId match {
case _: RawIdentifier | _: SpecialIdentifier => return
case _ => idToStr(attrId)
}
val name = idToStr(attrId)
rep match {
case NoRepeat =>
out.puts(s"(@_debug['$name'] ||= {})[:end] = $io.pos")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ trait CommonReads extends LanguageCompiler {
normalIO
}

if (config.readStoresPos)
if (attrDebugNeeded(id))
attrDebugStart(id, attr.dataType, Some(io), NoRepeat)

defEndian match {
Expand Down Expand Up @@ -107,9 +107,11 @@ trait CommonReads extends LanguageCompiler {
}
}

def attrDebugStart(attrName: Identifier, attrType: DataType, io: Option[String], repeat: RepeatSpec): Unit = {}
def attrDebugStart(attrId: Identifier, attrType: DataType, io: Option[String], repeat: RepeatSpec): Unit = {}
def attrDebugEnd(attrName: Identifier, attrType: DataType, io: String, repeat: RepeatSpec): Unit = {}

def attrDebugNeeded(attrId: Identifier): Boolean = false

/**
* Runs all validation procedures requested for an attribute.
* @param attr attribute to run validations for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ trait EveryReadIsExpression
assignTypeOpt: Option[DataType] = None
): Unit = {
val assignType = assignTypeOpt.getOrElse(dataType)
val needsDebug = attrDebugNeeded(id) && rep != NoRepeat

if (config.readStoresPos && rep != NoRepeat)
if (needsDebug)
attrDebugStart(id, dataType, Some(io), rep)

dataType match {
Expand Down Expand Up @@ -61,7 +62,7 @@ trait EveryReadIsExpression
handleAssignment(id, expr, rep, isRaw)
}

if (config.readStoresPos && rep != NoRepeat)
if (needsDebug)
attrDebugEnd(id, dataType, io, rep)
}

Expand Down Expand Up @@ -250,8 +251,18 @@ trait EveryReadIsExpression
def userTypeDebugRead(id: String, dataType: DataType, assignType: DataType): Unit = ???

def instanceCalculate(instName: Identifier, dataType: DataType, value: Ast.expr): Unit = {
if (config.readStoresPos)
if (attrDebugNeeded(instName))
attrDebugStart(instName, dataType, None, NoRepeat)
handleAssignmentSimple(instName, expression(value))
}

override def attrDebugNeeded(attrId: Identifier): Boolean = {
if (!config.readStoresPos)
return false

attrId match {
case _: NamedIdentifier | _: NumberedIdentifier | _: InstanceIdentifier => true
case _ => super.attrDebugNeeded(attrId)
}
}
}

0 comments on commit b9bc788

Please sign in to comment.