From 3e607f146f4c8acac6b42e61a0e6295f52f408a4 Mon Sep 17 00:00:00 2001 From: Nilay Vaish Date: Mon, 15 Oct 2012 17:27:16 -0500 Subject: ruby: allow function definition in slicc structs This patch adds support for function definitions to appear in slicc structs. This is required for supporting functional accesses for different types of messages. Subsequent patches will use this to development. --- src/mem/slicc/parser.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/mem/slicc/parser.py') diff --git a/src/mem/slicc/parser.py b/src/mem/slicc/parser.py index 6b6a1aaef..78b842f74 100644 --- a/src/mem/slicc/parser.py +++ b/src/mem/slicc/parser.py @@ -315,14 +315,23 @@ class SLICC(Grammar): "decl : type ident pairs SEMI" p[0] = ast.ObjDeclAST(self, p[1], p[2], p[3]) + # Function definition and declaration def p_decl__func_decl(self, p): - """decl : void ident '(' params ')' pairs SEMI + "decl : func_decl" + p[0] = p[1] + + def p_func_decl__0(self, p): + """func_decl : void ident '(' params ')' pairs SEMI | type ident '(' params ')' pairs SEMI""" p[0] = ast.FuncDeclAST(self, p[1], p[2], p[4], p[6], None) def p_decl__func_def(self, p): - """decl : void ident '(' params ')' pairs statements - | type ident '(' params ')' pairs statements""" + "decl : func_def" + p[0] = p[1] + + def p_func_def__0(self, p): + """func_def : void ident '(' params ')' pairs statements + | type ident '(' params ')' pairs statements""" p[0] = ast.FuncDeclAST(self, p[1], p[2], p[4], p[6], p[7]) # Type fields @@ -338,6 +347,10 @@ class SLICC(Grammar): "type_member : type_or_void ident '(' types ')' pairs SEMI" p[0] = ast.TypeFieldMethodAST(self, p[1], p[2], p[4], p[6]) + def p_type_method__1(self, p): + "type_member : type_or_void ident '(' params ')' pairs statements" + p[0] = ast.FuncDeclAST(self, p[1], p[2], p[4], p[6], p[7]) + def p_type_member__1(self, p): "type_member : type_or_void ident pairs SEMI" p[0] = ast.TypeFieldMemberAST(self, p[1], p[2], p[3], None) -- cgit v1.2.3