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 * Module: whirl2c_common.c 00040 * $Revision: 1.2 $ 00041 * $Date: 02/11/07 23:42:00-00:00 $ 00042 * $Author: fchow@keyresearch.com $ 00043 * $Source: /scratch/mee/2.4-65/kpro64-pending/be/whirl2c/SCCS/s.whirl2c_common.cxx $ 00044 * 00045 * Revision history: 00046 * 07-Nov-94 - Original Version 00047 * 00048 * Description: 00049 * 00050 * See whirl2c_common.h for comments on this file. 00051 * 00052 * ==================================================================== 00053 * ==================================================================== 00054 */ 00055 00056 #include <ctype.h> 00057 #include "whirl2c_common.h" 00058 #include "PUinfo.h" 00059 00060 00061 /*----------- Various Utility functions -----------*/ 00062 00063 void WHIRL2C_parenthesize(TOKEN_BUFFER tokens) 00064 { 00065 Prepend_Token_Special(tokens, '('); 00066 Append_Token_Special(tokens, ')'); 00067 } /* WHIRL2C_parenthesize */ 00068 00069 00070 /*----------- Functions and state for identifier naming -----------*/ 00071 00072 const char * 00073 WHIRL2C_make_valid_c_name(const char *name) 00074 { 00075 /* If name==NULL, then return NULL; otherwise, if a valid name, 00076 * then keep it unaltered; otherwise, construct a valid name 00077 * in a new Name_Buf by removing invalid characters (never return 00078 * NULL for this case) 00079 */ 00080 const char *return_name = name; 00081 char *new_name; 00082 INT name_idx; 00083 00084 if (name != NULL) 00085 { 00086 /* See if we need to construct a new name. First skip valid 00087 * characters (alphanumeric or '_', and beginning with 00088 * an alphabetic or '_' character). 00089 */ 00090 if (isalpha(name[0]) || name[0] == '_') 00091 { 00092 for (name_idx = 1; 00093 (isalnum(name[name_idx]) || 00094 name[name_idx] == '_'); 00095 name_idx++); 00096 } 00097 else /* Incorrect first character */ 00098 { 00099 /* Skip to a valid first character & construct a new name below */ 00100 name_idx = 0; 00101 while (name[name_idx] != '\0' && 00102 !isalpha(name[name_idx]) && 00103 name[name_idx] != '_') 00104 name += 1; 00105 return_name = name; /* Just in case (name[name_idx] == '\0') */ 00106 } 00107 00108 /* Did we find an invalid character? */ 00109 if (name[name_idx] != '\0') 00110 { 00111 /* Need to construct a new name. This should be relatively rare */ 00112 new_name = strcpy(Get_Name_Buf_Slot(strlen(name) + 1), name); 00113 return_name = new_name; 00114 while (*name != '\0') 00115 { 00116 if (isalnum(*name) || *name == '_' || *name == '$') 00117 { 00118 *new_name++ = *name++; 00119 } 00120 else 00121 name++; /* Skip invalid character */ 00122 } 00123 *new_name = '\0'; 00124 } 00125 } 00126 return return_name; 00127 } /* WHIRL2C_make_valid_c_name */ 00128
1.5.6