Skip to content
Permalink
Browse files
Created macro-lib project/module, and converted Assert's usage,
invariant, and notYetImplemented methods into macros.
macro.

ECLIPSE SETUP CHANGE: you must add -language:experimental.macros option
to the scala compiler settings. This setting is not set in our git
repository eclipse-projects, but is a global setting for the entire
eclipse instance (or maybe workspace?).

Unit tests of macro-lib are in daffodil-lib-unittest

Converted logging system to use macros.

This eliminates all these Glob objects, and closure forming.

The way to log now is log(LogLevel.Debug, "something %s", args...)

DFDL-1425
  • Loading branch information
mbeckerle committed Oct 7, 2015
1 parent 2aa21f0 commit 222b35afc4bc018223bce716e329002ddca0e426
Showing 56 changed files with 658 additions and 486 deletions.
@@ -4,7 +4,7 @@ organization in ThisBuild := "edu.illinois.ncsa"

scalaVersion in ThisBuild := "2.11.7"

scalacOptions in ThisBuild ++= Seq("-unchecked", "-deprecation", "-Yinline-warnings", "-Xfatal-warnings", "-Xxml:-coalescing")
scalacOptions in ThisBuild ++= Seq("-unchecked", "-deprecation", "-Yinline-warnings", "-Xfatal-warnings", "-Xxml:-coalescing", "-language:experimental.macros")

// parallelExecution in ThisBuild := false

@@ -123,11 +123,11 @@ class CommandLineXMLLoaderErrorHandler() extends org.xml.sax.ErrorHandler with L
}

trait CLILogPrefix extends LogWriter {
override def prefix(logID: String, glob: Glob): String = {
"[" + glob.lvl.toString.toLowerCase + "] "
override def prefix(lvl: LogLevel.Type, logID: String): String = {
"[" + lvl.toString.toLowerCase + "] "
}

override def suffix(logID: String, glob: Glob): String = {
override def suffix(logID: String): String = {
""
}
}
@@ -153,7 +153,7 @@ object TDMLLogWriter extends CLILogPrefix {
}

class CLIConf(arguments: Array[String]) extends scallop.ScallopConf(arguments)
with Logging {
with Logging {

/**
* This is used when the flag is optional and so is its
@@ -653,7 +653,7 @@ object Main extends Logging {
// Wrap timing around the whole of compilation
//
// compilation extends from the call to compile
// to also include the call to pf.onPath. (which is the last phase
// to also include the call to pf.onPath. (which is the last phase
// of compilation, where it asks for the parser)
//
val schemaSource = URISchemaSource(schema)
@@ -749,7 +749,7 @@ object Main extends Logging {
} else false
}
case None => {
// we need to look at the internal state of the parser inStream to
// we need to look at the internal state of the parser inStream to
// see how big it is. We do this after execution so as
// not to traverse the data twice.
val ps = parseResult.resultState.asInstanceOf[PState]
@@ -940,7 +940,7 @@ object Main extends Logging {
}

val outChannel = java.nio.channels.Channels.newChannel(output)
//
//
// We are not loading a schema here, we're loading the infoset to unparse.
//
val source = unparseOpts.infile.get match {
@@ -2,25 +2,25 @@
*
* Developed by: Tresys Technology, LLC
* http://www.tresys.com
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal with
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimers.
*
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimers in the
* documentation and/or other materials provided with the distribution.
*
*
* 3. Neither the names of Tresys Technology, nor the names of its contributors
* may be used to endorse or promote products derived from this Software
* without specific prior written permission.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -46,10 +46,7 @@ import edu.illinois.ncsa.daffodil.dsom.SchemaSet
import edu.illinois.ncsa.daffodil.dsom.oolag.OOLAG
import edu.illinois.ncsa.daffodil.exceptions.Assert
import edu.illinois.ncsa.daffodil.processors.DataProcessor
import edu.illinois.ncsa.daffodil.util.Compile
import edu.illinois.ncsa.daffodil.util.Error
import edu.illinois.ncsa.daffodil.util.Warning
import edu.illinois.ncsa.daffodil.util.Info
import edu.illinois.ncsa.daffodil.util.LogLevel
import edu.illinois.ncsa.daffodil.util.Logging
import edu.illinois.ncsa.daffodil.xml._
import edu.illinois.ncsa.daffodil.api.DFDL
@@ -88,9 +85,9 @@ object ForUnparser extends ParserOrUnparser
object BothParserAndUnparser extends ParserOrUnparser

class ProcessorFactory(val sset: SchemaSet)
extends SchemaComponentBase(<pf/>, sset)
with DFDL.ProcessorFactory
with HavingRootSpec {
extends SchemaComponentBase(<pf/>, sset)
with DFDL.ProcessorFactory
with HavingRootSpec {

lazy val parser = LV('parser) {
val par = rootElem.document.parser
@@ -127,8 +124,8 @@ class ProcessorFactory(val sset: SchemaSet)
// no point in going forward with more
// checks if the schema isn't valid
// The code base is written assuming valid
// schema input. It's just going to hit
// assertion failures and such if we
// schema input. It's just going to hit
// assertion failures and such if we
// try to compile invalid schemas.
val requiredErr = super.isError
val ssetErr = sset.isError
@@ -162,12 +159,12 @@ class ProcessorFactory(val sset: SchemaSet)
if (dataProc.isError) {
// NO longer printing anything here. Callers must do this.
// val diags = dataProc.getDiagnostics
// log(Error("Compilation (DataProcessor) reports %s compile errors/warnings.", diags.length))
// diags.foreach { diag => log(Error(diag.toString())) }
// log(LogLevel.Error,"Compilation (DataProcessor) reports %s compile errors/warnings.", diags.length)
// diags.foreach { diag => log(LogLevel.Error, diag.toString()) }
} else {
log(Compile("Parser = %s.", ssrd.parser.toString))
//log(Error("Unparser = %s.", ssrd.unparser.toString))
log(Compile("Compilation (DataProcesor) completed with no errors."))
log(LogLevel.Compile, "Parser = %s.", ssrd.parser.toString)
//log(LogLevel.Error, "Unparser = %s.", ssrd.unparser.toString)
log(LogLevel.Compile, "Compilation (DataProcesor) completed with no errors.")
}
dataProc
}
@@ -196,9 +193,9 @@ trait HavingRootSpec extends Logging {
class InvalidParserException(msg: String, cause: Throwable = null) extends Exception(msg, cause)

class Compiler(var validateDFDLSchemas: Boolean = true)
extends DFDL.Compiler
with Logging
with HavingRootSpec {
extends DFDL.Compiler
with Logging
with HavingRootSpec {

def setValidateDFDLSchemas(value: Boolean) = validateDFDLSchemas = value

@@ -249,7 +246,7 @@ class Compiler(var validateDFDLSchemas: Boolean = true)
case "inputfilememorymaplowthreshold" => DaffodilTunableParameters.inputFileMemoryMapLowThreshold = java.lang.Long.valueOf(value)
case "initialelementoccurrenceshint" => DaffodilTunableParameters.initialElementOccurrencesHint = java.lang.Long.valueOf(value)
case "prettyprintelementlimit" => DaffodilTunableParameters.prettyPrintElementLimit = java.lang.Integer.valueOf(value)
case _ => log(Warning("Ignoring unknown tunable: %s", tunable))
case _ => log(LogLevel.Warning, "Ignoring unknown tunable: %s", tunable)
}
}

@@ -325,15 +322,15 @@ class Compiler(var validateDFDLSchemas: Boolean = true)
val diags = pf.getDiagnostics // might be warnings even if not isError
if (err) {
Assert.invariant(diags.length > 0)
log(Compile("Compilation (ProcessorFactory) produced %d errors/warnings.", diags.length))
log(LogLevel.Compile, "Compilation (ProcessorFactory) produced %d errors/warnings.", diags.length)
} else {
if (diags.length > 0) {
log(Compile("Compilation (ProcessorFactory) produced %d warnings.", diags.length))
log(LogLevel.Compile, "Compilation (ProcessorFactory) produced %d warnings.", diags.length)
} else {
log(Compile("ProcessorFactory completed with no errors."))
log(LogLevel.Compile, "ProcessorFactory completed with no errors.")
}
}
log(Compile("Schema had %s elements.", ElementBase.count))
log(LogLevel.Compile, "Schema had %s elements.", ElementBase.count)
pf
}

@@ -355,4 +352,3 @@ object Compiler {
def apply() = new Compiler()

}

@@ -2,25 +2,25 @@
*
* Developed by: Tresys Technology, LLC
* http://www.tresys.com
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal with
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimers.
*
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimers in the
* documentation and/or other materials provided with the distribution.
*
*
* 3. Neither the names of Tresys Technology, nor the names of its contributors
* may be used to endorse or promote products derived from this Software
* without specific prior written permission.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -45,7 +45,6 @@ import edu.illinois.ncsa.daffodil.exceptions.Assert
import edu.illinois.ncsa.daffodil.xml.NS
import edu.illinois.ncsa.daffodil.xml.NoNamespace
import edu.illinois.ncsa.daffodil.util._
import edu.illinois.ncsa.daffodil.util.Info
import IIUtils._
import java.io.File
import java.net.URI
@@ -151,7 +150,7 @@ object IIUtils {
* Include/Import = "II" for short
*/
abstract class IIBase(xml: Node, xsdArg: XMLSchemaDocument, val seenBefore: IIMap)
extends SchemaComponent(xml, xsdArg) {
extends SchemaComponent(xml, xsdArg) {

/**
* An import/include requires only that we can access the
@@ -225,7 +224,7 @@ abstract class IIBase(xml: Node, xsdArg: XMLSchemaDocument, val seenBefore: IIMa
""
}
}
//
//
// Note that Looking in the current working directory (CWD)
// would be a security risk/issue. So if a user wants the CWD
// they should add "." to their classpath to get it to be
@@ -2,25 +2,25 @@
*
* Developed by: Tresys Technology, LLC
* http://www.tresys.com
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal with
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimers.
*
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimers in the
* documentation and/or other materials provided with the distribution.
*
*
* 3. Neither the names of Tresys Technology, nor the names of its contributors
* may be used to endorse or promote products derived from this Software
* without specific prior written permission.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -46,7 +46,6 @@ import edu.illinois.ncsa.daffodil.xml._
import edu.illinois.ncsa.daffodil.api.DaffodilSchemaSource
import edu.illinois.ncsa.daffodil.api.URISchemaSource
import edu.illinois.ncsa.daffodil.util._
import edu.illinois.ncsa.daffodil.util.Info
import IIUtils._
import java.io.File
import java.net.URI
@@ -70,7 +69,7 @@ import java.net.URLEncoder
* is different from this imported schema's goalNamespace.
*/
final class Import(importNode: Node, xsd: XMLSchemaDocument, seenArg: IIMap)
extends IIBase(importNode, xsd, seenArg) {
extends IIBase(importNode, xsd, seenArg) {

final def mapPair = LV('mapPair) {
val mpOpt = importElementNS.map { ieNS => (ieNS, resolvedLocation) }
@@ -81,16 +80,16 @@ final class Import(importNode: Node, xsd: XMLSchemaDocument, seenArg: IIMap)
// is, and then we might decide to use it, or not use it.
//
// This means we need to unconditionally load the schemaDocument
// and not do checks nor use the incoming set of "seenBefore"
// schemas - as we need to open this schema file simply to see
// and not do checks nor use the incoming set of "seenBefore"
// schemas - as we need to open this schema file simply to see
// its namespace.

// FIXME: if you have an import like this:
// <import schemaLocation="..."/>
// <import schemaLocation="..."/>
// This code will read the file TWICE. Once just to peek at the
// namespace.
//
// This should be cached. i.e., cache the loaded schema file
// namespace.
//
// This should be cached. i.e., cache the loaded schema file
// object by way of a factory without the final map parameter
// (similarly, for DFDLSchemaDocument, the Import/Exports etc.)
//
@@ -151,7 +150,7 @@ final class Import(importNode: Node, xsd: XMLSchemaDocument, seenArg: IIMap)
case (None, _, Some(sl), None) => {
if (xsd.isBootStrapSD) {
//
// special case - one of the user-supplied files (that we wrap in a
// special case - one of the user-supplied files (that we wrap in a
// fake import statement and a fake surrounding document
// doesn't exist.
// We don't want the message to discuss those fake things.
@@ -2,25 +2,25 @@
*
* Developed by: Tresys Technology, LLC
* http://www.tresys.com
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal with
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimers.
*
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimers in the
* documentation and/or other materials provided with the distribution.
*
*
* 3. Neither the names of Tresys Technology, nor the names of its contributors
* may be used to endorse or promote products derived from this Software
* without specific prior written permission.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -45,7 +45,6 @@ import edu.illinois.ncsa.daffodil.exceptions.Assert
import edu.illinois.ncsa.daffodil.xml.NS
import edu.illinois.ncsa.daffodil.xml.NoNamespace
import edu.illinois.ncsa.daffodil.util._
import edu.illinois.ncsa.daffodil.util.Info
import IIUtils._
import java.io.File
import java.net.URI
@@ -67,7 +66,7 @@ import java.net.URLEncoder
* a targetNamespace.
*/
final class Include(xml: Node, xsd: XMLSchemaDocument, seenArg: IIMap)
extends IIBase(xml, xsd, seenArg) {
extends IIBase(xml, xsd, seenArg) {

protected final def mapPair = LV('mapPair) {
// for an include, the targetNamespace of the schema document that contained us is right.
@@ -87,12 +86,11 @@ final class Include(xml: Node, xsd: XMLSchemaDocument, seenArg: IIMap)
schemaDefinitionError("Unable to determine target namespace.")) {
xsd.targetNamespace
}
log(Debug("Included schema from %s into namespace %s.", rsl, ns))
log(LogLevel.Debug, "Included schema from %s into namespace %s.", rsl, ns)
rsl
}
case None => schemaDefinitionError("Included schema not found at location %s. %s", slText, whereSearched)
}
}.value

}

0 comments on commit 222b35a

Please sign in to comment.