Skip to content

Commit

Permalink
Merge pull request #103 from frwang96/feature-report-file
Browse files Browse the repository at this point in the history
Feature report file
  • Loading branch information
frwang96 authored Feb 25, 2022
2 parents a40d619 + b0c84f8 commit 0461c5a
Show file tree
Hide file tree
Showing 37 changed files with 582 additions and 112 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- Support `toString` function.
- Support for safe access operator.
- Support for enums with values.
- Rename `config.yaml` to `report.yaml`.

## [0.1.13]
### Importer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import io.verik.compiler.ast.common.Declaration
import io.verik.compiler.ast.element.common.ETypedElement
import io.verik.compiler.ast.element.declaration.kt.EKtClass
import io.verik.compiler.ast.property.AnnotationEntry
import io.verik.compiler.ast.property.PackageType

abstract class EDeclaration : ETypedElement(), Declaration {

Expand All @@ -37,4 +38,17 @@ abstract class EDeclaration : ETypedElement(), Declaration {
else -> false
}
}

fun getQualifiedName(): String? {
if (this is EFile) return null
return when (val parent = parent) {
is EFile -> {
val pkg = parent.getParentPackage()
if (pkg.packageType == PackageType.REGULAR_ROOT) name
else "${pkg.name}.$name"
}
is EDeclaration -> "${parent.getQualifiedName()}.$name"
else -> null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object EntryPointCheckerStage : ProjectStage() {
override fun visitDeclaration(declaration: EDeclaration) {
super.visitDeclaration(declaration)
if (declaration.hasAnnotationEntry(AnnotationEntries.ENTRY)) {
names.add(declaration.name)
declaration.getQualifiedName()?.let { names.add(it) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ object Core {

object Int {

val F_unaryPlus = CoreKtInt.F_unaryPlus
val F_unaryMinus = CoreKtInt.F_unaryMinus
val F_plus_Int = CoreKtInt.F_plus_Int
val F_minus_Int = CoreKtInt.F_minus_Int
val F_times_Int = CoreKtInt.F_times_Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,32 @@ package io.verik.compiler.core.declaration.kt

import io.verik.compiler.ast.element.expression.common.ECallExpression
import io.verik.compiler.ast.element.expression.common.EConstantExpression
import io.verik.compiler.ast.element.expression.common.EExpression
import io.verik.compiler.ast.property.SvBinaryOperatorKind
import io.verik.compiler.ast.property.SvUnaryOperatorKind
import io.verik.compiler.constant.IntConstantEvaluator
import io.verik.compiler.core.common.BinaryCoreFunctionDeclaration
import io.verik.compiler.core.common.Core
import io.verik.compiler.core.common.CoreScope
import io.verik.compiler.core.common.TransformableCoreFunctionDeclaration
import io.verik.compiler.core.common.UnaryCoreFunctionDeclaration

object CoreKtInt : CoreScope(Core.Kt.C_Int) {

val F_unaryPlus = object : TransformableCoreFunctionDeclaration(parent, "unaryPlus", "fun unaryPlus()") {

override fun transform(callExpression: ECallExpression): EExpression {
return callExpression.receiver!!
}
}

val F_unaryMinus = UnaryCoreFunctionDeclaration(
parent,
"unaryMinus",
"fun unaryMinus()",
SvUnaryOperatorKind.MINUS
)

val F_plus_Int = object : BinaryCoreFunctionDeclaration(
parent,
"plus",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ object PackageInjectedPropertyReducerStage : ProjectStage() {
}

private fun processPackage(pkg: EPackage) {
val file = pkg.files.find { it.name == "Pkg.kt" }
if (file != null) {
pkg.files.remove(file)
val injectedProperties = getInjectedProperties(file)
injectedProperties.forEach { it.parent = pkg }
pkg.injectedProperties = injectedProperties
}
pkg.files.find { it.name == "Pkg.kt" }?.let { processFile(it, pkg) }
pkg.files.find { it.name == "pkg.kt" }?.let { processFile(it, pkg) }
}

private fun processFile(file: EFile, pkg: EPackage) {
pkg.files.remove(file)
val injectedProperties = getInjectedProperties(file)
injectedProperties.forEach { it.parent = pkg }
pkg.injectedProperties = injectedProperties
}

private fun getInjectedProperties(file: EFile): ArrayList<EInjectedProperty> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,19 @@ import io.verik.compiler.common.TextFile

class OutputContext {

lateinit var configTextFile: TextFile
lateinit var reportTextFile: TextFile
var targetPackageTextFile: TextFile? = null
var nonRootPackageTextFiles: List<TextFile> = listOf()
var rootPackageTextFiles: List<TextFile> = listOf()
var packageWrapperTextFiles: List<TextFile> = listOf()
lateinit var projectWrapperTextFile: TextFile
lateinit var wrapperTextFile: TextFile

fun getTextFiles(): List<TextFile> {
val textFiles = ArrayList<TextFile>()
textFiles.add(configTextFile)
textFiles.add(reportTextFile)
targetPackageTextFile?.let { textFiles.add(it) }
textFiles.addAll(nonRootPackageTextFiles)
textFiles.addAll(rootPackageTextFiles)
textFiles.addAll(packageWrapperTextFiles)
textFiles.add(projectWrapperTextFile)
textFiles.add(wrapperTextFile)
return textFiles.sortedBy { it.path }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ProjectContext(
val config: VerikConfig
) {

val report = VerikReport()
var sourceSetContexts: List<SourceSetContext> = listOf()
val processedProjectStages = HashSet<ProjectStage>()
lateinit var kotlinCoreEnvironment: KotlinCoreEnvironment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ import io.verik.compiler.resolve.SliceResolverStage
import io.verik.compiler.resolve.TypeReferenceForwarderStage
import io.verik.compiler.resolve.TypeResolvedCheckerStage
import io.verik.compiler.resolve.TypeResolverStage
import io.verik.compiler.serialize.general.ConfigFileSerializerStage
import io.verik.compiler.serialize.general.DeclarationCounterStage
import io.verik.compiler.serialize.general.ReportFileSerializerStage
import io.verik.compiler.serialize.general.WrapperSerializerStage
import io.verik.compiler.serialize.source.SourceSerializerStage
import io.verik.compiler.serialize.target.CompositeTargetSerializerStage
Expand Down Expand Up @@ -229,7 +230,8 @@ object StageSequencer {
stageSequence.add(StageType.POST_CHECK, NameRedeclarationCheckerStage)
stageSequence.add(StageType.POST_CHECK, StatementCheckerStage)

stageSequence.add(StageType.SERIALIZE, ConfigFileSerializerStage)
stageSequence.add(StageType.SERIALIZE, DeclarationCounterStage)
stageSequence.add(StageType.SERIALIZE, ReportFileSerializerStage)
stageSequence.add(StageType.SERIALIZE, CompositeTargetSerializerStage)
stageSequence.add(StageType.SERIALIZE, SourceSerializerStage)
stageSequence.add(StageType.SERIALIZE, WrapperSerializerStage)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2022 Francis Wang
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.verik.compiler.main

class VerikReport {

var entryPoints: List<String> = listOf()
var counts: List<Pair<String, Int>> = listOf()
}
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,11 @@ object Messages {
)

val NOT_INJECTED_PROPERTY = ErrorMessageTemplate0(
"Only injected properties are permitted in Pkg.kt"
"Only injected properties are permitted here"
)

val INJECTED_PROPERTY_NOT_LITERAL = ErrorMessageTemplate0(
"Expressions are not permitted in injected properties declared in Pkg.kt"
"Expression not permitted in injected property"
)

// UPPER TRANSFORM ///////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/*
* Copyright (c) 2022 Francis Wang
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.verik.compiler.serialize.general

import io.verik.compiler.ast.element.declaration.common.EPackage
import io.verik.compiler.ast.element.declaration.common.EProperty
import io.verik.compiler.ast.element.declaration.sv.EAlwaysComBlock
import io.verik.compiler.ast.element.declaration.sv.EAlwaysSeqBlock
import io.verik.compiler.ast.element.declaration.sv.EComponentInstantiation
import io.verik.compiler.ast.element.declaration.sv.EConstraint
import io.verik.compiler.ast.element.declaration.sv.EEnum
import io.verik.compiler.ast.element.declaration.sv.EInitialBlock
import io.verik.compiler.ast.element.declaration.sv.EModule
import io.verik.compiler.ast.element.declaration.sv.EModuleInterface
import io.verik.compiler.ast.element.declaration.sv.EStruct
import io.verik.compiler.ast.element.declaration.sv.ESvClass
import io.verik.compiler.ast.element.declaration.sv.ESvConstructor
import io.verik.compiler.ast.element.declaration.sv.ESvFunction
import io.verik.compiler.ast.element.declaration.sv.ETask
import io.verik.compiler.common.TreeVisitor
import io.verik.compiler.main.ProjectContext
import io.verik.compiler.main.ProjectStage

object DeclarationCounterStage : ProjectStage() {

override fun process(projectContext: ProjectContext) {
val declarationCounterVisitor = DeclarationCounterVisitor()
projectContext.project.regularPackages().forEach {
it.accept(declarationCounterVisitor)
}

val counts = ArrayList<Pair<String, Int>>()
counts.add(Pair("packages", declarationCounterVisitor.packageCount))
counts.add(Pair("classes", declarationCounterVisitor.classCount))
counts.add(Pair("modules", declarationCounterVisitor.moduleCount))
counts.add(Pair("moduleInterfaces", declarationCounterVisitor.moduleInterfaceCount))
counts.add(Pair("enums", declarationCounterVisitor.enumCount))
counts.add(Pair("structs", declarationCounterVisitor.structCount))
counts.add(Pair("functions", declarationCounterVisitor.functionCount))
counts.add(Pair("tasks", declarationCounterVisitor.taskCount))
counts.add(Pair("constructors", declarationCounterVisitor.constructorCount))
counts.add(Pair("initialBlocks", declarationCounterVisitor.initialBlockCount))
counts.add(Pair("alwaysComBlocks", declarationCounterVisitor.alwaysComBlockCount))
counts.add(Pair("alwaysSeqBlocks", declarationCounterVisitor.alwaysSeqBlockCount))
counts.add(Pair("properties", declarationCounterVisitor.propertyCount))
counts.add(Pair("componentInstantiations", declarationCounterVisitor.componentInstantiationCount))
counts.add(Pair("constraints", declarationCounterVisitor.constraintCount))
projectContext.report.counts = counts.filter { it.second != 0 }
}

class DeclarationCounterVisitor : TreeVisitor() {

var packageCount = 0
var classCount = 0
var moduleCount = 0
var moduleInterfaceCount = 0
var enumCount = 0
var structCount = 0
var functionCount = 0
var taskCount = 0
var constructorCount = 0
var initialBlockCount = 0
var alwaysComBlockCount = 0
var alwaysSeqBlockCount = 0
var propertyCount = 0
var componentInstantiationCount = 0
var constraintCount = 0

override fun visitPackage(pkg: EPackage) {
super.visitPackage(pkg)
packageCount++
}

override fun visitSvClass(cls: ESvClass) {
super.visitSvClass(cls)
classCount++
}

override fun visitModule(module: EModule) {
super.visitModule(module)
moduleCount++
}

override fun visitModuleInterface(moduleInterface: EModuleInterface) {
super.visitModuleInterface(moduleInterface)
moduleInterfaceCount++
}

override fun visitEnum(enum: EEnum) {
super.visitEnum(enum)
enumCount++
}

override fun visitStruct(struct: EStruct) {
super.visitStruct(struct)
structCount++
}

override fun visitSvFunction(function: ESvFunction) {
super.visitSvFunction(function)
functionCount++
}

override fun visitTask(task: ETask) {
super.visitTask(task)
taskCount++
}

override fun visitSvConstructor(constructor: ESvConstructor) {
super.visitSvConstructor(constructor)
constructorCount++
}

override fun visitInitialBlock(initialBlock: EInitialBlock) {
super.visitInitialBlock(initialBlock)
initialBlockCount++
}

override fun visitAlwaysComBlock(alwaysComBlock: EAlwaysComBlock) {
super.visitAlwaysComBlock(alwaysComBlock)
alwaysComBlockCount++
}

override fun visitAlwaysSeqBlock(alwaysSeqBlock: EAlwaysSeqBlock) {
super.visitAlwaysSeqBlock(alwaysSeqBlock)
alwaysSeqBlockCount++
}

override fun visitProperty(property: EProperty) {
super.visitProperty(property)
propertyCount++
}

override fun visitComponentInstantiation(componentInstantiation: EComponentInstantiation) {
super.visitComponentInstantiation(componentInstantiation)
componentInstantiationCount++
}

override fun visitConstraint(constraint: EConstraint) {
super.visitConstraint(constraint)
constraintCount++
}
}
}
Loading

0 comments on commit 0461c5a

Please sign in to comment.