Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PExplicit] Sync with master branch #721

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions Src/PChecker/CheckerCore/SystematicTesting/TestingEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,25 @@ public class TestingEngine
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true
WriteIndented = true,
Converters = { new EncodingConverter() }
};

internal class EncodingConverter : JsonConverter<Encoding>
{
public override Encoding Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var name = reader.GetString();
if (name == null)
return null;
return Encoding.GetEncoding(name);
}
public override void Write(Utf8JsonWriter writer, Encoding value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.WebName);
}
}

/// <summary>
/// The profiler.
/// </summary>
Expand Down Expand Up @@ -618,9 +634,18 @@ public object RecursivelyReplaceNullWithString(object obj) {
if (obj == null) {
return "null";
}
if (obj is Dictionary<string, object> dictionary) {
if (obj is Dictionary<string, object> dictionaryStr) {
var newDictionary = new Dictionary<string, object>();
foreach (var item in dictionary) {
foreach (var item in dictionaryStr) {
var newVal = RecursivelyReplaceNullWithString(item.Value);
if (newVal != null)
newDictionary[item.Key] = newVal;
}
return newDictionary;
}
else if (obj is Dictionary<int, object> dictionaryInt) {
var newDictionary = new Dictionary<int, object>();
foreach (var item in dictionaryInt) {
var newVal = RecursivelyReplaceNullWithString(item.Value);
if (newVal != null)
newDictionary[item.Key] = newVal;
Expand Down
5 changes: 5 additions & 0 deletions Src/PCompiler/CompilerCore/DefaultTranslationErrorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,5 +334,10 @@ private string DeclarationName(IPDecl method)
{
return method.Name.Length > 0 ? method.Name : $"at {locationResolver.GetLocation(method.SourceLocation)}";
}

public string SpecObservesSetIncompleteWarning(ParserRuleContext ctx, PEvent ev, Machine machine)
{
return $"[!Warning!]\n[{locationResolver.GetLocation(ctx, ctx.start)}] Event {ev.Name} is not in the observes list of the spec machine {machine.Name}. The event-handler is never triggered as the event is not observed by the spec.\n[!Warning!]";
}
}
}
2 changes: 2 additions & 0 deletions Src/PCompiler/CompilerCore/ITranslationErrorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,7 @@ Exception DuplicateStartState(

Exception IllegalChooseSubExprType(PParser.ChooseExprContext context, PLanguageType subExprType);
Exception IllegalFunctionUsedInSpecMachine(Function function, Machine callerOwner);

String SpecObservesSetIncompleteWarning(ParserRuleContext loc, PEvent ev, Machine machine);
}
}
2 changes: 1 addition & 1 deletion Src/PCompiler/CompilerCore/TypeChecker/Analyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static Scope AnalyzeCompilationUnit(ICompilerConfiguration config,
// Step 2: Validate machine specifications
foreach (var machine in globalScope.Machines)
{
MachineChecker.Validate(handler, machine);
MachineChecker.Validate(handler, machine, config);
}

// Step 3: Fill function bodies
Expand Down
23 changes: 22 additions & 1 deletion Src/PCompiler/CompilerCore/TypeChecker/MachineChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,34 @@ namespace Plang.Compiler.TypeChecker
{
public static class MachineChecker
{
public static void Validate(ITranslationErrorHandler handler, Machine machine)
public static void Validate(ITranslationErrorHandler handler, Machine machine, ICompilerConfiguration job)
{
var startState = FindStartState(machine, handler);
var startStatePayloadType = GetStatePayload(startState);
Debug.Assert(startStatePayloadType.IsSameTypeAs(machine.PayloadType));
ValidateHandlers(handler, machine);
ValidateTransitions(handler, machine);
// special validation for monitors:
// ensure that each eventhandler is in the observe set.
ValidateSpecObservesList(handler, machine, job);
}

private static void ValidateSpecObservesList(ITranslationErrorHandler handler, Machine machine, ICompilerConfiguration job)
{
if (machine.IsSpec)
{
foreach (var state in machine.AllStates())
{
foreach (var pair in state.AllEventHandlers)
{
if (!machine.Observes.Events.Contains(pair.Key))
{
job.Output.WriteWarning(
handler.SpecObservesSetIncompleteWarning(pair.Value.SourceLocation, pair.Key, machine));
}
}
}
}
}

private static void ValidateHandlers(ITranslationErrorHandler handler, Machine machine)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
event e1;
event e2;

spec Invariant1 observes e1 {
start state Init {
on e2 goto Init;
}
}

machine Main {
start state Init {

}
}
Loading