Skip to content

Commit

Permalink
#18 Added CexReader
Browse files Browse the repository at this point in the history
  • Loading branch information
arminzavada committed Nov 7, 2024
1 parent e0aeaf5 commit 5f7419b
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ generate cex "http://www.bme.hu/mit/2024/cex"
import "http://www.eclipse.org/emf/2002/Ecore" as Ecore

Cex:
"(" "XstsStateSequence"
"(" ("XstsStateSequence" | "XstsCliTracegen")
(states += XstsState)*

(edges += StateEdge)*
")"
;

StateEdge:
from=[XstsState] "->" to=[XstsState]
;

XstsState:
"(" "XstsState" (preInit?="pre_init")? (lastEnv?="last_env")? (lastInternal?="last_internal")?
"(" (name=ID ":")? "XstsState" (preInit?="pre_init")? (lastEnv?="last_env")? (lastInternal?="last_internal")?
state = State
")"
;
Expand Down
1 change: 1 addition & 0 deletions subprojects/semantifyr/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ artifacts {

dependencies {
implementation(project(":oxsts.lang"))
implementation(project(":cex.lang"))

implementation(libs.guice)
implementation(libs.slf4j.api)
Expand Down
77 changes: 77 additions & 0 deletions subprojects/semantifyr/src/main/kotlin/theta/CexReader.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package hu.bme.mit.semantifyr.oxsts.semantifyr.theta

import hu.bme.mit.semantifyr.cex.lang.CexStandaloneSetup
import hu.bme.mit.semantifyr.cex.lang.cex.Cex
import hu.bme.mit.semantifyr.oxsts.semantifyr.utils.error
import hu.bme.mit.semantifyr.oxsts.semantifyr.utils.info
import hu.bme.mit.semantifyr.oxsts.semantifyr.utils.loggerFactory
import hu.bme.mit.semantifyr.oxsts.semantifyr.utils.warn
import org.eclipse.emf.common.util.URI
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
import org.eclipse.xtext.diagnostics.Severity
import org.eclipse.xtext.resource.XtextResource
import org.eclipse.xtext.util.CancelIndicator
import org.eclipse.xtext.validation.CheckMode
import java.io.File

fun prepareCex() {
CexStandaloneSetup.doSetup()
}

class CexReader {
val logger by loggerFactory()

val resourceSet = ResourceSetImpl()

init {
resourceSet.loadOptions[XtextResource.OPTION_ENCODING] = "UTF-8"
}

fun validateResource(resource: Resource) {
if (resource.errors.any()) {
logger.error { "Errors found in file (${resource.uri.toFileString()})" }

for (error in resource.errors) {
logger.error(error.message)
}

error("Errors found in file (${resource.uri.toFileString()})}")
}
if (resource.warnings.any()) {
logger.warn { "Warnings found in file (${resource.uri.toFileString()})" }

for (warning in resource.warnings) {
logger.warn(warning.message)
}
}
val validator = (resource as XtextResource).resourceServiceProvider.resourceValidator
val issues = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl)
if (issues.any()) {
logger.info { "Issues found in file (${resource.uri.toFileString()})" }

for (issue in issues) {
when (issue.severity) {
Severity.INFO -> {
logger.info { "${issue.uriToProblem.toFileString()}[${issue.lineNumber}:${issue.column}] ${issue.message}" }
}
Severity.WARNING -> {
logger.warn { "${issue.uriToProblem.toFileString()}[${issue.lineNumber}:${issue.column}] ${issue.message}" }
}
Severity.ERROR -> {
logger.error { "${issue.uriToProblem.toFileString()}[${issue.lineNumber}:${issue.column}] ${issue.message}" }
}
else -> { }
}
}
}
}

fun readCexFile(file: File): Cex {
val resource = resourceSet.getResource(URI.createFileURI(file.path), true)
resource.load(emptyMap<Any, Any>())
validateResource(resource)

return resource.contents.single() as Cex
}
}

0 comments on commit 5f7419b

Please sign in to comment.