Commit e939f8c9 authored by Sven Fehlmann's avatar Sven Fehlmann

Merge branch 'master' into nucppn

# Conflicts:
#	pseuco-tests
#	src/compiler.ts
parents 95ff0e13 e837ebb4
Pipeline #20052 failed with stages
in 34 seconds
{
"name": "@pseuco/pseuco-cpn-compiler",
"version": "1.3.9",
"version": "1.3.10",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......
{
"name": "@pseuco/pseuco-cpn-compiler",
"version": "1.3.9",
"version": "1.3.10",
"description": "Compiles pseuCo programs to colored Petri nets.",
"main": "dist/main.js",
"types": "dist/main.d.ts",
......
import * as _ from 'lodash';
import {UnitStore} from "./unit-store";
import {NameSuggester, PetriNet, coloredPetriNetsPlusPlusCompiler, UnitType} from '@pseuco/colored-petri-nets';
import { NameSuggester, PetriNet } from '@pseuco/colored-petri-nets';
import * as PseuCo from '@pseuco/lang';
import {
......@@ -81,7 +81,7 @@ class ExpressionPartCompilationResult {
}
}
getSubExpressionPattern(): string { // gets a pattern that receives all subexpressions
getSubExpressionPattern (): string { // gets a pattern that receives all subexpressions
return subExpressionPatternForCount(this.subexpressionCount);
}
}
......@@ -128,7 +128,7 @@ class CompilerState {
// partial petri net
this.places = [];
this.transitions = [];
this.initialMarking = {tokens: {}, extensions: {}};
this.initialMarking = { tokens: {}, extensions: {} };
// suggesters that prevent duplicate keys
this.placeNameSuggester = new NameSuggester();
......@@ -189,7 +189,7 @@ class CompilerState {
_.each(this.transitions, mendTransition);
_.each(this.registeredProcedures, (registeredProcedure) => {
if (registeredProcedure.targetPlace == keyToMerge) registeredProcedure.targetPlace = keyToKeep;
if(registeredProcedure.targetPlace == keyToMerge) registeredProcedure.targetPlace = keyToKeep;
_.each(registeredProcedure.calls, mendTransition);
});
......@@ -282,7 +282,7 @@ class Scope {
}
blockSuccessor(containingStructureId?: number): Scope { // creates a new scope for a following block
return new Scope(false, _.clone(this.procedures), _.clone(this.structures), _.clone(this.conditions), _.clone(this.variables), containingStructureId !== undefined ? containingStructureId : this.containingStructureId, false, containingStructureId !== undefined); // successor will not share anything
return new Scope(false, _.clone(this.procedures), this.structures, _.clone(this.conditions), _.clone(this.variables), containingStructureId !== undefined ? containingStructureId : this.containingStructureId, false, containingStructureId !== undefined); // successor will not share anything
}
}
......@@ -376,7 +376,7 @@ function scopeAfterStructOrMonitor(statement: PseuCo.Struct | PseuCo.Monitor, st
const innerStructScope = scope.blockSuccessor(structureId);
const scopifiedBody = scopifyList(statement.children, state, unitStore, innerStructScope);
const scopeAtEndOfStructDecl = statement.children.length ? _.last(scopifiedBody)!.scope : innerStructScope; // ! is OK because we check that there are children
if (scopeAtEndOfStructDecl.currentStructureData === false) throw new Error("Internal inconsistency: Compiling struct without scope data.");
structureRecord.procedures = scopeAtEndOfStructDecl.currentStructureData.procedures;
structureRecord.fields = scopeAtEndOfStructDecl.currentStructureData.variables;
......@@ -385,7 +385,7 @@ function scopeAfterStructOrMonitor(statement: PseuCo.Struct | PseuCo.Monitor, st
structureRecord.scopifiedBody = scopifiedBody; // needed later during compilation – need to keep it, as re-scopification would define duplicate procedures
scope.defineStructure(name, structureId);
return scope;
}
......@@ -1013,13 +1013,16 @@ const lookupProcedure = function (purpose: string, state: CompilerState, unitSto
const classType = instanceExpression.getType();
if (!(classType instanceof PseuCo.ClassType)) throw new Error("Internal consistency: Trying to look up procedure, but instance type is not ClassType.");
const className = classType.identifier;
structureId = scope.structures[className].structureId;
const structureScopeData = scope.structures[className];
if (!structureScopeData) throw new Error(`Internal inconsistency: Trying to ${purpose} the procedure "${procedureName}" of class "${className}" which is not in scope.`);
structureId = structureScopeData.structureId;
structureRecord = state.registeredStructures[structureId];
if (structureRecord.procedures === undefined) throw new Error("Internal inconsistency: Trying to look up procedure in structure without procedure data.");
procedureScopeData = structureRecord.procedures[procedureName];
} else {
procedureScopeData = scope.procedures[procedureName];
}
if (!procedureScopeData) throw new Error(`Internal inconsistency: Trying to ${purpose} the procedure "${procedureName}" which is not in scope.`);
const procedureId = procedureScopeData.procedureId;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment