Skip to content

Instantly share code, notes, and snippets.

View CheckCatchParameter.cyan
package metaobjectTest
@doc{*
checkCatchParameter checks whether each parameter to a catch: selector
has at least one 'eval:' method, each of them accepting one parameter whose
type is subprototype of CyException
*}
object CheckCatchParameter
@joseoliv
joseoliv / ChangeFunctionForMethod
Last active Jun 22, 2018
Metaobject changeFunctionForMethod
View ChangeFunctionForMethod
package metaobjectTest
@doc{*
This metaobject should only be attached to methods 'functionForMethod:1' and
'functionForMethodWithSelf:1' of Any. It replaces method calls to these
methods by an anonymous function. If the parameter of 'functionForMethod:1' is
a literal string "m:1", then the code that
replaces the method call is
{ (: T elem :) receiver m: elem }
@joseoliv
joseoliv / CallUnaryMethods.cyan
Created Jun 22, 2018
Metaobject callUnaryMethods
View CallUnaryMethods.cyan
package metaobjectTest
@doc{*
callUnaryMethods generates code that calls all methods of
the current prototype whose name matches with the pattern
that is the annotation parameter.
*}
object CallUnaryMethods
func run {
@joseoliv
joseoliv / CallTestMethods.cyan
Created Jun 22, 2018
Metaobject callTestMethods
View CallTestMethods.cyan
package metaobjectTest
@doc{*
callTestMethods generates code that calls all methods of
the current prototype whose name ends with 'Test'. It
is the same as to use annotation @callUnaryMethods(".*Test")
*}
object CallTestMethods
func run {
@joseoliv
joseoliv / Type.cyan
Created Jun 22, 2018
Metaobject Type
View Type.cyan
package metaobjectTest
@doc{*
Annotation 'type' should be attached to a type. It works
much like a language-C typedef but without the explicit
declaration. Every type T@type(id) is compatible only with literals
and types annotated with T@type(id) (both should have the same 'id').
*}
object Type
@joseoliv
joseoliv / Tainted
Created Jun 15, 2018
Metaobjects tainted and untainted
View Tainted
package metaobjectTest
import untainted
object Tainted
func run {
var String@tainted(sql) maliciousSqlCode =
"I will delete your database";
@joseoliv
joseoliv / TaintedToUntainted.cyan
Created Jun 15, 2018
Prototype that can convert any tainted to untainted value
View TaintedToUntainted.cyan
package untainted
object TaintedToUntainted
func toUntaintedSql: String@tainted(sql) s -> String@untainted(sql) = s;
func toUntaintedHtml: String@tainted(html) s -> String@untainted(html) = s;
end
@joseoliv
joseoliv / p.pyan
Created Jun 15, 2018
This is the project file for the program 'metaobject' that has examples of metaobjects
View p.pyan
@addToSet(debug, "yes")
@addToSet(author, "Jose")
/* Because of this association, prototype 'TaintedToUntainted'
of package 'untainted' can cast expressions of type
T@tainted to T@untainted in which T is any type.
*/
@addToSet(untaintedDoNotCheckIn, "untainted.TaintedToUntainted")
program
main metaobjectTest.Program
@joseoliv
joseoliv / Regex.cyan
Created Jun 15, 2018
Metaobject regex
View Regex.cyan
package metaobjectTest
@doc{*
usage:
String@regex(re)
regex checks if the variable holds only strings that match the
regular expression re.
*}
object Regex
@joseoliv
joseoliv / Range.cyan
Created Jun 15, 2018
Metaobject range
View Range.cyan
package metaobjectTest
@doc{*
Ranges are attached to types. A variable of type Int@range(first, last)
can only contain values between first and last (inclusive). This is
checked at compile-time when a literal is assigned to the variable
and at run-time if an expression is assigned to the variable.
*}
object Range
You can’t perform that action at this time.