Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
onMessageSend_afsa
package metaobjectTest
@doc{*
Annotations of this metaobject should be attached to a method or
method signature (of an interface).
The attached DSL code is made in Myan, which supports interpreted Cyan
within parameterless methods declared with 'func':
func afti_codeToAdd {
// interpreted Cyan code
}
According to the method name, the Cyan code is interpreted in phase
afti or dsa. Methods of interfaces
IAction_dsa
IActionNewPrototypes_dsa
IAction_afti
IActionNewPrototypes_afti
IParseWithCyanCompiler_dpa
ICommunicateInPrototype_afti_dsa_afsa
ICheckMessageSend_afsa
can be implemented. To better understand this, see the documentation
for action_afti_dsa.
*}
object OnMessageSend_afsa
func run {
var Int k = 0;
// error if uncommented: the first parameter should be literal
// self at: k, "";
// ok
self at: 5, "";
}
/*
This annotation demands that the first parameter to
the message passing should be a literal Int
*/
@onMessageSend_afsa{*
func afsa_checkKeywordMessageSend {
// first parameter
var expr = (message getkeywordParameterList
get: 0) getExprList get: 0;
if ! (Null instanceof: expr, "meta.WrExprLiteral") {
var s = message getFirstSymbol;
var Int lineNumber = s getLineNumber;
var String fn = s getCompilationUnit getFullFileNamePath;
metaobject addError: "In line " ++ lineNumber ++ " of file " ++
fn ++ ": the first parameter to this " ++
"message passing should be a literal Int"
}
}
*}
func at: Int n, String s {
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.