[Prev][Next][Index]

overloading functions




Overloading works fine for member functions, and friend functions but
for global functions the symbol information is wrong.

first member functions:

-over1.cc---------------------8<------------------------------
class C {
public:
  int f( int );
  int f( float );
};
------------------------------8<------------------------------

% pC++2dep overc.cc
% dumpdep overc.dep
:
:
***SYMBOL NODES***

   id   var   type  attr  next   scope  variable-name
   1-S  550   ----    0   ----   ----              *                                               DEFAULT
   2-S  504   ----    0    3-S    1-B    ElementType                                             TYPE_NAME
   3-S  511   12-T    0   ----    1-B              C                                              CLASS_NAME
   4-S  510    1-T   64    6-S    2-B              f n_in=    0 n_out=    0 n_io=    0
                                     in_l=         5-S out_l=   ---- sy_l=   ---- f_hdr=   ---- 
                                     m_nxt=    6-S   b_name=    3-S   dec_name=   ----           MEMBER_FUNC
   5-S  503    1-T    0   ----    3-B             -- local=   0 nxt_in=  ---- nxt_out=  ----     VARIABLE_NAME
   6-S  510    1-T   64   ----    2-B              f n_in=    0 n_out=    0 n_io=    0
                                     in_l=         7-S out_l=   ---- sy_l=   ---- f_hdr=   ---- 
                                     m_nxt=   ----   b_name=    3-S   dec_name=   ----           MEMBER_FUNC
   7-S  503    2-T    0   ----    4-B             -- local=   0 nxt_in=  ---- nxt_out=  ----     VARIABLE_NAME
:
:

and you can see that two member function symbol nodes are reported
correctly.

but for:

-over2.cc---------------------8<------------------------------
int f( int );
int f( float );
------------------------------8<------------------------------

% pC++2dep over2.cc
% dumpdep over2.dep
:
:
***SYMBOL NODES***

   id   var   type  attr  next   scope  variable-name
   1-S  550   ----    0   ----   ----              *                                               DEFAULT
   2-S  504   ----    0    3-S    1-B    ElementType                                             TYPE_NAME
   3-S  511   12-T    0    4-S    1-B              C                                              CLASS_NAME
   4-S  509    1-T    0   ----    1-B              f n_in=    0 n_out=    0 n_io=    0
                                       in_l=    6-S out_l=   ---- sy_l=   ---- p_hdr=   ----     FUNCTION_NAME
   5-S  503    1-T    0   ----    3-B             -- local=   0 nxt_in=  ---- nxt_out=  ----     VARIABLE_NAME
   6-S  503    2-T    0   ----    4-B             -- local=   0 nxt_in=  ---- nxt_out=  ----     VARIABLE_NAME
:
:

you can see that only one function symbol is reported.


This problem manifests itself in the Sage class library by the
SgVarDeclStmt::symbol() returning the wrong information.

If I parse over2.cc above, and look through the function declarations:

{
  for ( SgStatement* stmt = file.firstStatement(); stmt; 
        stmt = stmt->lexNext() ) {

    SgVarDeclStmt* declaration_stmt = isSgVarDeclStmt( stmt );
    if ( declaration_stmt ) {

      int no_of_vars_declared = declaration_stmt->numberOfSymbols();
      for ( int i=0; i < no_of_vars_declared; i++ ) {
	SgSymbol* declared_symbol = declaration_stmt->symbol( i );
	
	SgFunctionSymb* function_symbol = isSgFunctionSymb( symbol );
	if ( function_symbol ) {

	  cout << (void*)function_symbol << endl;

	}
      }
    }
  }
}

You can see that the same function symbol is returned twice.  Decoding
the function symbol further with some more code shows that the
function symbol for the last function declaration (lexically) in the file
is the one that is returned in both cases.

This bug also affects non-member overloaded operators:

ie. it impossible to access the symbols of both of

C operator-(const C&);
C operator-(const C&, const C&);

as operator-() is an overloaded function.

Adam

_______________________________________________________________
email:aba@dcs.exeter.ac.uk        http://dcs.exeter.ac.uk/~aba/