Skip to content

Instantly share code, notes, and snippets.

@joseoliv
Last active August 31, 2022 12:22
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 joseoliv/4eead47a5fac689bbd8dd8749df3067f to your computer and use it in GitHub Desktop.
Save joseoliv/4eead47a5fac689bbd8dd8749df3067f to your computer and use it in GitHub Desktop.
onDeclaration_afterSemAn
package metaobjectTest
@doc{*
Annotations of this metaobject are attached to a declaration. The
Cyan code attached to the annotation is run in phase afterSemAn. Method
afterSemAn_checkDeclaration of the class of metaobject onDeclaration_afterSemAn,
overridden from ICheckDeclaration_afterSemAn, just interpret the Cyan
statements attached to the annotation.
Then, in phase afterSemAn of the compilation, the Myan statements below
are interpreted. Myan is interpreted Cyan.
To better understand this, see the documentation for action_afterResTypes_semAn.
*}
@onDeclaration_afterSemAn{*
var Boolean found = false;
var Int size = compiler getMethodDecList size;
for i in 0..< size {
var String methodName = ((compiler getMethodDecList) get: i) getName;
if methodName == "run" {
found = true;
break;
}
}
if !found {
metaobject addError: "This prototype should have a 'run' method";
}
*}
object OnDeclaration_afterSemAn
func run {
}
@onDeclaration_afterSemAn{*
var annotation = metaobject getAnnotation;
var String name = annotation getDeclaration getName;
if name != "age" {
metaobject addError: "Field name should be 'age'"
}
*}
var Int age = 0;
@onDeclaration_afterSemAn{*
var Int size = metaobject getAttachedDeclaration
getMethodSignature getParameterList size;
if ( size != 2 ) {
metaobject addError: "This method should have two paramters"
}
*}
func at: Int n put: String s {
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment