File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,10 @@ impl comptimeDecl {
6464 // Returns declaration information wrappers for methods.
6565 // Supports only structures and traits.
6666 fn Methods(self): comptimeDecls
67+
68+ // Returns count of tags as constant expression.
69+ // Supports only structure fields.
70+ fn Tags(self): int
6771}
6872
6973*/
Original file line number Diff line number Diff line change @@ -1984,6 +1984,26 @@ impl comptimeDecl {
19841984 }
19851985 }
19861986
1987+ fn _Tags(mut &self, mut &e: &eval, mut &fc: &ast::FuncCallExpr): &Value {
1988+ if len(fc.Args) > 0 {
1989+ e.pushErr(fc.Args[0].Token, log::ArgumentOverflow, "Tags")
1990+ ret nil
1991+ }
1992+ match type self.decl {
1993+ | &Field:
1994+ f := self.decl.(&Field)
1995+ mut constant := constant::Const.NewI64(i64(len(f.Tags)))
1996+ ret &Value{
1997+ untyped: true,
1998+ Type: primInt,
1999+ Constant: constant,
2000+ Model: constant,
2001+ }
2002+ |:
2003+ panic("sema: comptimeDecl.Tags: unimplemented declaration kind")
2004+ }
2005+ }
2006+
19872007 fn subIdent(mut &self, &ident: str): &Value {
19882008 match ident {
19892009 | "Name":
@@ -2056,6 +2076,13 @@ impl comptimeDecl {
20562076 },
20572077 }
20582078 ret buildAsComptimeMethodData(method)
2079+ | "Tags":
2080+ mut method := &FuncIns{
2081+ caller: fn(mut &e: &eval, mut &fc: &ast::FuncCallExpr, mut &_: &Value): &Value {
2082+ ret self._Tags(e, fc)
2083+ },
2084+ }
2085+ ret buildAsComptimeMethodData(method)
20592086 |:
20602087 ret nil
20612088 }
You can’t perform that action at this time.
0 commit comments