Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
whirl2c_common.cxx
Go to the documentation of this file.
00001 /*
00002 
00003   Copyright (C) 2000, 2001 Silicon Graphics, Inc.  All Rights Reserved.
00004 
00005   This program is free software; you can redistribute it and/or modify it
00006   under the terms of version 2 of the GNU General Public License as
00007   published by the Free Software Foundation.
00008 
00009   This program is distributed in the hope that it would be useful, but
00010   WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013   Further, this software is distributed without any warranty that it is
00014   free of the rightful claim of any third person regarding infringement 
00015   or the like.  Any license provided herein, whether implied or 
00016   otherwise, applies only to this software file.  Patent licenses, if 
00017   any, provided herein do not apply to combinations of this program with 
00018   other software, or any other product whatsoever.  
00019 
00020   You should have received a copy of the GNU General Public License along
00021   with this program; if not, write the Free Software Foundation, Inc., 59
00022   Temple Place - Suite 330, Boston MA 02111-1307, USA.
00023 
00024   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
00025   Mountain View, CA 94043, or:
00026 
00027   http://www.sgi.com
00028 
00029   For further information regarding this notice, see:
00030 
00031   http://oss.sgi.com/projects/GenInfo/NoticeExplan
00032 
00033 */
00034 
00035 
00036 /* ====================================================================
00037  * ====================================================================
00038  *
00039  *
00040  * Revision history:
00041  *  07-Nov-94 - Original Version
00042  *
00043  * Description:
00044  *
00045  *   See whirl2c_common.h for comments on this file.
00046  *
00047  * ====================================================================
00048  * ====================================================================
00049  */
00050 
00051 #include <ctype.h>
00052 #include "whirl2c_common.h"
00053 #include "PUinfo.h"
00054 
00055 
00056 /*----------- Various Utility functions -----------*/
00057 
00058 void WHIRL2C_parenthesize(TOKEN_BUFFER tokens)
00059 {
00060    Prepend_Token_Special(tokens, '(');
00061    Append_Token_Special(tokens, ')');
00062 } /* WHIRL2C_parenthesize */
00063 
00064 
00065 /*----------- Functions and state for identifier naming -----------*/
00066 
00067 const char * 
00068 WHIRL2C_make_valid_c_name(const char *name)
00069 {
00070   /* If name==NULL, then return NULL;  otherwise, if a valid name,
00071    * then keep it unaltered; otherwise, construct a valid name
00072    * in a new Name_Buf by removing invalid characters (never return
00073    * NULL for this case)
00074    */
00075   const char *return_name = name;
00076   char       *new_name;
00077   INT         name_idx;
00078   
00079   if (name != NULL)
00080     {
00081       /* See if we need to construct a new name. First skip valid
00082        * characters (alphanumeric or '_', and beginning with
00083        * an alphabetic or '_' character).
00084        */
00085       if (isalpha(name[0]) || name[0] == '_')
00086         {
00087           for (name_idx = 1;
00088               (isalnum(name[name_idx]) || 
00089                name[name_idx] == '_');
00090                name_idx++);
00091         }
00092       else /* Incorrect first character */
00093         {
00094           /* Skip to a valid first character & construct a new name below */
00095           name_idx = 0;
00096           while (name[name_idx] != '\0'   &&
00097                  !isalpha(name[name_idx]) && 
00098                  name[name_idx] != '_')
00099             name += 1;
00100           return_name = name; /* Just in case (name[name_idx] == '\0') */
00101         }
00102       
00103       /* Did we find an invalid character? */
00104       if (name[name_idx] != '\0')
00105         {
00106           /* Need to construct a new name.  This should be relatively rare */
00107           new_name = strcpy(Get_Name_Buf_Slot(strlen(name) + 1), name);
00108           return_name = new_name;
00109           while (*name != '\0')
00110             {
00111               if (isalnum(*name) || *name == '_' || *name == '$')
00112                 {
00113                   *new_name++ = *name++;
00114                 }
00115               else
00116                 name++; /* Skip invalid character */
00117             }
00118           *new_name = '\0';
00119         }
00120     }
00121   return return_name;
00122 } /* WHIRL2C_make_valid_c_name */
00123 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines