Skip to content

Instantly share code, notes, and snippets.

@dhh1128
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhh1128/1fc2a20ffb370ba39327 to your computer and use it in GitHub Desktop.
Save dhh1128/1fc2a20ffb370ba39327 to your computer and use it in GitHub Desktop.
id validator mark
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