Changeset 609 for branches/GNU/src/binutils/gas/macro.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/gas/macro.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 /* macro.c - macro support for gas and gasp2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000 1 /* macro.c - macro support for gas 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 3 3 Free Software Foundation, Inc. 4 4 … … 25 25 #include "config.h" 26 26 27 /* AIX requires this to be the first thing in the file. */ 28 #ifdef __GNUC__ 29 # ifndef alloca 30 # ifdef __STDC__ 31 extern void *alloca (); 32 # else 33 extern char *alloca (); 34 # endif 35 # endif 36 #else 27 #ifndef __GNUC__ 37 28 # if HAVE_ALLOCA_H 38 29 # include <alloca.h> 39 30 # else 40 31 # ifdef _AIX 32 /* Indented so that pre-ansi C compilers will ignore it, rather than 33 choke on it. Some versions of AIX require this to be the first 34 thing in the file. */ 41 35 #pragma alloca 42 36 # else … … 50 44 # endif /* _AIX */ 51 45 # endif /* HAVE_ALLOCA_H */ 52 #endif 46 #endif /* __GNUC__ */ 53 47 54 48 #include <stdio.h> … … 58 52 #include <strings.h> 59 53 #endif 60 #include <ctype.h>61 54 #ifdef HAVE_STDLIB_H 62 55 #include <stdlib.h> 63 56 #endif 64 57 #include "libiberty.h" 58 #include "safe-ctype.h" 65 59 #include "sb.h" 66 60 #include "hash.h" … … 70 64 71 65 /* The routines in this file handle macro definition and expansion. 72 They are called by both gasp andgas. */66 They are called by gas. */ 73 67 74 68 /* Internal functions. */ … … 82 76 PARAMS ((int, sb *, sb *, struct hash_control *, int, sb *, int)); 83 77 static const char *macro_expand_body 84 PARAMS ((sb *, sb *, formal_entry *, struct hash_control *, int , int));85 static const char *macro_expand PARAMS ((int, sb *, macro_entry *, sb * , int));78 PARAMS ((sb *, sb *, formal_entry *, struct hash_control *, int)); 79 static const char *macro_expand PARAMS ((int, sb *, macro_entry *, sb *)); 86 80 87 81 #define ISWHITE(x) ((x) == ' ' || (x) == '\t') … … 100 94 /* The macro hash table. */ 101 95 102 st atic struct hash_control *macro_hash;96 struct hash_control *macro_hash; 103 97 104 98 /* Whether any macros have been defined. */ … … 106 100 int macro_defined; 107 101 108 /* Whether we are in GASP alternatemode. */102 /* Whether we are in alternate syntax mode. */ 109 103 110 104 static int macro_alternate; … … 190 184 /* Skip over a label. */ 191 185 while (i < ptr->len 192 && ( isalnum ((unsigned char)ptr->ptr[i])186 && (ISALNUM (ptr->ptr[i]) 193 187 || ptr->ptr[i] == '_' 194 188 || ptr->ptr[i] == '$')) … … 213 207 if (strncasecmp (ptr->ptr + i, from, from_len) == 0 214 208 && (ptr->len == (i + from_len) 215 || ! isalnum(ptr->ptr[i + from_len])))209 || ! ISALNUM (ptr->ptr[i + from_len]))) 216 210 depth++; 217 211 if (strncasecmp (ptr->ptr + i, to, to_len) == 0 218 212 && (ptr->len == (i + to_len) 219 || ! isalnum(ptr->ptr[i + to_len])))213 || ! ISALNUM (ptr->ptr[i + to_len]))) 220 214 { 221 215 depth--; … … 229 223 } 230 224 231 /* Add a CRto the end and keep running. */232 sb_add_char (ptr, '\n');225 /* Add the original end-of-line char to the end and keep running. */ 226 sb_add_char (ptr, more); 233 227 line_start = ptr->len; 234 228 more = get_line (ptr); … … 248 242 { 249 243 if (idx < in->len 250 && ( isalpha ((unsigned char)in->ptr[idx])244 && (ISALPHA (in->ptr[idx]) 251 245 || in->ptr[idx] == '_' 252 246 || in->ptr[idx] == '$')) … … 254 248 sb_add_char (name, in->ptr[idx++]); 255 249 while (idx < in->len 256 && ( isalnum ((unsigned char)in->ptr[idx])250 && (ISALNUM (in->ptr[idx]) 257 251 || in->ptr[idx] == '_' 258 252 || in->ptr[idx] == '$')) … … 373 367 if (idx < in->len) 374 368 { 375 if (in->len > 2 && in->ptr[idx + 1] == '\'' && ISBASE (in->ptr[idx]))369 if (in->len > idx + 2 && in->ptr[idx + 1] == '\'' && ISBASE (in->ptr[idx])) 376 370 { 377 371 while (!ISSEP (in->ptr[idx])) … … 385 379 char buf[20]; 386 380 /* Turns the next expression into a string. */ 381 /* xgettext: no-c-format */ 387 382 idx = (*macro_expr) (_("% operator needs absolute expression"), 388 383 idx + 1, 389 384 in, 390 385 &val); 391 sprintf (buf, "%d", val);386 sprintf (buf, "%d", val); 392 387 sb_add_string (out, buf); 393 388 } … … 574 569 /* And stick it in the macro hash table. */ 575 570 for (idx = 0; idx < name.len; idx++) 576 if (isupper ((unsigned char) name.ptr[idx])) 577 name.ptr[idx] = tolower (name.ptr[idx]); 571 name.ptr[idx] = TOLOWER (name.ptr[idx]); 578 572 namestr = sb_terminate (&name); 579 573 hash_jam (macro_hash, namestr, (PTR) macro); … … 644 638 /* Doing this permits people to use & in macro bodies. */ 645 639 sb_add_char (out, '&'); 640 sb_add_sb (out, t); 646 641 } 647 642 else if (copyifnotthere) … … 660 655 661 656 static const char * 662 macro_expand_body (in, out, formals, formal_hash, comment_char,locals)657 macro_expand_body (in, out, formals, formal_hash, locals) 663 658 sb *in; 664 659 sb *out; 665 660 formal_entry *formals; 666 661 struct hash_control *formal_hash; 667 int comment_char;668 662 int locals; 669 663 { … … 696 690 { 697 691 src++; 698 if (in->ptr[src] == comment_char && comment_char != '\0') 699 { 700 /* This is a comment, just drop the rest of the line. */ 701 while (src < in->len 702 && in->ptr[src] != '\n') 703 src++; 704 } 705 else if (in->ptr[src] == '(') 692 if (in->ptr[src] == '(') 706 693 { 707 694 /* Sub in till the next ')' literally. */ … … 733 720 src++; 734 721 } 735 else if (macro_mri 736 && isalnum ((unsigned char) in->ptr[src])) 722 else if (macro_mri && ISALNUM (in->ptr[src])) 737 723 { 738 724 int ind; 739 725 formal_entry *f; 740 726 741 if ( isdigit ((unsigned char)in->ptr[src]))727 if (ISDIGIT (in->ptr[src])) 742 728 ind = in->ptr[src] - '0'; 743 else if ( isupper ((unsigned char)in->ptr[src]))729 else if (ISUPPER (in->ptr[src])) 744 730 ind = in->ptr[src] - 'A' + 10; 745 731 else … … 765 751 } 766 752 else if ((macro_alternate || macro_mri) 767 && ( isalpha ((unsigned char)in->ptr[src])753 && (ISALPHA (in->ptr[src]) 768 754 || in->ptr[src] == '_' 769 755 || in->ptr[src] == '$') … … 787 773 788 774 src = sb_skip_white (src + 5, in); 789 while (in->ptr[src] != '\n' && in->ptr[src] != comment_char)775 while (in->ptr[src] != '\n') 790 776 { 791 777 static int loccnt; … … 813 799 } 814 800 } 815 }816 else if (comment_char != '\0'817 && in->ptr[src] == comment_char818 && src + 1 < in->len819 && in->ptr[src + 1] == comment_char820 && !inquote)821 {822 /* Two comment chars in a row cause the rest of the line to823 be dropped. */824 while (src < in->len && in->ptr[src] != '\n')825 src++;826 801 } 827 802 else if (in->ptr[src] == '"' … … 907 882 908 883 static const char * 909 macro_expand (idx, in, m, out , comment_char)884 macro_expand (idx, in, m, out) 910 885 int idx; 911 886 sb *in; 912 887 macro_entry *m; 913 888 sb *out; 914 int comment_char;915 889 { 916 890 sb t; … … 937 911 if (idx < in->len && in->ptr[idx] == '.') 938 912 { 939 formal_entry *n; 940 941 n = (formal_entry *) xmalloc (sizeof (formal_entry)); 942 sb_new (&n->name); 943 sb_new (&n->def); 944 sb_new (&n->actual); 945 n->index = QUAL_INDEX; 946 947 n->next = m->formals; 948 m->formals = n; 949 950 idx = get_any_string (idx + 1, in, &n->actual, 1, 0); 913 /* The Microtec assembler ignores this if followed by a white space. 914 (Macro invocation with empty extension) */ 915 idx++; 916 if ( idx < in->len 917 && in->ptr[idx] != ' ' 918 && in->ptr[idx] != '\t') 919 { 920 formal_entry *n; 921 922 n = (formal_entry *) xmalloc (sizeof (formal_entry)); 923 sb_new (&n->name); 924 sb_new (&n->def); 925 sb_new (&n->actual); 926 n->index = QUAL_INDEX; 927 928 n->next = m->formals; 929 m->formals = n; 930 931 idx = get_any_string (idx, in, &n->actual, 1, 0); 932 } 951 933 } 952 934 } … … 954 936 /* Peel off the actuals and store them away in the hash tables' actuals. */ 955 937 idx = sb_skip_white (idx, in); 956 while (idx < in->len && in->ptr[idx] != comment_char)938 while (idx < in->len) 957 939 { 958 940 int scan; … … 1056 1038 } 1057 1039 1058 err = macro_expand_body (&m->sub, out, m->formals, m->formal_hash, 1059 comment_char, 1); 1040 err = macro_expand_body (&m->sub, out, m->formals, m->formal_hash, 1); 1060 1041 if (err != NULL) 1061 1042 return err; … … 1090 1071 1091 1072 /* Check for a macro. If one is found, put the expansion into 1092 *EXPAND. COMMENT_CHAR is the comment character--this is used by 1093 gasp. Return 1 if a macro is found, 0 otherwise. */ 1073 *EXPAND. Return 1 if a macro is found, 0 otherwise. */ 1094 1074 1095 1075 int 1096 check_macro (line, expand, comment_char,error, info)1076 check_macro (line, expand, error, info) 1097 1077 const char *line; 1098 1078 sb *expand; 1099 int comment_char;1100 1079 const char **error; 1101 1080 macro_entry **info; … … 1106 1085 sb line_sb; 1107 1086 1108 if (! isalpha ((unsigned char)*line)1087 if (! ISALPHA (*line) 1109 1088 && *line != '_' 1110 1089 && *line != '$' … … 1113 1092 1114 1093 s = line + 1; 1115 while ( isalnum ((unsigned char)*s)1094 while (ISALNUM (*s) 1116 1095 || *s == '_' 1117 1096 || *s == '$') … … 1122 1101 copy[s - line] = '\0'; 1123 1102 for (cs = copy; *cs != '\0'; cs++) 1124 if (isupper ((unsigned char) *cs)) 1125 *cs = tolower (*cs); 1103 *cs = TOLOWER (*cs); 1126 1104 1127 1105 macro = (macro_entry *) hash_find (macro_hash, copy); … … 1136 1114 1137 1115 sb_new (expand); 1138 *error = macro_expand (0, &line_sb, macro, expand , comment_char);1116 *error = macro_expand (0, &line_sb, macro, expand); 1139 1117 1140 1118 sb_kill (&line_sb); … … 1161 1139 1162 1140 const char * 1163 expand_irp (irpc, idx, in, out, get_line , comment_char)1141 expand_irp (irpc, idx, in, out, get_line) 1164 1142 int irpc; 1165 1143 int idx; … … 1167 1145 sb *out; 1168 1146 int (*get_line) PARAMS ((sb *)); 1169 int comment_char;1170 1147 { 1171 1148 const char *mn; … … 1205 1182 1206 1183 idx = sb_skip_comma (idx, in); 1207 if (idx >= in->len || in->ptr[idx] == comment_char)1184 if (idx >= in->len) 1208 1185 { 1209 1186 /* Expand once with a null string. */ 1210 err = macro_expand_body (&sub, out, &f, h, comment_char,0);1187 err = macro_expand_body (&sub, out, &f, h, 0); 1211 1188 if (err != NULL) 1212 1189 return err; … … 1216 1193 if (irpc && in->ptr[idx] == '"') 1217 1194 ++idx; 1218 while (idx < in->len && in->ptr[idx] != comment_char)1195 while (idx < in->len) 1219 1196 { 1220 1197 if (!irpc) … … 1227 1204 1228 1205 nxt = sb_skip_white (idx + 1, in); 1229 if (nxt >= in->len || in->ptr[nxt] == comment_char)1206 if (nxt >= in->len) 1230 1207 { 1231 1208 idx = nxt; … … 1237 1214 ++idx; 1238 1215 } 1239 err = macro_expand_body (&sub, out, &f, h, comment_char,0);1216 err = macro_expand_body (&sub, out, &f, h, 0); 1240 1217 if (err != NULL) 1241 1218 return err; -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.