preparse.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,697 行 · 第 1/5 页
C
1,697 行
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
/* c:\mks\YACC.EXE -p pre ..\c\preparse.y */
// File generated from preparse.y using yaccpre.bat
#include <stdlib.h>
#include <stdio.h>
#include "wic.h"
static pToken _lastDefineTok;
#define PRESTYPE ParseUnion
#ifndef __SMALL__
#define __SMALL__ 0 // To avoid warnings in MKS yacc
#endif
#pragma disable_message(118)
#define Y_EOF 300
#define Y_EXCLAMATION 301
#define Y_NE 302
#define Y_POUND 303
#define Y_POUND_POUND 304
#define Y_AND 305
#define Y_AND_AND 306
#define Y_AND_EQUAL 307
#define Y_LEFT_PAREN 308
#define Y_RIGHT_PAREN 309
#define Y_TIMES 310
#define Y_TIMES_EQUAL 311
#define Y_PLUS 312
#define Y_PLUS_PLUS 313
#define Y_PLUS_EQUAL 314
#define Y_COMMA 315
#define Y_MINUS 316
#define Y_MINUS_MINUS 317
#define Y_MINUS_EQUAL 318
#define Y_ARROW 319
#define Y_DOT 320
#define Y_DOT_DOT_DOT 321
#define Y_DIVIDE 322
#define Y_DIVIDE_EQUAL 323
#define Y_COLON 324
#define Y_SEG_OP 325
#define Y_SEMICOLON 326
#define Y_LT 327
#define Y_LSHIFT 328
#define Y_LSHIFT_EQUAL 329
#define Y_LE 330
#define Y_EQUAL 331
#define Y_EQ 332
#define Y_GT 333
#define Y_GE 334
#define Y_RSHIFT 335
#define Y_RSHIFT_EQUAL 336
#define Y_QUESTION 337
#define Y_LEFT_BRACKET 338
#define Y_RIGHT_BRACKET 339
#define Y_XOR 340
#define Y_XOR_EQUAL 341
#define Y___BASED 342
#define Y___CDECL 343
#define Y___EXPORT 344
#define Y___FAR 345
#define Y___FAR16 346
#define Y___FORTRAN 347
#define Y___HUGE 348
#define Y___INTERRUPT 349
#define Y___LOADDS 350
#define Y___NEAR 351
#define Y___PASCAL 352
#define Y___PRAGMA 353
#define Y___SAVEREGS 354
#define Y___SEGMENT 355
#define Y___SEGNAME 356
#define Y___SELF 357
#define Y___STDCALL 358
#define Y__PACKED 359
#define Y__SEG16 360
#define Y__SYSCALL 361
#define Y_AUTO 362
#define Y_CHAR 363
#define Y_CONST 364
#define Y_DOUBLE 365
#define Y_ELSE 366
#define Y_ENUM 367
#define Y_EXTERN 368
#define Y_FLOAT 369
#define Y_INT 370
#define Y_LONG 371
#define Y_REGISTER 372
#define Y_SHORT 373
#define Y_SIGNED 374
#define Y_SIZEOF 375
#define Y_STATIC 376
#define Y_STRUCT 377
#define Y_TYPEDEF 378
#define Y_UNION 379
#define Y_UNSIGNED 380
#define Y_VOID 381
#define Y_VOLATILE 382
#define Y_LEFT_BRACE 383
#define Y_OR 384
#define Y_OR_EQUAL 385
#define Y_OR_OR 386
#define Y_RIGHT_BRACE 387
#define Y_TILDE 388
#define Y_ID 389
#define Y_STRING 390
#define Y_INCLUDE_FILE_NAME 391
#define Y_TYPEDEF_NAME 392
#define Y_NUMBER 393
#define Y_PERCENT 394
#define Y_PERCENT_EQUAL 395
#define Y_DEFINED 396
#define Y_PRE_COMMENT 500
#define Y_PRE_NULL 501
#define Y_PRE_NEWLINE 502
#define Y_PRE_DEFINE 503
#define Y_PRE_ELIF 504
#define Y_PRE_ELSE 505
#define Y_PRE_ENDIF 506
#define Y_PRE_ERROR 507
#define Y_PRE_IF 508
#define Y_PRE_IFDEF 509
#define Y_PRE_IFNDEF 510
#define Y_PRE_INCLUDE 511
#define Y_PRE_LINE 512
#define Y_PRE_PRAGMA 513
#define Y_PRE_UNDEF 514
#define Y_PRE_SPECIAL_LEFT_PAREN 515
extern int prechar, preerrflag;
extern PRESTYPE preval, prelval;
static pToken firstToken;
static int expandNextToken;
static int expandThisLine;
int expandThisLineHideErrors;
int successfulExpand;
int preerror(char *str) {
str = str;
return 0;
}
void preparseInterface(pToken t) {
firstToken = t;
expandNextToken = 1;
expandThisLine = 1;
expandThisLineHideErrors = 0;
successfulExpand = 1;
preparse();
}
static int prelex(void) {
int retval;
successfulExpand = 1;
if (firstToken != NULL) {
prelval.token = firstToken;
firstToken = NULL;
} else {
prelval.token = getExpandToken(
((expandNextToken && expandThisLine) ? EXP_OP_EXPAND : 0) |
EXP_OP_EMIT_EOL |
(expandThisLineHideErrors ? EXP_OP_HIDE_ERRORS : 0),
&successfulExpand);
}
if (!successfulExpand) {
expandThisLineHideErrors = 0;
retval = 0;
} else {
retval = prelval.token->data->code;
}
expandNextToken = 1;
if (retval == Y_PRE_NEWLINE) {
expandThisLine = 1;
expandThisLineHideErrors = 0;
zapToken(prelval.token);
}
return retval;
}
static void *_dupTokenKeepPos(void *_tok) {
pToken tok = _tok;
return dupToken(tok, NULL);
}
pCTree createDefineMacroCTree(void) {
pCTree tree;
pSLList list;
pToken tempTok;
pToken idToken;
pSymTabEntry newSymbol;
int assertVal;
/* Read tokens until end-of-line */
expandThisLine = 0;
if (prechar != Y_PRE_NEWLINE) {
while (prelex() != Y_PRE_NEWLINE);
if (g_opt.targetLang == TLT_FORTRAN) {
reportError(CERR_PREDIR_NOT_SUPPORTED, "#define");
}
}
rewindCurrSLListPos(g_currLineCode);
incCurrSLListPos(g_currLineCode); /* Skip #define */
assertVal = getCurrSLListPosElem(g_currLineCode, &idToken);
assert(assertVal);
incCurrSLListPos(g_currLineCode); /* Skip id */
list = createSLList();
for (;;) {
if (!getCurrSLListPosElem(g_currLineCode, &tempTok)) {
break;
}
addSLListElem(list, tempTok);
incCurrSLListPos(g_currLineCode);
}
tree = createCTree2(
createConstr1Label(LABCT_PRE_DEFINE_MACRO, _lastDefineTok),
createCTreeRoot(createTokenLabel(idToken)),
createCTreeRoot(createListLabel(list))
);
newSymbol = createTabEntry(getTokenIdName(idToken), SYMT_MACRO,
dupSLList(list, _dupTokenKeepPos));
addSymbol(newSymbol);
return tree;
}
pCTree eatPreDirList(pToken tok) {
pSLList list;
list = createSLList();
prechar = prelex();
while (prechar != Y_PRE_NEWLINE) {
addSLListElem(list, prelval.token);
prechar = prelex();
}
return createCTree1(
createConstr1Label(LABCT_PRE_DIR_LIST, tok),
createCTreeRoot(createListLabel(list))
);
}
#define preclearin prechar = -1
// We have to copy yacc def'n of preclearin since
// yacc puts recoverError() function before it declares
// 'preclearin'. If yacc's def'n ever changes,
// we will get a redefinition error.
#define CLEARIN preclearin
static void recoverError(void) {
pToken tok;
pSLList context = createSLList();
int recordMaxTok = 15;
char *s1;
for (tok = prelval.token;
prechar == Y_PRE_NEWLINE ? 0 : (tok->data->code != Y_EOF) ;
prechar = prelex(), tok = prelval.token)
{
if (recordMaxTok-- > 0) {
addSLListElem(context, tok);
}
}
s1 = getTokListString(context);
reportError(RERR_CPARSE_WITH_CONTEXT, s1, "");
zapSLList(context, zapToken);
CLEARIN;
firstToken = tok;
}
static short predef[] = {
135, 135, -1, 191, 195, 196, 197, 198, 199, 200,
201, 202, 203, 204, 205, -5, 27, 194, 193, 135,
18, 17, 16, 15, 14, 13, 12, 11, 10, 9,
8, 7, 6, 5, 4, 206, 33, -9, 32, 31,
30, 29, 23, 22, 21, 20, 35, 34, 37, 190,
-13, 26, -17, 19, -21, 28, 31, 30, 29, 25,
192, 108, -25
};
static short preex[] = {
0, 0, -1, 1, 309, 3, -1, 1, 309, 36,
-1, 1, 309, 36, -1, 1, 387, 24, -1, 1,
309, 36, -1, 1, 309, 36, -1, 1
};
static short preact[] = {
-269, -141, -255, -252, -145, -142, -143, -258, -144, -2,
-1, -146, -257, -259, -246, 514, 513, 512, 511, 510,
509, 508, 507, 506, 505, 504, 503, 502, 501, 256,
-248, -149, 389, 256, -254, -253, 391, 390, -230, -233,
-134, -234, -232, -231, -136, -229, -149, -178, -181, -133,
396, 393, 390, 389, 388, 375, 316, 312, 310, 308,
305, 301, -247, 502, -130, 389, -129, 389, -249, -230,
-233, -134, -234, -232, -231, -136, -229, -149, -178, -181,
-133, -250, 515, 396, 393, 390, 389, 388, 375, 316,
312, 310, 308, 305, 301, 256, -178, 390, -127, -126,
386, 337, -125, 306, -124, 384, -123, 340, -122, 305,
-121, -120, 332, 302, -116, -117, -118, -119, 334, 333,
330, 327, -115, -114, 335, 328, -112, -113, 316, 312,
-109, -110, -111, 394, 322, 310, -230, -233, -108, -234,
-232, -231, -136, -229, -149, -178, -181, -133, 396, 393,
390, 389, 388, 375, 316, 312, 310, 308, 305, 301,
-16, -107, -106, -105, 338, 320, 319, 308, -230, -233,
-134, -234, -232, -231, -216, -210, -184, -205, -104, -214,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?