GCC Wikia
Advertisement

このページを編集する際は,編集に関する方針に従ってください.[]

概要[]

引数[]

実装[]

1035 /* External routine to get a token.  Also used nearly everywhere
1036    internally, except for places where we know we can safely call
1037    _cpp_lex_token directly, such as lexing a directive name.
1038 
1039    Macro expansions and directives are transparently handled,
1040    including entering included files.  Thus tokens are post-macro
1041    expansion, and after any intervening directives.  External callers
1042    see CPP_EOF only at EOF.  Internal callers also see it when meeting
1043    a directive inside a macro call, when at the end of a directive and
1044    state.in_directive is still 1, and at the end of argument
1045    pre-expansion.  */
1046 const cpp_token *
1047 cpp_get_token (cpp_reader *pfile)
1048 {
1049   const cpp_token *result;
1050 
1051   for (;;)
1052     {
1053       cpp_hashnode *node;
1054       cpp_context *context = pfile->context;
1055 
1056       /* Context->prev == 0 <=> base context.  */
1057       if (!context->prev)
1058         result = _cpp_lex_token (pfile);
1059       else if (FIRST (context).token != LAST (context).token)
1060         {
1061           if (context->direct_p)
1062             result = FIRST (context).token++;
1063           else
1064             result = *FIRST (context).ptoken++;
1065 
1066           if (result->flags & PASTE_LEFT)
1067             {
1068               paste_all_tokens (pfile, result);
1069               if (pfile->state.in_directive)
1070                 continue;
1071               return padding_token (pfile, result);
1072             }
1073         }
1074       else
1075         {
1076           _cpp_pop_context (pfile);
1077           if (pfile->state.in_directive)
1078             continue;
1079           return &pfile->avoid_paste;
1080         }
1081 
1082       if (pfile->state.in_directive && result->type == CPP_COMMENT)
1083         continue;
1084 
1085       if (result->type != CPP_NAME)
1086         break;
1087 
1088       node = result->val.node;
1089 
1090       if (node->type != NT_MACRO || (result->flags & NO_EXPAND))
1091         break;
1092 
1093       if (!(node->flags & NODE_DISABLED))
1094         {
1095           if (!pfile->state.prevent_expansion
1096               && enter_macro_context (pfile, node))
1097             {
1098               if (pfile->state.in_directive)
1099                 continue;
1100               return padding_token (pfile, result);
1101             }
1102         }
1103       else
1104         {
1105           /* Flag this token as always unexpandable.  FIXME: move this
1106              to collect_args()?.  */
1107           cpp_token *t = _cpp_temp_token (pfile);
1108           t->type = result->type;
1109           t->flags = result->flags | NO_EXPAND;
1110           t->val = result->val;
1111           result = t;
1112         }
1113 
1114       break;
1115     }
1116 
1117   return result;
1118 }



リンク元

Advertisement