/Source/CParse/parser.y
Happy | 6160 lines | 5664 code | 496 blank | 0 comment | 0 complexity | 5047041a5413e359e0c7cf3902b63bb0 MD5 | raw file
Possible License(s): 0BSD, GPL-2.0, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- /* -----------------------------------------------------------------------------
- * See the LICENSE file for information on copyright, usage and redistribution
- * of SWIG, and the README file for authors - http://www.swig.org/release.html.
- *
- * parser.y
- *
- * YACC parser for SWIG. The grammar is a somewhat broken subset of C/C++.
- * This file is a bit of a mess and probably needs to be rewritten at
- * some point. Beware.
- * ----------------------------------------------------------------------------- */
- %{
- #define yylex yylex
- char cvsroot_parser_y[] = "$Id$";
- #include "swig.h"
- #include "cparse.h"
- #include "preprocessor.h"
- #include <ctype.h>
- /* We do this for portability */
- #undef alloca
- #define alloca malloc
- /* -----------------------------------------------------------------------------
- * Externals
- * ----------------------------------------------------------------------------- */
- int yyparse();
- /* NEW Variables */
- static Node *top = 0; /* Top of the generated parse tree */
- static int unnamed = 0; /* Unnamed datatype counter */
- static Hash *extendhash = 0; /* Hash table of added methods */
- static Hash *classes = 0; /* Hash table of classes */
- static Symtab *prev_symtab = 0;
- static Node *current_class = 0;
- String *ModuleName = 0;
- static Node *module_node = 0;
- static String *Classprefix = 0;
- static String *Namespaceprefix = 0;
- static int inclass = 0;
- static int nested_template = 0; /* template class/function definition within a class */
- static char *last_cpptype = 0;
- static int inherit_list = 0;
- static Parm *template_parameters = 0;
- static int extendmode = 0;
- static int compact_default_args = 0;
- static int template_reduce = 0;
- static int cparse_externc = 0;
- static int max_class_levels = 0;
- static int class_level = 0;
- static Node **class_decl = NULL;
- /* -----------------------------------------------------------------------------
- * Assist Functions
- * ----------------------------------------------------------------------------- */
-
- /* Called by the parser (yyparse) when an error is found.*/
- static void yyerror (const char *e) {
- (void)e;
- }
- static Node *new_node(const_String_or_char_ptr tag) {
- Node *n = NewHash();
- set_nodeType(n,tag);
- Setfile(n,cparse_file);
- Setline(n,cparse_line);
- return n;
- }
- /* Copies a node. Does not copy tree links or symbol table data (except for
- sym:name) */
- static Node *copy_node(Node *n) {
- Node *nn;
- Iterator k;
- nn = NewHash();
- Setfile(nn,Getfile(n));
- Setline(nn,Getline(n));
- for (k = First(n); k.key; k = Next(k)) {
- String *ci;
- String *key = k.key;
- char *ckey = Char(key);
- if ((strcmp(ckey,"nextSibling") == 0) ||
- (strcmp(ckey,"previousSibling") == 0) ||
- (strcmp(ckey,"parentNode") == 0) ||
- (strcmp(ckey,"lastChild") == 0)) {
- continue;
- }
- if (Strncmp(key,"csym:",5) == 0) continue;
- /* We do copy sym:name. For templates */
- if ((strcmp(ckey,"sym:name") == 0) ||
- (strcmp(ckey,"sym:weak") == 0) ||
- (strcmp(ckey,"sym:typename") == 0)) {
- String *ci = Copy(k.item);
- Setattr(nn,key, ci);
- Delete(ci);
- continue;
- }
- if (strcmp(ckey,"sym:symtab") == 0) {
- Setattr(nn,"sym:needs_symtab", "1");
- }
- /* We don't copy any other symbol table attributes */
- if (strncmp(ckey,"sym:",4) == 0) {
- continue;
- }
- /* If children. We copy them recursively using this function */
- if (strcmp(ckey,"firstChild") == 0) {
- /* Copy children */
- Node *cn = k.item;
- while (cn) {
- Node *copy = copy_node(cn);
- appendChild(nn,copy);
- Delete(copy);
- cn = nextSibling(cn);
- }
- continue;
- }
- /* We don't copy the symbol table. But we drop an attribute
- requires_symtab so that functions know it needs to be built */
- if (strcmp(ckey,"symtab") == 0) {
- /* Node defined a symbol table. */
- Setattr(nn,"requires_symtab","1");
- continue;
- }
- /* Can't copy nodes */
- if (strcmp(ckey,"node") == 0) {
- continue;
- }
- if ((strcmp(ckey,"parms") == 0) || (strcmp(ckey,"pattern") == 0) || (strcmp(ckey,"throws") == 0)
- || (strcmp(ckey,"kwargs") == 0)) {
- ParmList *pl = CopyParmList(k.item);
- Setattr(nn,key,pl);
- Delete(pl);
- continue;
- }
- /* Looks okay. Just copy the data using Copy */
- ci = Copy(k.item);
- Setattr(nn, key, ci);
- Delete(ci);
- }
- return nn;
- }
- /* -----------------------------------------------------------------------------
- * Variables
- * ----------------------------------------------------------------------------- */
- static char *typemap_lang = 0; /* Current language setting */
- static int cplus_mode = 0;
- static String *class_rename = 0;
- /* C++ modes */
- #define CPLUS_PUBLIC 1
- #define CPLUS_PRIVATE 2
- #define CPLUS_PROTECTED 3
- /* include types */
- static int import_mode = 0;
- void SWIG_typemap_lang(const char *tm_lang) {
- typemap_lang = Swig_copy_string(tm_lang);
- }
- void SWIG_cparse_set_compact_default_args(int defargs) {
- compact_default_args = defargs;
- }
- int SWIG_cparse_template_reduce(int treduce) {
- template_reduce = treduce;
- return treduce;
- }
- /* -----------------------------------------------------------------------------
- * Assist functions
- * ----------------------------------------------------------------------------- */
- static int promote_type(int t) {
- if (t <= T_UCHAR || t == T_CHAR) return T_INT;
- return t;
- }
- /* Perform type-promotion for binary operators */
- static int promote(int t1, int t2) {
- t1 = promote_type(t1);
- t2 = promote_type(t2);
- return t1 > t2 ? t1 : t2;
- }
- static String *yyrename = 0;
- /* Forward renaming operator */
- static String *resolve_node_scope(String *cname);
- Hash *Swig_cparse_features(void) {
- static Hash *features_hash = 0;
- if (!features_hash) features_hash = NewHash();
- return features_hash;
- }
- static String *feature_identifier_fix(String *s) {
- if (SwigType_istemplate(s)) {
- String *tp, *ts, *ta, *tq;
- tp = SwigType_templateprefix(s);
- ts = SwigType_templatesuffix(s);
- ta = SwigType_templateargs(s);
- tq = Swig_symbol_type_qualify(ta,0);
- Append(tp,tq);
- Append(tp,ts);
- Delete(ts);
- Delete(ta);
- Delete(tq);
- return tp;
- } else {
- return NewString(s);
- }
- }
- /* Generate the symbol table name for an object */
- /* This is a bit of a mess. Need to clean up */
- static String *add_oldname = 0;
- static String *make_name(Node *n, String *name,SwigType *decl) {
- int destructor = name && (*(Char(name)) == '~');
- if (yyrename) {
- String *s = NewString(yyrename);
- Delete(yyrename);
- yyrename = 0;
- if (destructor && (*(Char(s)) != '~')) {
- Insert(s,0,"~");
- }
- return s;
- }
- if (!name) return 0;
- return Swig_name_make(n,Namespaceprefix,name,decl,add_oldname);
- }
- /* Generate an unnamed identifier */
- static String *make_unnamed() {
- unnamed++;
- return NewStringf("$unnamed%d$",unnamed);
- }
- /* Return if the node is a friend declaration */
- static int is_friend(Node *n) {
- return Cmp(Getattr(n,"storage"),"friend") == 0;
- }
- static int is_operator(String *name) {
- return Strncmp(name,"operator ", 9) == 0;
- }
- /* Add declaration list to symbol table */
- static int add_only_one = 0;
- static void add_symbols(Node *n) {
- String *decl;
- String *wrn = 0;
- if (nested_template) {
- if (!(n && Equal(nodeType(n), "template"))) {
- return;
- }
- /* continue if template function, but not template class, declared within a class */
- }
- if (inclass && n) {
- cparse_normalize_void(n);
- }
- while (n) {
- String *symname = 0;
- /* for friends, we need to pop the scope once */
- String *old_prefix = 0;
- Symtab *old_scope = 0;
- int isfriend = inclass && is_friend(n);
- int iscdecl = Cmp(nodeType(n),"cdecl") == 0;
- int only_csymbol = 0;
- if (extendmode) {
- Setattr(n,"isextension","1");
- }
-
- if (inclass) {
- String *name = Getattr(n, "name");
- if (isfriend) {
- /* for friends, we need to add the scopename if needed */
- String *prefix = name ? Swig_scopename_prefix(name) : 0;
- old_prefix = Namespaceprefix;
- old_scope = Swig_symbol_popscope();
- Namespaceprefix = Swig_symbol_qualifiedscopename(0);
- if (!prefix) {
- if (name && !is_operator(name) && Namespaceprefix) {
- String *nname = NewStringf("%s::%s", Namespaceprefix, name);
- Setattr(n,"name",nname);
- Delete(nname);
- }
- } else {
- Symtab *st = Swig_symbol_getscope(prefix);
- String *ns = st ? Getattr(st,"name") : prefix;
- String *base = Swig_scopename_last(name);
- String *nname = NewStringf("%s::%s", ns, base);
- Setattr(n,"name",nname);
- Delete(nname);
- Delete(base);
- Delete(prefix);
- }
- Namespaceprefix = 0;
- } else {
- /* for member functions, we need to remove the redundant
- class scope if provided, as in
-
- struct Foo {
- int Foo::method(int a);
- };
-
- */
- String *prefix = name ? Swig_scopename_prefix(name) : 0;
- if (prefix) {
- if (Classprefix && (Equal(prefix,Classprefix))) {
- String *base = Swig_scopename_last(name);
- Setattr(n,"name",base);
- Delete(base);
- }
- Delete(prefix);
- }
- /*
- if (!Getattr(n,"parentNode") && class_level) set_parentNode(n,class_decl[class_level - 1]);
- */
- Setattr(n,"ismember","1");
- }
- }
- if (!isfriend && inclass) {
- if ((cplus_mode != CPLUS_PUBLIC)) {
- only_csymbol = 1;
- if (cplus_mode == CPLUS_PROTECTED) {
- Setattr(n,"access", "protected");
- only_csymbol = !Swig_need_protected(n);
- } else {
- Setattr(n,"access", "private");
- /* private are needed only when they are pure virtuals - why? */
- if ((Cmp(Getattr(n,"storage"),"virtual") == 0) && (Cmp(Getattr(n,"value"),"0") == 0)) {
- only_csymbol = 0;
- }
- }
- } else {
- Setattr(n,"access", "public");
- }
- }
- if (Getattr(n,"sym:name")) {
- n = nextSibling(n);
- continue;
- }
- decl = Getattr(n,"decl");
- if (!SwigType_isfunction(decl)) {
- String *name = Getattr(n,"name");
- String *makename = Getattr(n,"parser:makename");
- if (iscdecl) {
- String *storage = Getattr(n, "storage");
- if (Cmp(storage,"typedef") == 0) {
- Setattr(n,"kind","typedef");
- } else {
- SwigType *type = Getattr(n,"type");
- String *value = Getattr(n,"value");
- Setattr(n,"kind","variable");
- if (value && Len(value)) {
- Setattr(n,"hasvalue","1");
- }
- if (type) {
- SwigType *ty;
- SwigType *tmp = 0;
- if (decl) {
- ty = tmp = Copy(type);
- SwigType_push(ty,decl);
- } else {
- ty = type;
- }
- if (!SwigType_ismutable(ty)) {
- SetFlag(n,"hasconsttype");
- SetFlag(n,"feature:immutable");
- }
- if (tmp) Delete(tmp);
- }
- if (!type) {
- Printf(stderr,"notype name %s\n", name);
- }
- }
- }
- Swig_features_get(Swig_cparse_features(), Namespaceprefix, name, 0, n);
- if (makename) {
- symname = make_name(n, makename,0);
- Delattr(n,"parser:makename"); /* temporary information, don't leave it hanging around */
- } else {
- makename = name;
- symname = make_name(n, makename,0);
- }
-
- if (!symname) {
- symname = Copy(Getattr(n,"unnamed"));
- }
- if (symname) {
- wrn = Swig_name_warning(n, Namespaceprefix, symname,0);
- }
- } else {
- String *name = Getattr(n,"name");
- SwigType *fdecl = Copy(decl);
- SwigType *fun = SwigType_pop_function(fdecl);
- if (iscdecl) {
- Setattr(n,"kind","function");
- }
-
- Swig_features_get(Swig_cparse_features(),Namespaceprefix,name,fun,n);
- symname = make_name(n, name,fun);
- wrn = Swig_name_warning(n, Namespaceprefix,symname,fun);
-
- Delete(fdecl);
- Delete(fun);
-
- }
- if (!symname) {
- n = nextSibling(n);
- continue;
- }
- if (only_csymbol || GetFlag(n,"feature:ignore")) {
- /* Only add to C symbol table and continue */
- Swig_symbol_add(0, n);
- } else if (strncmp(Char(symname),"$ignore",7) == 0) {
- char *c = Char(symname)+7;
- SetFlag(n,"feature:ignore");
- if (strlen(c)) {
- SWIG_WARN_NODE_BEGIN(n);
- Swig_warning(0,Getfile(n), Getline(n), "%s\n",c+1);
- SWIG_WARN_NODE_END(n);
- }
- Swig_symbol_add(0, n);
- } else {
- Node *c;
- if ((wrn) && (Len(wrn))) {
- String *metaname = symname;
- if (!Getmeta(metaname,"already_warned")) {
- SWIG_WARN_NODE_BEGIN(n);
- Swig_warning(0,Getfile(n),Getline(n), "%s\n", wrn);
- SWIG_WARN_NODE_END(n);
- Setmeta(metaname,"already_warned","1");
- }
- }
- c = Swig_symbol_add(symname,n);
- if (c != n) {
- /* symbol conflict attempting to add in the new symbol */
- if (Getattr(n,"sym:weak")) {
- Setattr(n,"sym:name",symname);
- } else {
- String *e = NewStringEmpty();
- String *en = NewStringEmpty();
- String *ec = NewStringEmpty();
- int redefined = Swig_need_redefined_warn(n,c,inclass);
- if (redefined) {
- Printf(en,"Identifier '%s' redefined (ignored)",symname);
- Printf(ec,"previous definition of '%s'",symname);
- } else {
- Printf(en,"Redundant redeclaration of '%s'",symname);
- Printf(ec,"previous declaration of '%s'",symname);
- }
- if (Cmp(symname,Getattr(n,"name"))) {
- Printf(en," (Renamed from '%s')", SwigType_namestr(Getattr(n,"name")));
- }
- Printf(en,",");
- if (Cmp(symname,Getattr(c,"name"))) {
- Printf(ec," (Renamed from '%s')", SwigType_namestr(Getattr(c,"name")));
- }
- Printf(ec,".");
- SWIG_WARN_NODE_BEGIN(n);
- if (redefined) {
- Swig_warning(WARN_PARSE_REDEFINED,Getfile(n),Getline(n),"%s\n",en);
- Swig_warning(WARN_PARSE_REDEFINED,Getfile(c),Getline(c),"%s\n",ec);
- } else if (!is_friend(n) && !is_friend(c)) {
- Swig_warning(WARN_PARSE_REDUNDANT,Getfile(n),Getline(n),"%s\n",en);
- Swig_warning(WARN_PARSE_REDUNDANT,Getfile(c),Getline(c),"%s\n",ec);
- }
- SWIG_WARN_NODE_END(n);
- Printf(e,"%s:%d:%s\n%s:%d:%s\n",Getfile(n),Getline(n),en,
- Getfile(c),Getline(c),ec);
- Setattr(n,"error",e);
- Delete(e);
- Delete(en);
- Delete(ec);
- }
- }
- }
- /* restore the class scope if needed */
- if (isfriend) {
- Swig_symbol_setscope(old_scope);
- if (old_prefix) {
- Delete(Namespaceprefix);
- Namespaceprefix = old_prefix;
- }
- }
- Delete(symname);
- if (add_only_one) return;
- n = nextSibling(n);
- }
- }
- /* add symbols a parse tree node copy */
- static void add_symbols_copy(Node *n) {
- String *name;
- int emode = 0;
- while (n) {
- char *cnodeType = Char(nodeType(n));
- if (strcmp(cnodeType,"access") == 0) {
- String *kind = Getattr(n,"kind");
- if (Strcmp(kind,"public") == 0) {
- cplus_mode = CPLUS_PUBLIC;
- } else if (Strcmp(kind,"private") == 0) {
- cplus_mode = CPLUS_PRIVATE;
- } else if (Strcmp(kind,"protected") == 0) {
- cplus_mode = CPLUS_PROTECTED;
- }
- n = nextSibling(n);
- continue;
- }
- add_oldname = Getattr(n,"sym:name");
- if ((add_oldname) || (Getattr(n,"sym:needs_symtab"))) {
- int old_inclass = -1;
- Node *old_current_class = 0;
- if (add_oldname) {
- DohIncref(add_oldname);
- /* Disable this, it prevents %rename to work with templates */
- /* If already renamed, we used that name */
- /*
- if (Strcmp(add_oldname, Getattr(n,"name")) != 0) {
- Delete(yyrename);
- yyrename = Copy(add_oldname);
- }
- */
- }
- Delattr(n,"sym:needs_symtab");
- Delattr(n,"sym:name");
- add_only_one = 1;
- add_symbols(n);
- if (Getattr(n,"partialargs")) {
- Swig_symbol_cadd(Getattr(n,"partialargs"),n);
- }
- add_only_one = 0;
- name = Getattr(n,"name");
- if (Getattr(n,"requires_symtab")) {
- Swig_symbol_newscope();
- Swig_symbol_setscopename(name);
- Delete(Namespaceprefix);
- Namespaceprefix = Swig_symbol_qualifiedscopename(0);
- }
- if (strcmp(cnodeType,"class") == 0) {
- old_inclass = inclass;
- inclass = 1;
- old_current_class = current_class;
- current_class = n;
- if (Strcmp(Getattr(n,"kind"),"class") == 0) {
- cplus_mode = CPLUS_PRIVATE;
- } else {
- cplus_mode = CPLUS_PUBLIC;
- }
- }
- if (strcmp(cnodeType,"extend") == 0) {
- emode = cplus_mode;
- cplus_mode = CPLUS_PUBLIC;
- }
- add_symbols_copy(firstChild(n));
- if (strcmp(cnodeType,"extend") == 0) {
- cplus_mode = emode;
- }
- if (Getattr(n,"requires_symtab")) {
- Setattr(n,"symtab", Swig_symbol_popscope());
- Delattr(n,"requires_symtab");
- Delete(Namespaceprefix);
- Namespaceprefix = Swig_symbol_qualifiedscopename(0);
- }
- if (add_oldname) {
- Delete(add_oldname);
- add_oldname = 0;
- }
- if (strcmp(cnodeType,"class") == 0) {
- inclass = old_inclass;
- current_class = old_current_class;
- }
- } else {
- if (strcmp(cnodeType,"extend") == 0) {
- emode = cplus_mode;
- cplus_mode = CPLUS_PUBLIC;
- }
- add_symbols_copy(firstChild(n));
- if (strcmp(cnodeType,"extend") == 0) {
- cplus_mode = emode;
- }
- }
- n = nextSibling(n);
- }
- }
- /* Extension merge. This function is used to handle the %extend directive
- when it appears before a class definition. To handle this, the %extend
- actually needs to take precedence. Therefore, we will selectively nuke symbols
- from the current symbol table, replacing them with the added methods */
- static void merge_extensions(Node *cls, Node *am) {
- Node *n;
- Node *csym;
- n = firstChild(am);
- while (n) {
- String *symname;
- if (Strcmp(nodeType(n),"constructor") == 0) {
- symname = Getattr(n,"sym:name");
- if (symname) {
- if (Strcmp(symname,Getattr(n,"name")) == 0) {
- /* If the name and the sym:name of a constructor are the same,
- then it hasn't been renamed. However---the name of the class
- itself might have been renamed so we need to do a consistency
- check here */
- if (Getattr(cls,"sym:name")) {
- Setattr(n,"sym:name", Getattr(cls,"sym:name"));
- }
- }
- }
- }
- symname = Getattr(n,"sym:name");
- DohIncref(symname);
- if ((symname) && (!Getattr(n,"error"))) {
- /* Remove node from its symbol table */
- Swig_symbol_remove(n);
- csym = Swig_symbol_add(symname,n);
- if (csym != n) {
- /* Conflict with previous definition. Nuke previous definition */
- String *e = NewStringEmpty();
- String *en = NewStringEmpty();
- String *ec = NewStringEmpty();
- Printf(ec,"Identifier '%s' redefined by %%extend (ignored),",symname);
- Printf(en,"%%extend definition of '%s'.",symname);
- SWIG_WARN_NODE_BEGIN(n);
- Swig_warning(WARN_PARSE_REDEFINED,Getfile(csym),Getline(csym),"%s\n",ec);
- Swig_warning(WARN_PARSE_REDEFINED,Getfile(n),Getline(n),"%s\n",en);
- SWIG_WARN_NODE_END(n);
- Printf(e,"%s:%d:%s\n%s:%d:%s\n",Getfile(csym),Getline(csym),ec,
- Getfile(n),Getline(n),en);
- Setattr(csym,"error",e);
- Delete(e);
- Delete(en);
- Delete(ec);
- Swig_symbol_remove(csym); /* Remove class definition */
- Swig_symbol_add(symname,n); /* Insert extend definition */
- }
- }
- n = nextSibling(n);
- }
- }
- static void append_previous_extension(Node *cls, Node *am) {
- Node *n, *ne;
- Node *pe = 0;
- Node *ae = 0;
- if (!am) return;
-
- n = firstChild(am);
- while (n) {
- ne = nextSibling(n);
- set_nextSibling(n,0);
- /* typemaps and fragments need to be prepended */
- if (((Cmp(nodeType(n),"typemap") == 0) || (Cmp(nodeType(n),"fragment") == 0))) {
- if (!pe) pe = new_node("extend");
- appendChild(pe, n);
- } else {
- if (!ae) ae = new_node("extend");
- appendChild(ae, n);
- }
- n = ne;
- }
- if (pe) prependChild(cls,pe);
- if (ae) appendChild(cls,ae);
- }
-
- /* Check for unused %extend. Special case, don't report unused
- extensions for templates */
-
- static void check_extensions() {
- Iterator ki;
- if (!extendhash) return;
- for (ki = First(extendhash); ki.key; ki = Next(ki)) {
- if (!Strchr(ki.key,'<')) {
- SWIG_WARN_NODE_BEGIN(ki.item);
- Swig_warning(WARN_PARSE_EXTEND_UNDEF,Getfile(ki.item), Getline(ki.item), "%%extend defined for an undeclared class %s.\n", ki.key);
- SWIG_WARN_NODE_END(ki.item);
- }
- }
- }
- /* Check a set of declarations to see if any are pure-abstract */
- static List *pure_abstract(Node *n) {
- List *abs = 0;
- while (n) {
- if (Cmp(nodeType(n),"cdecl") == 0) {
- String *decl = Getattr(n,"decl");
- if (SwigType_isfunction(decl)) {
- String *init = Getattr(n,"value");
- if (Cmp(init,"0") == 0) {
- if (!abs) {
- abs = NewList();
- }
- Append(abs,n);
- Setattr(n,"abstract","1");
- }
- }
- } else if (Cmp(nodeType(n),"destructor") == 0) {
- if (Cmp(Getattr(n,"value"),"0") == 0) {
- if (!abs) {
- abs = NewList();
- }
- Append(abs,n);
- Setattr(n,"abstract","1");
- }
- }
- n = nextSibling(n);
- }
- return abs;
- }
- /* Make a classname */
- static String *make_class_name(String *name) {
- String *nname = 0;
- if (Namespaceprefix) {
- nname= NewStringf("%s::%s", Namespaceprefix, name);
- } else {
- nname = NewString(name);
- }
- if (SwigType_istemplate(nname)) {
- String *prefix, *args, *qargs;
- prefix = SwigType_templateprefix(nname);
- args = SwigType_templateargs(nname);
- qargs = Swig_symbol_type_qualify(args,0);
- Append(prefix,qargs);
- Delete(nname);
- Delete(args);
- Delete(qargs);
- nname = prefix;
- }
- return nname;
- }
- static List *make_inherit_list(String *clsname, List *names) {
- int i, ilen;
- String *derived;
- List *bases = NewList();
- if (Namespaceprefix) derived = NewStringf("%s::%s", Namespaceprefix,clsname);
- else derived = NewString(clsname);
- ilen = Len(names);
- for (i = 0; i < ilen; i++) {
- Node *s;
- String *base;
- String *n = Getitem(names,i);
- /* Try to figure out where this symbol is */
- s = Swig_symbol_clookup(n,0);
- if (s) {
- while (s && (Strcmp(nodeType(s),"class") != 0)) {
- /* Not a class. Could be a typedef though. */
- String *storage = Getattr(s,"storage");
- if (storage && (Strcmp(storage,"typedef") == 0)) {
- String *nn = Getattr(s,"type");
- s = Swig_symbol_clookup(nn,Getattr(s,"sym:symtab"));
- } else {
- break;
- }
- }
- if (s && ((Strcmp(nodeType(s),"class") == 0) || (Strcmp(nodeType(s),"template") == 0))) {
- String *q = Swig_symbol_qualified(s);
- Append(bases,s);
- if (q) {
- base = NewStringf("%s::%s", q, Getattr(s,"name"));
- Delete(q);
- } else {
- base = NewString(Getattr(s,"name"));
- }
- } else {
- base = NewString(n);
- }
- } else {
- base = NewString(n);
- }
- if (base) {
- Swig_name_inherit(base,derived);
- Delete(base);
- }
- }
- return bases;
- }
- /* If the class name is qualified. We need to create or lookup namespace entries */
- static Symtab *set_scope_to_global() {
- Symtab *symtab = Swig_symbol_global_scope();
- Swig_symbol_setscope(symtab);
- return symtab;
- }
-
- /* Remove the block braces, { and }, if the 'noblock' attribute is set.
- * Node *kw can be either a Hash or Parmlist. */
- static String *remove_block(Node *kw, const String *inputcode) {
- String *modified_code = 0;
- while (kw) {
- String *name = Getattr(kw,"name");
- if (name && (Cmp(name,"noblock") == 0)) {
- char *cstr = Char(inputcode);
- size_t len = Len(inputcode);
- if (len && cstr[0] == '{') {
- --len; ++cstr;
- if (len && cstr[len - 1] == '}') { --len; }
- /* we now remove the extra spaces */
- while (len && isspace((int)cstr[0])) { --len; ++cstr; }
- while (len && isspace((int)cstr[len - 1])) { --len; }
- modified_code = NewStringWithSize(cstr, len);
- break;
- }
- }
- kw = nextSibling(kw);
- }
- return modified_code;
- }
- static Node *nscope = 0;
- static Node *nscope_inner = 0;
- /* Remove the scope prefix from cname and return the base name without the prefix.
- * The scopes specified in the prefix are found, or created in the current namespace.
- * So ultimately the scope is changed to that required for the base name.
- * For example AA::BB::CC as input returns CC and creates the namespace AA then inner
- * namespace BB in the current scope. If no scope separator (::) in the input, then nothing happens! */
- static String *resolve_node_scope(String *cname) {
- Symtab *gscope = 0;
- nscope = 0;
- nscope_inner = 0;
- if (Swig_scopename_check(cname)) {
- Node *ns;
- String *prefix = Swig_scopename_prefix(cname);
- String *base = Swig_scopename_last(cname);
- if (prefix && (Strncmp(prefix,"::",2) == 0)) {
- /* Use the global scope */
- String *nprefix = NewString(Char(prefix)+2);
- Delete(prefix);
- prefix= nprefix;
- gscope = set_scope_to_global();
- }
- if (!prefix || (Len(prefix) == 0)) {
- /* Use the global scope, but we need to add a 'global' namespace. */
- if (!gscope) gscope = set_scope_to_global();
- /* note that this namespace is not the "unnamed" one,
- and we don't use Setattr(nscope,"name", ""),
- because the unnamed namespace is private */
- nscope = new_node("namespace");
- Setattr(nscope,"symtab", gscope);;
- nscope_inner = nscope;
- return base;
- }
- /* Try to locate the scope */
- ns = Swig_symbol_clookup(prefix,0);
- if (!ns) {
- Swig_error(cparse_file,cparse_line,"Undefined scope '%s'\n", prefix);
- } else {
- Symtab *nstab = Getattr(ns,"symtab");
- if (!nstab) {
- Swig_error(cparse_file,cparse_line,
- "'%s' is not defined as a valid scope.\n", prefix);
- ns = 0;
- } else {
- /* Check if the node scope is the current scope */
- String *tname = Swig_symbol_qualifiedscopename(0);
- String *nname = Swig_symbol_qualifiedscopename(nstab);
- if (tname && (Strcmp(tname,nname) == 0)) {
- ns = 0;
- cname = base;
- }
- Delete(tname);
- Delete(nname);
- }
- if (ns) {
- /* we will try to create a new node using the namespaces we
- can find in the scope name */
- List *scopes;
- String *sname;
- Iterator si;
- String *name = NewString(prefix);
- scopes = NewList();
- while (name) {
- String *base = Swig_scopename_last(name);
- String *tprefix = Swig_scopename_prefix(name);
- Insert(scopes,0,base);
- Delete(base);
- Delete(name);
- name = tprefix;
- }
- for (si = First(scopes); si.item; si = Next(si)) {
- Node *ns1,*ns2;
- sname = si.item;
- ns1 = Swig_symbol_clookup(sname,0);
- assert(ns1);
- if (Strcmp(nodeType(ns1),"namespace") == 0) {
- if (Getattr(ns1,"alias")) {
- ns1 = Getattr(ns1,"namespace");
- }
- } else {
- /* now this last part is a class */
- si = Next(si);
- ns1 = Swig_symbol_clookup(sname,0);
- /* or a nested class tree, which is unrolled here */
- for (; si.item; si = Next(si)) {
- if (si.item) {
- Printf(sname,"::%s",si.item);
- }
- }
- /* we get the 'inner' class */
- nscope_inner = Swig_symbol_clookup(sname,0);
- /* set the scope to the inner class */
- Swig_symbol_setscope(Getattr(nscope_inner,"symtab"));
- /* save the last namespace prefix */
- Delete(Namespaceprefix);
- Namespaceprefix = Swig_symbol_qualifiedscopename(0);
- /* and return the node name, including the inner class prefix */
- break;
- }
- /* here we just populate the namespace tree as usual */
- ns2 = new_node("namespace");
- Setattr(ns2,"name",sname);
- Setattr(ns2,"symtab", Getattr(ns1,"symtab"));
- add_symbols(ns2);
- Swig_symbol_setscope(Getattr(ns1,"symtab"));
- Delete(Namespaceprefix);
- Namespaceprefix = Swig_symbol_qualifiedscopename(0);
- if (nscope_inner) {
- if (Getattr(nscope_inner,"symtab") != Getattr(ns2,"symtab")) {
- appendChild(nscope_inner,ns2);
- Delete(ns2);
- }
- }
- nscope_inner = ns2;
- if (!nscope) nscope = ns2;
- }
- cname = base;
- Delete(scopes);
- }
- }
- Delete(prefix);
- }
- return cname;
- }
-
- /* Structures for handling code fragments built for nested classes */
- typedef struct Nested {
- String *code; /* Associated code fragment */
- int line; /* line number where it starts */
- char *name; /* Name associated with this nested class */
- char *kind; /* Kind of class */
- int unnamed; /* unnamed class */
- SwigType *type; /* Datatype associated with the name */
- struct Nested *next; /* Next code fragment in list */
- } Nested;
- /* Some internal variables for saving nested class information */
- static Nested *nested_list = 0;
- /* Add a function to the nested list */
- static void add_nested(Nested *n) {
- Nested *n1;
- if (!nested_list) nested_list = n;
- else {
- n1 = nested_list;
- while (n1->next) n1 = n1->next;
- n1->next = n;
- }
- }
- /* Strips C-style and C++-style comments from string in-place. */
- static void strip_comments(char *string) {
- int state = 0; /*
- * 0 - not in comment
- * 1 - in c-style comment
- * 2 - in c++-style comment
- * 3 - in string
- * 4 - after reading / not in comments
- * 5 - after reading * in c-style comments
- * 6 - after reading \ in strings
- */
- char * c = string;
- while (*c) {
- switch (state) {
- case 0:
- if (*c == '\"')
- state = 3;
- else if (*c == '/')
- state = 4;
- break;
- case 1:
- if (*c == '*')
- state = 5;
- *c = ' ';
- break;
- case 2:
- if (*c == '\n')
- state = 0;
- else
- *c = ' ';
- break;
- case 3:
- if (*c == '\"')
- state = 0;
- else if (*c == '\\')
- state = 6;
- break;
- case 4:
- if (*c == '/') {
- *(c-1) = ' ';
- *c = ' ';
- state = 2;
- } else if (*c == '*') {
- *(c-1) = ' ';
- *c = ' ';
- state = 1;
- } else
- state = 0;
- break;
- case 5:
- if (*c == '/')
- state = 0;
- else
- state = 1;
- *c = ' ';
- break;
- case 6:
- state = 3;
- break;
- }
- ++c;
- }
- }
- /* Dump all of the nested class declarations to the inline processor
- * However. We need to do a few name replacements and other munging
- * first. This function must be called before closing a class! */
- static Node *dump_nested(const char *parent) {
- Nested *n,*n1;
- Node *ret = 0;
- n = nested_list;
- if (!parent) {
- nested_list = 0;
- return 0;
- }
- while (n) {
- Node *retx;
- SwigType *nt;
- /* Token replace the name of the parent class */
- Replace(n->code, "$classname", parent, DOH_REPLACE_ANY);
- /* Fix up the name of the datatype (for building typedefs and other stuff) */
- Append(n->type,parent);
- Append(n->type,"_");
- Append(n->type,n->name);
- /* Add the appropriate declaration to the C++ processor */
- retx = new_node("cdecl");
- Setattr(retx,"name",n->name);
- nt = Copy(n->type);
- Setattr(retx,"type",nt);
- Delete(nt);
- Setattr(retx,"nested",parent);
- if (n->unnamed) {
- Setattr(retx,"unnamed","1");
- }
-
- add_symbols(retx);
- if (ret) {
- set_nextSibling(retx,ret);
- Delete(ret);
- }
- ret = retx;
- /* Insert a forward class declaration */
- /* Disabled: [ 597599 ] union in class: incorrect scope
- retx = new_node("classforward");
- Setattr(retx,"kind",n->kind);
- Setattr(retx,"name",Copy(n->type));
- Setattr(retx,"sym:name", make_name(n->type,0));
- set_nextSibling(retx,ret);
- ret = retx;
- */
- /* Strip comments - further code may break in presence of comments. */
- strip_comments(Char(n->code));
- /* Make all SWIG created typedef structs/unions/classes unnamed else
- redefinition errors occur - nasty hack alert.*/
- {
- const char* types_array[3] = {"struct", "union", "class"};
- int i;
- for (i=0; i<3; i++) {
- char* code_ptr = Char(n->code);
- while (code_ptr) {
- /* Replace struct name (as in 'struct name {...}' ) with whitespace
- name will be between struct and opening brace */
-
- code_ptr = strstr(code_ptr, types_array[i]);
- if (code_ptr) {
- char *open_bracket_pos;
- code_ptr += strlen(types_array[i]);
- open_bracket_pos = strchr(code_ptr, '{');
- if (open_bracket_pos) {
- /* Make sure we don't have something like struct A a; */
- char* semi_colon_pos = strchr(code_ptr, ';');
- if (!(semi_colon_pos && (semi_colon_pos < open_bracket_pos)))
- while (code_ptr < open_bracket_pos)
- *code_ptr++ = ' ';
- }
- }
- }
- }
- }
-
- {
- /* Remove SWIG directive %constant which may be left in the SWIG created typedefs */
- char* code_ptr = Char(n->code);
- while (code_ptr) {
- code_ptr = strstr(code_ptr, "%constant");
- if (code_ptr) {
- char* directive_end_pos = strchr(code_ptr, ';');
- if (directive_end_pos) {
- while (code_ptr <= directive_end_pos)
- *code_ptr++ = ' ';
- }
- }
- }
- }
- {
- Node *head = new_node("insert");
- String *code = NewStringf("\n%s\n",n->code);
- Setattr(head,"code", code);
- Delete(code);
- set_nextSibling(head,ret);
- Delete(ret);
- ret = head;
- }
-
- /* Dump the code to the scanner */
- start_inline(Char(n->code),n->line);
- n1 = n->next;
- Delete(n->code);
- free(n);
- n = n1;
- }
- nested_list = 0;
- return ret;
- }
- Node *Swig_cparse(File *f) {
- scanner_file(f);
- top = 0;
- yyparse();
- return top;
- }
- static void single_new_feature(const char *featurename, String *val, Hash *featureattribs, char *declaratorid, SwigType *type, ParmList *declaratorparms, String *qualifier) {
- String *fname;
- String *name;
- String *fixname;
- SwigType *t = Copy(type);
- /* Printf(stdout, "single_new_feature: [%s] [%s] [%s] [%s] [%s] [%s]\n", featurename, val, declaratorid, t, ParmList_str_defaultargs(declaratorparms), qualifier); */
- fname = NewStringf("feature:%s",featurename);
- if (declaratorid) {
- fixname = feature_identifier_fix(declaratorid);
- } else {
- fixname = NewStringEmpty();
- }
- if (Namespaceprefix) {
- name = NewStringf("%s::%s",Namespaceprefix, fixname);
- } else {
- name = fixname;
- }
- if (declaratorparms) Setmeta(val,"parms",declaratorparms);
- if (!Len(t)) t = 0;
- if (t) {
- if (qualifier) SwigType_push(t,qualifier);
- if (SwigType_isfunction(t)) {
- SwigType *decl = SwigType_pop_function(t);
- if (SwigType_ispointer(t)) {
- String *nname = NewStringf("*%s",name);
- Swig_feature_set(Swig_cparse_features(), nname, decl, fname, val, featureattribs);
- Delete(nname);
- } else {
- Swig_feature_set(Swig_cparse_features(), name, decl, fname, val, featureattribs);
- }
- Delete(decl);
- } else if (SwigType_ispointer(t)) {
- String *nname = NewStringf("*%s",name);
- Swig_feature_set(Swig_cparse_features(),nname,0,fname,val, featureattribs);
- Delete(nname);
- }
- } else {
- /* Global feature, that is, feature not associated with any particular symbol */
- Swig_feature_set(Swig_cparse_features(),name,0,fname,val, featureattribs);
- }
- Delete(fname);
- Delete(name);
- }
- /* Add a new feature to the Hash. Additional features are added if the feature has a parameter list (declaratorparms)
- * and one or more of the parameters have a default argument. An extra feature is added for each defaulted parameter,
- * simulating the equivalent overloaded method. */
- static void new_feature(const char *featurename, String *val, Hash *featureattribs, char *declaratorid, SwigType *type, ParmList *declaratorparms, String *qualifier) {
- ParmList *declparms = declaratorparms;
- /* remove the { and } braces if the noblock attribute is set */
- String *newval = remove_block(featureattribs, val);
- val = newval ? newval : val;
- /* Add the feature */
- single_new_feature(featurename, val, featureattribs, declaratorid, type, declaratorparms, qualifier);
- /* Add extra features if there are default parameters in the parameter list */
- if (type) {
- while (declparms) {
- if (ParmList_has_defaultargs(declparms)) {
- /* Create a parameter list for the new feature by copying all
- but the last (defaulted) parameter */
- ParmList* newparms = CopyParmListMax(declparms, ParmList_len(declparms)-1);
- /* Create new declaration - with the last parameter removed */
- SwigType *newtype = Copy(type);
- Delete(SwigType_pop_function(newtype)); /* remove the old parameter list from newtype */
- SwigType_add_function(newtype,newparms);
- single_new_feature(featurename, Copy(val), featureattribs, declaratorid, newtype, newparms, qualifier);
- declparms = newparms;
- } else {
- declparms = 0;
- }
- }
- }
- }
- /* check if a function declaration is a plain C object */
- static int is_cfunction(Node *n) {
- if (!cparse_cplusplus || cparse_externc) return 1;
- if (Cmp(Getattr(n,"storage"),"externc") == 0) {
- return 1;
- }
- return 0;
- }
- /* If the Node is a function with parameters, check to see if any of the parameters
- * have default arguments. If so create a new function for each defaulted argument.
- * The additional functions form a linked list of nodes with the head being the original Node n. */
- static void default_arguments(Node *n) {
- Node *function = n;
- if (function) {
- ParmList *varargs = Getattr(function,"feature:varargs");
- if (varargs) {
- /* Handles the %varargs directive by looking for "feature:varargs" and
- * substituting ... with an alternative set of arguments. */
- Parm *p = Getattr(function,"parms");
- Parm *pp = 0;
- while (p) {
- SwigType *t = Getattr(p,"type");
- if (Strcmp(t,"v(...)") == 0) {
- if (pp) {
- ParmList *cv = Copy(varargs);
- set_nextSibling(pp,cv);
- Delete(cv);
- } else {
- ParmList *cv = Copy(varargs);
- Setattr(function,"parms", cv);
- Delete(cv);
- }
- break;
- }
- pp = p;
- p = nextSibling(p);
- }
- }
- /* Do not add in functions if kwargs is being used or if user wants old default argument wrapping
- (one wrapped method per function irrespective of number of default arguments) */
- if (compact_default_args
- || is_cfunction(function)
- || GetFlag(function,"feature:compactdefaultargs")
- || GetFlag(function,"feature:kwargs")) {
- ParmList *p = Getattr(function,"parms");
- if (p)
- Setattr(p,"compactdefargs", "1"); /* mark parameters for special handling */
- function = 0; /* don't add in extra methods */
- }
- }
- while (function) {
- ParmList *parms = Getattr(function,"parms");
- if (ParmList_has_defaultargs(parms)) {
- /* Create a parameter list for the new function by copying all
- but the last (defaulted) parameter */
- ParmList* newparms = CopyParmListMax(parms,ParmList_len(parms)-1);
- /* Create new function and add to symbol table */
- {
- SwigType *ntype = Copy(nodeType(function));
- char *cntype = Char(ntype);
- Node *new_function = new_node(ntype);
- SwigType *decl = Copy(Getattr(function,"decl"));
- int constqualifier = SwigType_isconst(decl);
- String *ccode = Copy(Getattr(function,"code"));
- String *cstorage = Copy(Getattr(function,"storage"));
- String *cvalue = Copy(Getattr(function,"value"));
- SwigType *ctype = Copy(Getattr(function,"type"));
- String *cthrow = Copy(Getattr(function,"throw"));
- Delete(SwigType_pop_function(decl)); /* remove the old parameter list from decl */
- SwigType_add_function(decl,newparms);
- if (constqualifier)
- SwigType_add_qualifier(decl,"const");
- Setattr(new_function,"name", Getattr(function,"name"));
- Setattr(new_function,"code", ccode);
- Setattr(new_function,"decl", decl);
- Setattr(new_function,"parms", newparms);
- Setattr(new_function,"storage", cstorage);
- Setattr(new_function,"value", cvalue);
- Setattr(new_function,"type", ctype);
- Setattr(new_function,"throw", cthrow);
- Delete(ccode);
- Delete(cstorage);
- Delete(cvalue);
- Delete(ctype);
- Delete(cthrow);
- Delete(decl);
- {
- Node *throws = Getattr(function,"throws");
- ParmList *pl = CopyParmList(throws);
- if (throws) Setattr(new_function,"throws",pl);
- Delete(pl);
- }
- /* copy specific attributes for global (or in a namespace) template functions - these are not templated class methods */
- if (strcmp(cntype,"template") == 0) {
- Node *templatetype = Getattr(function,"templatetype");
- Node *symtypename = Getattr(function,"sym:typename");
- Parm *templateparms = Getattr(function,"templateparms");
- if (templatetype) {
- Node *tmp = Copy(templatetype);
- Setattr(new_function,"templatetype",tmp);
- Delete(tmp);
- }
- if (symtypename) {
- Node *tmp = Copy(symtypename);
- Setattr(new_function,"sym:typename",tmp);
- Delete(tmp);
- }
- if (templateparms) {
- Parm *tmp = CopyParmList(templateparms);
- Setattr(new_function,"templateparms",tmp);
- Delete(tmp);
- }
- } else if (strcmp(cntype,"constructor") == 0) {
- /* only copied for constructors as this is not a user defined feature - it is hard coded in the parser */
- if (GetFlag(function,"feature:new")) SetFlag(new_function,"feature:new");
- }
- add_symbols(new_function);
- /* mark added functions as ones with overloaded parameters and point to the parsed method */
- Setattr(new_function,"defaultargs", n);
- /* Point to the new function, extending the linked list */
- set_nextSibling(function, new_function);
- Delete(new_function);
- function = new_function;
-
- Delete(ntype);
- }
- } else {
- function = 0;
- }
- }
- }
- /* -----------------------------------------------------------------------------
- * nested_forward_declaration()
- *
- * Treat the nested class/struct/union as a forward declaration until a proper
- * nested class solution is implemented.
- * ----------------------------------------------------------------------------- */
- static Node *nested_forward_declaration(const char *kind, const char *name) {
- Node *n = new_node("classforward");
- Setfile(n,cparse_file);
- Setline(n,cparse_line);
- Setattr(n,"kind", kind);
- Setattr(n,"name", name);
- Setattr(n,"sym:weak", "1");
- add_symbols(n);
- if (GetFlag(n, "feature:nestedworkaround")) {
- Swig_symbol_remove(n);
- n = 0;
- } else {
- SWIG_WARN_NODE_BEGIN(n);
- Swig_warning(WARN_PARSE_NAMED_NESTED_CLASS, cparse_file, cparse_line,"Nested %s not currently supported (%s ignored)\n", kind, name);
- SWIG_WARN_NODE_END(n);
- }
- return n;
- }
- /* -----------------------------------------------------------------------------
- * tag_nodes()
- *
- * Used by the parser to mark subtypes with extra information.
- * ----------------------------------------------------------------------------- */
- static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) {
- while (n) {
- Setattr(n, attrname, value);
- tag_nodes(firstChild(n), attrname, value);
- n = nextSibling(n);
- }
- }
- %}
- %union {
- char *id;
- List *bases;
- struct Define {
- String *val;
- String *rawval;
- int type;
- String *qualifier;
- String *bitfield;
- Parm *throws;
- String *throwf;
- } dtype;
- struct {
- char *type;
- String *filename;
- int line;
- } loc;
- struct {
- char *id;
- SwigType *type;
- String *defarg;
- ParmList *parms;
- short have_parms;
- ParmList *throws;
- String *throwf;
- } decl;
- Parm *tparms;
- struct {
- String *method;
- Hash *kwargs;
- } tmap;
- struct {
- String *type;
- String *us;
- } ptype;
- SwigType *type;
- String *str;
- Parm *p;
- ParmList *pl;
- int ivalue;
- Node *node;
- };
- %token <id> ID
- %token <str> HBLOCK
- %token <id> POUND
- %token <id> STRING
- %token <loc> INCLUDE IMPORT INSERT
- %token <str> CHARCONST
- %token <dtype> NUM_INT NUM_FLOAT NUM_UNSIGNED NUM_LONG NUM_ULONG NUM_LONGLONG NUM_ULONGLONG NUM_BOOL
- %token <ivalue> TYPEDEF
- %token <type> TYPE_INT TYPE_UNSIGNED TYPE_SHORT TYPE_LONG TYPE_FLOAT TYPE_DOUBLE TYPE_CHAR TYPE_WCHAR TYPE_VOID TYPE_SIGNED TYPE_BOOL TYPE_COMPLEX TYPE_TYPEDEF TYPE_RAW TYPE_NON_ISO_INT8 TYPE_NON_ISO_INT16 TYPE_NON_ISO_INT32 TYPE_NON_ISO_INT64
- %token LPAREN RPAREN COMMA SEMI EXTERN INIT LBRACE RBRACE PERIOD
- %token CONST_QUAL VOLATILE REGISTER STRUCT UNION EQUAL SIZEOF MODULE LBRACKET RBRACKET
- %token ILLEGAL CONSTANT
- %token NAME RENAME NAMEWARN EXTEND PRAGMA FEATURE VARARGS
- %token ENUM
- %token CLASS TYPENAME PRIVATE PUBLIC PROTECTED COLON STATIC VIRTUAL FRIEND THROW CATCH EXPLICIT
- %token USING
- %token <node> NAMESPACE
- %token NATIVE INLINE
- %token TYPEMAP EXCEPT ECHO APPLY CLEAR SWIGTEMPLATE FRAGMENT
- %token WARN
- %token LESSTHAN GREATERTHAN MODULO DELETE_KW
- %token LESSTHANOREQUALTO GREATERTHANOREQUALTO EQUALTO NOTEQUALTO
- %token QUESTIONMARK
- %token TYPES PARMS
- %token NONID DSTAR DCNOT
- %token <ivalue> TEMPLATE
- %token <str> OPERATOR
- %token <str> COPERATOR
- %token PARSETYPE PARSEPARM PARSEPARMS
- %left CAST
- %left QUESTIONMARK
- %left LOR
- %left LAND
- %left OR
- %left XOR
- %left AND
- %left EQUALTO NOTEQUALTO
- %left GREATERTHAN LESSTHAN GREATERTHANOREQUALTO LESSTHANOREQUALTO
- %left LSHIFT RSHIFT
- %left PLUS MINUS
- %left STAR SLASH MODULUS
- %left UMINUS NOT LNOT
- %left DCOLON
- %type <node> program interface declaration swig_directive ;
- /* SWIG directives */
- %type <node> extend_directive apply_directive clear_directive constant_directive ;
- %type <node> echo_directive except_directive fragment_directive include_directive inline_directive ;
- %type <node> insert_directive module_directive name_directive native_directive ;
- %type <node> pragma_directive rename_directive feature_directive varargs_directive typemap_directive ;
- %type <node> types_directive template_directive warn_directive ;
- /* C declarations */
- %type <node> c_declaration c_decl c_decl_tail c_enum_decl c_enum_forward_decl c_constructor_decl ;
- %type <node> enumlist edecl;
- /* C++ declarations */
- %type <node> cpp_declaration cpp_class_decl cpp_forward_class_decl cpp_template_decl;
- %type <node> cpp_members cpp_member;
- %type <node> cpp_constructor_decl cpp_destructor_decl cpp_protection_decl cpp_conversion_operator;
- %type <node> cpp_swig_directive cpp_temp_possible cpp_nested cpp_opt_declarators ;
- %type <node> cpp_using_decl cpp_namespace_decl cpp_catch_decl ;
- %type <node> kwargs options;
- /* Misc */
- %type <dtype> initializer cpp_const ;
- %type <id> storage_class;
- %type <pl> parms ptail rawparms varargs_parms;
- %type <pl> templateparameters templateparameterstail;
- %type <p> parm valparm rawvalparms valparms valptail ;
- %type <p> typemap_parm tm_list tm_tail ;
- %type <p> templateparameter ;
- %type <id> templcpptype cpptype access_specifier;
- %type <node> base_specifier
- %type <type> type rawtype type_right ;
- %type <bases> base_list inherit raw_inherit;
- %type <dtype> definetype def_args etype;
- %type <dtype> expr exprnum exprcompound valexpr;
- %type <id> ename ;
- %type <id> template_decl;
- %type <str> type_qualifier ;
- %type <id> type_qualifier_raw;
- %type <id> idstring idstringopt;
- %type <id> pragma_lang;
- %type <str> pragma_arg;
- %type <loc> includetype;
- %type <type> pointer primitive_type;
- %type <decl> declarator direct_declarator notso_direct_declarator parameter_declarator typemap_parameter_declarator nested_decl;
- %type <decl> abstract_declarator direct_abstract_declarator ctor_end;
- %type <tmap> typemap_type;
- %type <str> idcolon idcolontail idcolonnt idcolontailnt idtemplate stringbrace stringbracesemi;
- %type <id> string stringnum ;
- %type <tparms> template_parms;
- %type <dtype> cpp_end cpp_vend;
- %type <ivalue> rename_namewarn;
- %type <ptype> type_specifier primitive_type_list ;
- %type <node> fname stringtype;
- %type <node> featattr;
- %%
- /* ======================================================================
- * High-level Interface file
- *
- * An interface is just a sequence of declarations which may be SWIG directives
- * or normal C declarations.
- * ====================================================================== */
- program : interface {
- if (!classes) classes = NewHash();
- Setattr($1,"classes",classes);
- Setattr($1,"name",ModuleName);
-
- if ((!module_node) && ModuleName) {
- module_node = new_node("module");
- Setattr(module_node,"name",ModuleName);
- }
- Setattr($1,"module",module_node);
- check_extensions();
- top = $1;
- }
- | PARSETYPE parm SEMI {
- top = Copy(Getattr($2,"type"));
- Delete($2);
- }
- | PARSETYPE error {
- top = 0;
- }
- | PARSEPARM parm SEMI {
- top = $2;
- }
- | PARSEPARM error {
- top = 0;
- }
- | PARSEPARMS LPAREN parms RPAREN SEMI {
- top = $3;
- }
- | PARSEPARMS error SEMI {
- top = 0;
- }
- ;
- interface : interface declaration {
- /* add declaration to end of linked list (the declaration isn't always a single declaration, sometimes it is a linked list itself) */
- appendChild($1,$2);
- $$ = $1;
- }
- | empty {
- $$ = new_node("top");
- }
- ;
- declaration : swig_directive { $$ = $1; }
- | c_declaration { $$ = $1; }
- | cpp_declaration { $$ = $1; }
- | SEMI { $$ = 0; }
- | error {
- $$ = 0;
- Swig_error(cparse_file, cparse_line,"Syntax error in…
Large files files are truncated, but you can click here to view the full file