Skip to content
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
20 changes: 18 additions & 2 deletions Src/PCompiler/CompilerCore/TypeChecker/Analyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public static Scope AnalyzeCompilationUnit(ICompilerConfiguration config,
FunctionValidator.CheckAllPathsReturn(handler, machineFunction);
}

// Step 3b: for PVerifier, fill in body of Invariants, Axioms, Init conditions and Pure functions
// Step 3b: for PVerifier, fill in body of Invariants, Axioms, Init conditions and Pure functions and functions with pre/post conditions
foreach (var inv in globalScope.Invariants)
{
var ctx = (PParser.InvariantDeclContext) inv.SourceLocation;
var ctx = (PParser.InvariantDeclContext)inv.SourceLocation;
var temporaryFunction = new Function(inv.Name, inv.SourceLocation)
{
Scope = globalScope
Expand Down Expand Up @@ -78,6 +78,22 @@ public static Scope AnalyzeCompilationUnit(ICompilerConfiguration config,
}
}

foreach (var func in allFunctions.Where(func => func.Role.HasFlag(FunctionRole.Foreign)))
{
// populate pre/post conditions
var ctx = (PParser.ForeignFunDeclContext)func.SourceLocation;
foreach (var req in ctx._requires)
{
var preExpr = PopulateExpr(func, req, PrimitiveType.Bool, handler);
func.AddRequire(preExpr);
}
foreach (var post in ctx._ensures)
{
var postExpr = PopulateExpr(func, post, PrimitiveType.Bool, handler);
func.AddEnsure(postExpr);
}
}

// Step 2b: Validate no static handlers
foreach (var machine in globalScope.Machines)
{
Expand Down
12 changes: 1 addition & 11 deletions Src/PCompiler/CompilerCore/TypeChecker/DeclarationVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -735,17 +735,7 @@ public override object VisitForeignFunDecl(PParser.ForeignFunDeclContext context

var exprVisitor = new ExprVisitor(temporaryFunction, Handler);

// (REQUIRES requires+=expr SEMI)*
foreach (var req in context._requires)
{
fun.AddRequire(exprVisitor.Visit(req));
}

// (ENSURES ensures+=expr SEMI)*
foreach (var ensure in context._ensures)
{
fun.AddEnsure(exprVisitor.Visit(ensure));
}
// pre/post conditions are handled in a later phase

return fun;
}
Expand Down
Loading