-
Notifications
You must be signed in to change notification settings - Fork 37
Encode slice make as a method call
#607
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3273660
Introduce explicit call to method to make slice
jcp19 b9325eb
Clean up old encoding
jcp19 2b3c6f8
cleanup
jcp19 0cea7b4
use pure instead of checking stuff wrongly
jcp19 7cc6c36
add doc
jcp19 82f7895
Apply suggestions from code review
jcp19 ac8f6d4
Apply suggestions from code review
jcp19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/scala/viper/gobra/translator/util/MethodGenerator.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // This Source Code Form is subject to the terms of the Mozilla Public | ||
| // License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| // file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| // | ||
| // Copyright (c) 2011-2022 ETH Zurich. | ||
|
|
||
| package viper.gobra.translator.util | ||
|
|
||
| import viper.gobra.translator.library.Generator | ||
| import viper.gobra.translator.context.Context | ||
| import viper.silver.{ast => vpr} | ||
|
|
||
| trait MethodGenerator[T] extends Generator { | ||
|
|
||
| override def finalize(addMemberFn: vpr.Member => Unit): Unit = generatedMember foreach addMemberFn | ||
|
|
||
| private var generatedMember: List[vpr.Method] = List.empty | ||
| private var genMap: Map[T, vpr.Method] = Map.empty | ||
|
|
||
| def genMethod(x: T)(ctx: Context): vpr.Method | ||
|
|
||
| def getMethod(x: T)(ctx: Context): vpr.Method = { | ||
| genMap.getOrElse(x, { | ||
| val newMethod = genMethod(x)(ctx) | ||
| genMap += x -> newMethod | ||
| generatedMember ::= newMethod | ||
| newMethod | ||
| }) | ||
| } | ||
|
|
||
| def apply(args: Vector[vpr.Exp], targets: Seq[vpr.LocalVar], x: T)(pos: vpr.Position = vpr.NoPosition, info: vpr.Info = vpr.NoInfo, errT: vpr.ErrorTrafo = vpr.NoTrafos)(ctx: Context): vpr.MethodCall = { | ||
| val method = getMethod(x)(ctx) | ||
| vpr.MethodCall(method, args, targets)(pos, info, errT) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.