This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[treelang] Fix external references and argument-less functions
- From: ja2morri at csclub dot uwaterloo dot ca (James A. Morrison)
- To: gcc-patches at gcc dot gnu dot org
- Date: 26 Jan 2005 20:58:20 -0500
- Subject: [treelang] Fix external references and argument-less functions
Hi,
This patch allows treelang files with external_references to compile, as
they are documented to. It also allows functions that take no arguments to
be called. This patch has been tested with make tree1 and make check-treelang.
I'm currently bootstrapping and regtesting on sparc-linux. Ok for mainline if
the testing passes?
--
Thanks,
Jim
http://www.student.cs.uwaterloo.ca/~ja2morri/
http://phython.blogspot.com
http://open.nit.ca/wiki/?page=jim
2005-01-26 James A. Morrison <phython@gcc.gnu.org>
* parse.y: (function_prototype): Accept EXTERNAL_REFERENCE_STORAGE.
Move function parameters check from ...
(function): ...Here. Update call to tree_code_create_function_initial.
(function_invocation): Use expressions_with_commas_opt instead of
expressions_with_commas.
(expressions_with_commas_opt): New rule.
* treetree.c (tree_code_create_function_prototype): Create PARM_DECLs
for function parameters.
(tree_code_create_function_initial): Remove PARMS parameter.
Don't create PARM_DECLs for function parameters.
* treetree.h (tree_code_create_function_initial): Remove PARMS
parameter.
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/treelang/parse.y,v
retrieving revision 1.17
diff -u -p -r1.17 parse.y
--- parse.y 6 Oct 2004 04:47:42 -0000 1.17
+++ parse.y 27 Jan 2005 00:38:42 -0000
@@ -3,7 +3,7 @@
---------------------------------------------------------------------
-Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004
+Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
@@ -273,6 +273,7 @@ storage typename NAME LEFT_PARENTHESIS p
{
case STATIC_STORAGE:
case EXTERNAL_DEFINITION_STORAGE:
+ case EXTERNAL_REFERENCE_STORAGE:
break;
case AUTOMATIC_STORAGE:
@@ -324,6 +325,17 @@ storage typename NAME LEFT_PARENTHESIS p
STORAGE_CLASS (prod),
NUMERIC_TYPE (type),
first_parms, tok->tp.tok.location);
+
+#ifdef ENABLE_CHECKING
+ /* Check all the parameters have code. */
+ for (this_parm = PARAMETERS (prod);
+ this_parm;
+ this_parm = this_parm->tp.pro.next)
+ {
+ gcc_assert ((struct prod_token_parm_item*)VARIABLE (this_parm));
+ gcc_assert (((struct prod_token_parm_item*)VARIABLE (this_parm))->tp.pro.code);
+ }
+#endif
}
;
@@ -332,7 +344,6 @@ NAME LEFT_BRACE {
struct prod_token_parm_item *proto;
struct prod_token_parm_item search_prod;
struct prod_token_parm_item* tok;
- struct prod_token_parm_item *this_parm;
tok = $1;
SYMBOL_TABLE_NAME ((&search_prod)) = tok;
search_prod.category = token_category;
@@ -346,20 +357,9 @@ NAME LEFT_BRACE {
gcc_assert (proto->tp.pro.code);
- tree_code_create_function_initial (proto->tp.pro.code, tok->tp.tok.location,
- FIRST_PARMS (current_function));
-
-#ifdef ENABLE_CHECKING
- /* Check all the parameters have code. */
- for (this_parm = PARAMETERS (proto);
- this_parm;
- this_parm = this_parm->tp.pro.next)
- {
- gcc_assert ((struct prod_token_parm_item*)VARIABLE (this_parm));
- gcc_assert (((struct prod_token_parm_item*)VARIABLE (this_parm))->tp.pro.code);
- }
-#endif
+ tree_code_create_function_initial (proto->tp.pro.code, tok->tp.tok.location);
}
+
variable_defs_opt statements_opt RIGHT_BRACE {
struct prod_token_parm_item* tok;
tok = $1;
@@ -610,7 +610,7 @@ INTEGER {
;
function_invocation:
-NAME LEFT_PARENTHESIS expressions_with_commas RIGHT_PARENTHESIS {
+NAME LEFT_PARENTHESIS expressions_with_commas_opt RIGHT_PARENTHESIS {
struct prod_token_parm_item *prod;
struct prod_token_parm_item* tok;
struct prod_token_parm_item search_prod;
@@ -677,6 +677,13 @@ NAME LEFT_PARENTHESIS expressions_with_c
}
;
+expressions_with_commas_opt:
+/* Nil. */ {
+$$ = 0
+}
+|expressions_with_commas { $$ = $1 }
+;
+
expressions_with_commas:
expression {
struct prod_token_parm_item *exp;
Index: treetree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/treelang/treetree.c,v
retrieving revision 1.50
diff -u -p -r1.50 treetree.c
--- treetree.c 25 Oct 2004 03:03:24 -0000 1.50
+++ treetree.c 27 Jan 2005 00:38:43 -0000
@@ -5,7 +5,7 @@
you are in the right place.
Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
- 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This code is based on toy.c written by Richard Kenner.
@@ -325,6 +325,7 @@ tree_code_create_function_prototype (uns
tree type_node;
tree fn_type;
tree fn_decl;
+ tree parm_list = NULL_TREE;
/* Build the type. */
id = get_identifier ((const char*)chars);
@@ -377,6 +380,37 @@ tree_code_create_function_prototype (uns
gcc_unreachable ();
}
+ /* Make the argument variable decls. */
+ for (parm = parms; parm; parm = parm->tp.par.next)
+ {
+ tree parm_decl = build_decl (PARM_DECL, get_identifier
+ ((const char*) (parm->tp.par.variable_name)),
+ tree_code_get_type (parm->type));
+
+ /* Some languages have different nominal and real types. */
+ DECL_ARG_TYPE (parm_decl) = TREE_TYPE (parm_decl);
+ gcc_assert (DECL_ARG_TYPE (parm_decl));
+ gcc_assert (fn_decl);
+ DECL_CONTEXT (parm_decl) = fn_decl;
+ DECL_SOURCE_LOCATION (parm_decl) = loc;
+ parm_list = chainon (parm_decl, parm_list);
+ }
+
+ /* Back into reverse order as the back end likes them. */
+ parm_list = nreverse (parm_list);
+
+ DECL_ARGUMENTS (fn_decl) = parm_list;
+
+ /* Save the decls for use when the args are referred to. */
+ for (parm = parms; parm_list;
+ parm_list = TREE_CHAIN (parm_list),
+ parm = parm->tp.par.next)
+ {
+ gcc_assert (parm); /* Too few. */
+ *parm->tp.par.where_to_put_var_tree = parm_list;
+ }
+ gcc_assert (!parm); /* Too many. */
+
/* Process declaration of function defined elsewhere. */
rest_of_decl_compilation (fn_decl, 1, 0);
@@ -385,21 +419,16 @@ tree_code_create_function_prototype (uns
/* Output code for start of function; the decl of the function is in
- PREV_SAVED (as created by tree_code_create_function_prototype),
- the function is at line number LINENO in file FILENAME. The
- parameter details are in the lists PARMS. Returns nothing. */
+ PREV_SAVED (as created by tree_code_create_function_prototype),
+ the function is at line number LINENO in file FILENAME. The
+ parameter details are in the lists PARMS. Returns nothing. */
+
void
tree_code_create_function_initial (tree prev_saved,
- location_t loc,
- struct prod_token_parm_item* parms)
+ location_t loc)
{
tree fn_decl;
- tree param_decl;
- tree parm_decl;
- tree parm_list;
tree resultdecl;
- struct prod_token_parm_item* this_parm;
- struct prod_token_parm_item* parm;
fn_decl = prev_saved;
gcc_assert (fn_decl);
@@ -425,40 +454,6 @@ tree_code_create_function_initial (tree
DECL_SOURCE_LOCATION (resultdecl) = loc;
DECL_RESULT (fn_decl) = resultdecl;
- /* Make the argument variable decls. */
- parm_list = NULL_TREE;
- for (parm = parms; parm; parm = parm->tp.par.next)
- {
- parm_decl = build_decl (PARM_DECL, get_identifier
- ((const char*) (parm->tp.par.variable_name)),
- tree_code_get_type (parm->type));
-
- /* Some languages have different nominal and real types. */
- DECL_ARG_TYPE (parm_decl) = TREE_TYPE (parm_decl);
- gcc_assert (DECL_ARG_TYPE (parm_decl));
- gcc_assert (fn_decl);
- DECL_CONTEXT (parm_decl) = fn_decl;
- DECL_SOURCE_LOCATION (parm_decl) = loc;
- parm_list = chainon (parm_decl, parm_list);
- }
-
- /* Back into reverse order as the back end likes them. */
- parm_list = nreverse (parm_list);
-
- DECL_ARGUMENTS (fn_decl) = parm_list;
-
- /* Save the decls for use when the args are referred to. */
- for (param_decl = DECL_ARGUMENTS (fn_decl),
- this_parm = parms;
- param_decl;
- param_decl = TREE_CHAIN (param_decl),
- this_parm = this_parm->tp.par.next)
- {
- gcc_assert (this_parm); /* Too few. */
- *this_parm->tp.par.where_to_put_var_tree = param_decl;
- }
- gcc_assert (!this_parm); /* Too many. */
-
/* Create a new level at the start of the function. */
pushlevel (0);
@@ -723,7 +716,7 @@ tree_code_get_expression (unsigned int e
break;
case EXP_FUNCTION_INVOCATION:
- gcc_assert (op1 && op2);
+ gcc_assert (op1);
{
tree fun_ptr;
fun_ptr = fold (build1 (ADDR_EXPR,
Index: treetree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/treelang/treetree.h,v
retrieving revision 1.9
diff -u -p -r1.9 treetree.h
--- treetree.h 8 Aug 2004 04:47:17 -0000 1.9
+++ treetree.h 27 Jan 2005 00:38:43 -0000
@@ -40,14 +36,13 @@ void tree_ggc_storage_always_used (void
tree tree_code_get_expression (unsigned int exp_type, tree type, tree op1, tree op2, tree op3);
tree tree_code_get_numeric_type (unsigned int size1, unsigned int sign1);
void tree_code_create_function_initial (tree prev_saved,
- location_t loc,
- struct prod_token_parm_item* parms);
+ location_t loc);
void tree_code_create_function_wrapup (location_t loc);
tree tree_code_create_function_prototype (unsigned char* chars,
unsigned int storage_class,
unsigned int ret_type,
- struct prod_token_parm_item* parms,
- location_t loc);
+ struct prod_token_parm_item* parms,
+ location_t loc);
tree tree_code_create_variable (unsigned int storage_class,
unsigned char* chars,
unsigned int length,