📄 parser.c
字号:
#include <string.h>#include <ctype.h>#include "sip.h"#define MAX_NESTED_IF 10#define MAX_NESTED_SCOPE 10#define inMainModule() (currentSpec -> module == currentModule)static sipSpec *currentSpec; /* The current spec being parsed. */static stringList *neededQualifiers; /* The list of required qualifiers. */static stringList *excludedQualifiers; /* The list of excluded qualifiers. */static moduleDef *currentModule; /* The current module being parsed. */static mappedTypeDef *currentMappedType; /* The current mapped type. */static enumDef *currentEnum; /* The current enum being parsed. */static int sectionFlags; /* The current section flags. */static int currentOverIsVirt; /* Set if the overload is virtual. */static int currentCtorIsExplicit; /* Set if the ctor is explicit. */static int currentIsStatic; /* Set if the current is static. */static char *previousFile; /* The file just parsed. */static parserContext newContext; /* The new pending context. */static int skipStackPtr; /* The skip stack pointer. */static int skipStack[MAX_NESTED_IF]; /* Stack of skip flags. */static classDef *scopeStack[MAX_NESTED_SCOPE]; /* The scope stack. */static int sectFlagsStack[MAX_NESTED_SCOPE]; /* The section flags stack. */static int currentScopeIdx; /* The scope stack index. */static int currentTimelineOrder; /* The current timeline order. */static char *getPythonName(optFlags *optflgs, char *cname);static nameDef *cacheName(sipSpec *,char *);static classDef *findClass(sipSpec *,ifaceFileType,scopedNameDef *);static classDef *findClassWithInterface(sipSpec *pt, ifaceFileDef *iff);static classDef *newClass(sipSpec *,ifaceFileType,scopedNameDef *);static void finishClass(sipSpec *,moduleDef *,classDef *,optFlags *);static exceptionDef *findException(sipSpec *pt, scopedNameDef *fqname, int new);static mappedTypeDef *newMappedType(sipSpec *,argDef *);static enumDef *newEnum(sipSpec *,moduleDef *,char *,optFlags *,int);static void instantiateClassTemplate(sipSpec *pt, moduleDef *mod, classDef *scope, scopedNameDef *fqname, classTmplDef *tcd, templateDef *td);static void newTypedef(sipSpec *,moduleDef *,char *,argDef *);static void newVar(sipSpec *,moduleDef *,char *,int,argDef *,optFlags *, codeBlock *,codeBlock *,codeBlock *);static void newCtor(char *,int,signatureDef *,optFlags *,codeBlock *, throwArgs *,signatureDef *,int);static void newFunction(sipSpec *,moduleDef *,int,int,int,char *, signatureDef *,int,int,optFlags *,codeBlock *, codeBlock *,throwArgs *,signatureDef *);static optFlag *findOptFlag(optFlags *,char *,flagType);static memberDef *findFunction(sipSpec *,moduleDef *,classDef *,nameDef *,int, int);static void checkAttributes(sipSpec *,classDef *,char *,int);static void newModule(FILE *,char *);static void appendCodeBlock(codeBlock **,codeBlock *);static void parseFile(FILE *,char *,moduleDef *,int);static void handleEOF(void);static void handleEOM(void);static qualDef *findQualifier(char *);static scopedNameDef *text2scopedName(char *);static scopedNameDef *scopeScopedName(scopedNameDef *name);static void pushScope(classDef *);static void popScope(void);static classDef *currentScope(void);static void newQualifier(moduleDef *,int,int,char *,qualType);static void newImport(char *);static void usedInMainModule(sipSpec *,ifaceFileDef *);static int timePeriod(char *,char *);static int platOrFeature(char *,int);static int isNeeded(qualDef *);static int notSkipping(void);static void getHooks(optFlags *,char **,char **);static int getReleaseGIL(optFlags *);static void templateSignature(signatureDef *sd, int result, classTmplDef *tcd, templateDef *td, classDef *ncd);static void templateType(argDef *ad, classTmplDef *tcd, templateDef *td, classDef *ncd);static int search_back(const char *end, const char *start, const char *target);static char *getType(scopedNameDef *ename, argDef *ad);static char *scopedNameToString(scopedNameDef *name);static void addUsedFromCode(sipSpec *pt, ifaceFileList **used, const char *sname);static int sameName(scopedNameDef *snd, const char *sname);/* Enabling traces. */#ifndef YYDEBUG# define YYDEBUG 0#endif/* Enabling verbose error messages. */#ifdef YYERROR_VERBOSE# undef YYERROR_VERBOSE# define YYERROR_VERBOSE 1#else# define YYERROR_VERBOSE 0#endif#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)#line 101 "parser.y"typedef union YYSTYPE { char qchar; char *text; long number; double real; argDef memArg; signatureDef signature; signatureDef *optsignature; throwArgs *throwlist; codeBlock *codeb; valueDef value; valueDef *valp; optFlags optflags; optFlag flag; scopedNameDef *scpvalp; fcallDef fcall; int boolean; exceptionDef exceptionbase; classDef *klass;} YYSTYPE;/* Line 191 of yacc.c. */#line 376 "parser.c"# define yystype YYSTYPE /* obsolescent; will be withdrawn */# define YYSTYPE_IS_DECLARED 1# define YYSTYPE_IS_TRIVIAL 1#endif/* Copy the second part of user declarations. *//* Line 214 of yacc.c. */#line 388 "parser.c"#if ! defined (yyoverflow) || YYERROR_VERBOSE# ifndef YYFREE# define YYFREE free# endif# ifndef YYMALLOC# define YYMALLOC malloc# endif/* The parser invokes alloca or malloc; define the necessary symbols. */# ifdef YYSTACK_USE_ALLOCA# if YYSTACK_USE_ALLOCA# define YYSTACK_ALLOC alloca# endif# else# if defined (alloca) || defined (_ALLOCA_H)# define YYSTACK_ALLOC alloca# else# ifdef __GNUC__# define YYSTACK_ALLOC __builtin_alloca# endif# endif# endif# ifdef YYSTACK_ALLOC /* Pacify GCC's `empty if-body' warning. */# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)# else# if defined (__STDC__) || defined (__cplusplus)# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */# define YYSIZE_T size_t# endif# define YYSTACK_ALLOC YYMALLOC# define YYSTACK_FREE YYFREE# endif#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */#if (! defined (yyoverflow) \ && (! defined (__cplusplus) \ || (defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))/* A type that is properly aligned for any stack member. */union yyalloc{ short int yyss; YYSTYPE yyvs; };/* The size of the maximum gap between one aligned stack and the next. */# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)/* The size of an array large to enough to hold all stacks, each with N elements. */# define YYSTACK_BYTES(N) \ ((N) * (sizeof (short int) + sizeof (YYSTYPE)) \ + YYSTACK_GAP_MAXIMUM)/* Copy COUNT objects from FROM to TO. The source and destination do not overlap. */# ifndef YYCOPY# if defined (__GNUC__) && 1 < __GNUC__# define YYCOPY(To, From, Count) \ __builtin_memcpy (To, From, (Count) * sizeof (*(From)))# else# define YYCOPY(To, From, Count) \ do \ { \ register YYSIZE_T yyi; \ for (yyi = 0; yyi < (Count); yyi++) \ (To)[yyi] = (From)[yyi]; \ } \ while (0)# endif# endif/* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of elements in the stack, and YYPTR gives the new location of the stack. Advance YYPTR to a properly aligned location for the next stack. */# define YYSTACK_RELOCATE(Stack) \ do \ { \ YYSIZE_T yynewbytes; \ YYCOPY (&yyptr->Stack, Stack, yysize); \ Stack = &yyptr->Stack; \ yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ yyptr += yynewbytes / sizeof (*yyptr); \ } \ while (0)#endif#if defined (__STDC__) || defined (__cplusplus) typedef signed char yysigned_char;#else typedef short int yysigned_char;#endif/* YYFINAL -- State number of the termination state. */#define YYFINAL 4/* YYLAST -- Last index in YYTABLE. */#define YYLAST 1047/* YYNTOKENS -- Number of terminals. */#define YYNTOKENS 120/* YYNNTS -- Number of nonterminals. */#define YYNNTS 130/* YYNRULES -- Number of rules. */#define YYNRULES 330/* YYNRULES -- Number of states. */#define YYNSTATES 546/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */#define YYUNDEFTOK 2#define YYMAXUTOK 352#define YYTRANSLATE(YYX) \ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -