Last active
August 29, 2015 14:04
-
-
Save dhh1128/1fc2a20ffb370ba39327 to your computer and use it in GitHub Desktop.
id validator mark
This file contains 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
id_validator: mark | |
propagation: propagation_types.package | propagation_types.viral | |
# Override mark.infect() -- define what parts of code should acquire this mark | |
# automatically. Return a list of (site, mark_type) tuples. | |
def infect(site): | |
infected = [] | |
for module in site.package.modules: | |
for function in module.functions: | |
for param in function.parameters: | |
if param.datatype == typeof(str) and param.name == "id": | |
infected.append(param, mark_types.implicit_affirmative) | |
return infected | |
def can_bind(site): | |
if site.type != site_types.package: | |
return "Must be placed on a package." | |
# At compile time, generate appropriate preconditions | |
# in the code for the function that uses a marked parameter | |
def generate(site): | |
insert_point = site.function.body.statements[0] | |
generated = "precondition(%s)\nn = len(%s)" % site.name | |
generated += "precondition(s >= 20 and s <= 40)" % site.name | |
return insert_point, generated |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment