Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
whirl2f_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  *  17-Apr-95 - Original Version
00042  *
00043  * Description:
00044  *
00045  *   See whirl2f_common.h for comments on this file.
00046  *
00047  * ====================================================================
00048  * ====================================================================
00049  */
00050 
00051 #include <ctype.h>
00052 #include "whirl2f_common.h"
00053 #include "PUinfo.h"
00054 
00055 /*----------- Functions and state for identifier naming -----------*/
00056 
00057 const char * 
00058 WHIRL2F_make_valid_name(const char *name, BOOL allow_dot )
00059 {
00060    /* If name==NULL, then return NULL;  otherwise, if a valid name,
00061     * then keep it unaltered; otherwise, construct a valid name
00062     * in a new Name_Buf by removing invalid characters (never return
00063     * NULL for this case)
00064     */
00065    const char *return_name = name;
00066    char       *new_name;
00067    INT         name_idx;
00068    
00069    if (name != NULL)
00070    {
00071       /* See if we need to construct a new name. First skip valid
00072        * characters (alphanumeric, '_', or '$', beginning with
00073        * an alphabetic or '_' character).
00074        */
00075       if (isalpha(name[0]) || name[0] == '_')
00076       {
00077          /* See if there are any invalid characters */
00078          for (name_idx = 1;
00079               (isalnum(name[name_idx]) || 
00080                name[name_idx] == '_'   || 
00081                name[name_idx] == '$');
00082               name_idx++);
00083       }
00084       else /* Incorrect first character */
00085       {
00086          /* Skip to first alphabetic or '_' character */
00087          name_idx = 0;
00088          while (name[name_idx] != '\0' && 
00089                 !isalpha(name[name_idx]) && name[name_idx] != '_')
00090             name += 1;
00091          return_name = name;
00092       }
00093       
00094       
00095       /* Did we find an invalid character? */
00096       if (name[name_idx] != '\0')
00097       {
00098          /* Need to construct a new name.  This should be relatively rare */
00099          new_name = strcpy(Get_Name_Buf_Slot(strlen(name) + 1), name);
00100          return_name = new_name;
00101          while (*name != '\0')
00102          {
00103            if ((isalnum(*name)) || 
00104                (*name == '_' )  || 
00105                (*name == '$' )  || 
00106                (*name == '.' && allow_dot))
00107            {
00108                *new_name++ = *name;
00109            }
00110            name++;     /* Skip character (may be invalid) */
00111          }
00112          *new_name = '\0';
00113       }
00114    }
00115    return return_name;
00116 } /* WHIRL2F_make_valid_name */
00117 
00118 
00119 void 
00120 WHIRL2F_Append_Comment(TOKEN_BUFFER  tokens,
00121                        const char   *cmt,
00122                        UINT          prefix_lines,
00123                        UINT          suffix_lines)
00124 {
00125    /* Purpose: Adds prefix_lines+1+postfix_lines number of comment-lines
00126     * to the given token buffer, where the given comment-string (if non-
00127     * NULL) will be insterted on a separate line between the prefix and 
00128     * postifix at the current identation.
00129     */   
00130    if (cmt == NULL || cmt[0] == '\0')
00131    {
00132       Append_F77_Comment_Newline(tokens,
00133                                  prefix_lines + suffix_lines + 1, 
00134                                  FALSE/*ident_last_line*/);
00135    }
00136    else
00137    {
00138       Append_F77_Comment_Newline(tokens, 
00139                                  prefix_lines+1, 
00140                                  TRUE/*ident_last_line*/);
00141       Append_Token_String(tokens, cmt);
00142       Append_F77_Comment_Newline(tokens, 
00143                                  suffix_lines, 
00144                                  FALSE/*ident_last_line*/);
00145    }
00146 } /* WHIRL2F_Append_Comment */
00147 
00148 
00149 void 
00150 WHIRL2F_Parenthesize(TOKEN_BUFFER tokens)
00151 {
00152    Prepend_Token_Special(tokens, '(');
00153    Append_Token_Special(tokens, ')');
00154 } /* WHIRL2F_Parenthesize */
00155 
00156 
00157 
00158 
00159 
00160 
00161 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines