Exemplo n.º 1
0
String *Swig_name_disown(const String_or_char *classname) {
  String *r;
  String *f;
  String *rclassname;
  char *cname;
  rclassname = SwigType_namestr(classname);
  r = NewString("");
  if (!naming_hash) naming_hash = NewHash();
  f = Getattr(naming_hash,"disown");
  if (!f) {
    Append(r,"disown_%c");
  } else {
    Append(r,f);
  }

  cname = Char(rclassname);
  if ((strncmp(cname,"struct ", 7) == 0) ||
      ((strncmp(cname,"class ", 6) == 0)) ||
      ((strncmp(cname,"union ", 6) == 0))) {
    cname = strchr(cname, ' ')+1;
  }
  Replace(r,"%c",cname, DOH_REPLACE_ANY);
  Delete(rclassname);
  return r;
}
Exemplo n.º 2
0
SwigType *
SwigType_strip_qualifiers(SwigType *t) {
  static Hash *memoize_stripped = 0;
  SwigType *r;
  List     *l;
  Iterator  ei;

  if (!memoize_stripped) memoize_stripped = NewHash();
  r = Getattr(memoize_stripped,t);
  if (r) return Copy(r);
  
  l = SwigType_split(t);
  r = NewString("");
  
  for (ei = First(l);ei.item; ei = Next(ei)) {
    if (SwigType_isqualifier(ei.item)) continue;
    Append(r,ei.item);
  }
  Delete(l);
  {
    String *key, *value;
    key = Copy(t);
    value = Copy(r);
    Setattr(memoize_stripped,key,value);
    Delete(key);
    Delete(value);
  }
  return r;
}
Exemplo n.º 3
0
void *
DohGetVoid(DOH *obj, const DOH *name) {
  DOH *val;
  val = Getattr(obj,(DOH *) name);
  if (!val) return 0;
  return (void *) Data(val);
}
Exemplo n.º 4
0
int Swig_need_redefined_warn(Node *a, Node *b, int InClass) {
  String *a_name = Getattr(a, "name");
  String *b_name = Getattr(b, "name");
  String *a_symname = Getattr(a, "sym:name");
  String *b_symname = Getattr(b, "sym:name");
  /* always send a warning if a 'rename' is involved */
  if ((a_symname && !Equal(a_symname, a_name))
      || (b_symname && !Equal(b_symname, b_name))) {
    if (!Equal(a_name, b_name)) {
      return 1;
    }
  }


  return !nodes_are_equivalent(a, b, InClass);
}
Exemplo n.º 5
0
String *Swig_name_destroy(const_String_or_char_ptr nspace, const_String_or_char_ptr classname) {
  String *r;
  String *f;
  String *rclassname;
  char *cname;
  rclassname = SwigType_namestr(classname);
  r = NewStringEmpty();
  if (!naming_hash)
    naming_hash = NewHash();
  f = Getattr(naming_hash, "destroy");
  if (!f) {
    Append(r, "delete_%n%c");
  } else {
    Append(r, f);
  }

  cname = Char(rclassname);
  if ((strncmp(cname, "struct ", 7) == 0) || ((strncmp(cname, "class ", 6) == 0)) || ((strncmp(cname, "union ", 6) == 0))) {
    cname = strchr(cname, ' ') + 1;
  }

  replace_nspace(r, nspace);
  Replace(r, "%c", cname, DOH_REPLACE_ANY);
  Delete(rclassname);
  return r;
}
Exemplo n.º 6
0
int Swig_VarsetToFunction(Node *n, int flags) {
    String *name, *nname;
    ParmList *parms;
    SwigType *type, *ty;

    int varcref = flags & CWRAP_NATURAL_VAR;

    name = Getattr(n, "name");
    type = Getattr(n, "type");
    nname = SwigType_namestr(name);
    ty = Swig_wrapped_var_type(type, varcref);
    parms = NewParm(ty, name);

    if (flags & CWRAP_EXTEND) {
        String *sname = Swig_name_set(name);
        String *mangled = Swig_name_mangle(sname);
        String *call = Swig_cfunction_call(mangled, parms);
        String *cres = NewStringf("%s;", call);
        Setattr(n, "wrap:action", cres);
        Delete(cres);
        Delete(call);
        Delete(mangled);
        Delete(sname);
    } else {
        if (!Strstr(type, "enum $unnamed")) {
            String *pname = Swig_cparm_name(0, 0);
            String *dref = Swig_wrapped_var_deref(type, pname, varcref);
            String *call = NewStringf("%s = %s;", nname, dref);
            Setattr(n, "wrap:action", call);
            Delete(call);
            Delete(dref);
            Delete(pname);
        } else {
            String *pname = Swig_cparm_name(0, 0);
            String *call = NewStringf("if (sizeof(int) == sizeof(%s)) *(int*)(void*)&(%s) = %s;", nname, nname, pname);
            Setattr(n, "wrap:action", call);
            Delete(pname);
            Delete(call);
        }
    }
    Setattr(n, "type", "void");
    Setattr(n, "parms", parms);
    Delete(parms);
    Delete(ty);
    Delete(nname);
    return SWIG_OK;
}
Exemplo n.º 7
0
Arquivo: parms.c Projeto: kanbang/Colt
int ParmList_numarg(ParmList *p) {
  int  n = 0;
  while (p) {
    if (!Getattr(p,"ignore")) n++;
    p = nextSibling(p);
  }
  return n;
}
Exemplo n.º 8
0
String *ParmList_errorstr(ParmList *p) {
  String *out = NewStringEmpty();
  while (p) {
    if (Getattr(p,"hidden")) {
      p = nextSibling(p);
    } else {
      String *pstr = SwigType_str(Getattr(p, "type"), 0);
      Append(out, pstr);
      p = nextSibling(p);
      if (p) {
	Append(out, ",");
      }
      Delete(pstr);
    }
  }
  return out;
}
Exemplo n.º 9
0
int ParmList_is_compactdefargs(ParmList *p) {
  int compactdefargs = 0;

  if (p) {
    compactdefargs = Getattr(p, "compactdefargs") ? 1 : 0;

    /* The "compactdefargs" attribute should only be set on the first parameter in the list.
     * However, sometimes an extra parameter is inserted at the beginning of the parameter list,
     * so we check the 2nd parameter too. */
    if (!compactdefargs) {
      Parm *nextparm = nextSibling(p);
      compactdefargs = (nextparm && Getattr(nextparm, "compactdefargs")) ? 1 : 0;
    }
  }

  return compactdefargs;
}
Exemplo n.º 10
0
void Swig_require(const char *ns, Node *n, ...) {
  va_list ap;
  char *name;
  DOH *obj;

  va_start(ap, n);
  name = va_arg(ap, char *);
  while (name) {
    int newref = 0;
    int opt = 0;
    if (*name == '*') {
      newref = 1;
      name++;
    } else if (*name == '?') {
      newref = 1;
      opt = 1;
      name++;
    }
    obj = Getattr(n, name);
    if (!opt && !obj) {
      Swig_error(Getfile(n), Getline(n), "Fatal error (Swig_require).  Missing attribute '%s' in node '%s'.\n", name, nodeType(n));
      assert(obj);
    }
    if (!obj)
      obj = DohNone;
    if (newref) {
      /* Save a copy of the attribute */
      Setattr(n, NewStringf("%s:%s", ns, name), obj);
    }
    name = va_arg(ap, char *);
  }
  va_end(ap);

  /* Save the view */
  {
    String *view = Getattr(n, "view");
    if (view) {
      if (Strcmp(view, ns) != 0) {
	Setattr(n, NewStringf("%s:view", ns), view);
	Setattr(n, "view", NewString(ns));
      }
    } else {
      Setattr(n, "view", NewString(ns));
    }
  }
}
Exemplo n.º 11
0
int
checkAttribute(Node *n, const String_or_char *name, const String_or_char *value) {
  String *v;
  v = Getattr(n,name);
  if (!v) return 0;
  if (Cmp(v,value) == 0) return 1;
  return 0;
}
Exemplo n.º 12
0
int 
Swig_save(const char *ns, Node *n, ...) {
  va_list ap;
  char *name;
  DOH *obj;
  char temp[512];

  va_start(ap, n);
  name = va_arg(ap, char *);
  while (name) {
    if (*name == '*') {
      name++;
    } else if (*name == '?') {
      name++;
    }
    obj = Getattr(n,name);
    if (!obj) {
      obj = DohNone;
    }
    strcpy(temp,ns);
    strcat(temp,":");
    strcat(temp,name);
    if (Setattr(n,temp,obj)) {
      Printf(stderr,"Swig_save('%s','%s'): Warning, attribute '%s' was already saved.\n", ns, nodeType(n), name);
    }
    name = va_arg(ap, char *);
  }
  va_end(ap);

  /* Save the view */
  {
    String *view = Getattr(n,"view");
    if (view) {
      if (Strcmp(view,ns) != 0) {
	strcpy(temp,ns);
	strcat(temp,":view");
	Setattr(n,temp,view);
	Setattr(n,"view",ns);
      }
    } else {
      Setattr(n,"view",ns);
    }
  }

  return 1;
}
Exemplo n.º 13
0
String *ParmList_str_defaultargs(ParmList *p) {
  String *out = NewStringEmpty();
  while (p) {
    String *value = Getattr(p, "value");
    String *pstr = SwigType_str(Getattr(p, "type"), Getattr(p, "name"));
    Append(out, pstr);
    if (value) {
      Printf(out, "=%s", value);
    }
    p = nextSibling(p);
    if (p) {
      Append(out, ",");
    }
    Delete(pstr);
  }
  return out;
}
static Parm *nonvoid_parms(Parm *p) {
  if (p) {
    SwigType *t = Getattr(p, k_type);
    if (SwigType_type(t) == T_VOID)
      return 0;
  }
  return p;
}
Exemplo n.º 15
0
int Swig_cargs(Wrapper *w, ParmList *p) {
  int   i;
  SwigType *pt;
  String  *pvalue;
  String  *pname;
  String  *local;
  String  *lname;
  SwigType *altty;
  String  *type;
  int      tycode;

  i = 0;
  while (p != 0) {
    lname  = Swig_cparm_name(p,i);
    pt     = Getattr(p,"type");
    if ((SwigType_type(pt) != T_VOID)) {
      pname  = Getattr(p,"name");
      pvalue = Getattr(p,"value");
      altty = Getattr(p,"alttype");
      type  = Getattr(p,"type");
      tycode = SwigType_type(type);
      if (tycode == T_REFERENCE) {
	if (pvalue) {
	  String *defname, *defvalue;
	  defname = NewStringf("%s_defvalue", lname);
	  defvalue = NewStringf("%s = %s", SwigType_str(type,defname), pvalue);
	  Wrapper_add_localv(w,defname, defvalue, NIL);
	  Delete(defname);
	  Delete(defvalue);
	}
      }  else if (!pvalue && (tycode == T_POINTER)) {
	pvalue = (String *) "0";
      }
      if (!altty) {
	local  = Swig_clocal(pt,lname,pvalue);
      } else {
	local = Swig_clocal(altty,lname, pvalue);
      }
      Wrapper_add_localv(w,lname,local,NIL);
      i++;
    }
    p = nextSibling(p);
  }
  return(i);
}
Exemplo n.º 16
0
void
Swig_fragment_register(Node* fragment) {
  if (Getattr(fragment,k_emitonly)) {
    Swig_fragment_emit(fragment);
    return;
  } else {
    String *name = Copy(Getattr(fragment,k_value));
    String *type = Getattr(fragment,k_type);
    if (type) {
      SwigType *rtype = SwigType_typedef_resolve_all(type);
      String *mangle = Swig_string_mangle(type);
      Append(name,mangle);
      Delete(mangle);
      Delete(rtype);
      if (debug) Printf(stdout,"register fragment %s %s\n",name,type);
    }
    if (!fragments) {
      fragments = NewHash();
    }
    if (!Getattr(fragments,name)) {
      String *section = Copy(Getattr(fragment,k_section));
      String *ccode = Copy(Getattr(fragment,k_code));
      Hash *kwargs = Getattr(fragment,k_kwargs);
      Setmeta(ccode,k_section,section);
      if (kwargs) {
	Setmeta(ccode,k_kwargs,kwargs);
      }
      Setattr(fragments,name,ccode);
      if (debug) Printf(stdout,"registering fragment %s %s\n",name,section);
      Delete(section);
      Delete(ccode);
    }
    Delete(name);
  }
}
Exemplo n.º 17
0
static void Swig_name_object_attach_keys(const char *keys[], Hash *nameobj) {
  Node *kw = nextSibling(nameobj);
  List *matchlist = 0;
  while (kw) {
    Node *next = nextSibling(kw);
    String *kname = Getattr(kw, "name");
    char *ckey = kname ? Char(kname) : 0;
    if (ckey) {
      const char **rkey;
      int isnotmatch = 0;
      int isregexmatch = 0;
      if ((strncmp(ckey, "match", 5) == 0)
	  || (isnotmatch = (strncmp(ckey, "notmatch", 8) == 0))
	  || (isregexmatch = (strncmp(ckey, "regexmatch", 10) == 0))
	  || (isnotmatch = isregexmatch = (strncmp(ckey, "notregexmatch", 13) == 0))) {
	Hash *mi = NewHash();
	List *attrlist = Swig_make_attrlist(ckey);
	if (!matchlist)
	  matchlist = NewList();
	Setattr(mi, "value", Getattr(kw, "value"));
	Setattr(mi, "attrlist", attrlist);
	if (isnotmatch)
	  SetFlag(mi, "notmatch");
	if (isregexmatch)
	  SetFlag(mi, "regexmatch");
	Delete(attrlist);
	Append(matchlist, mi);
	Delete(mi);
	removeNode(kw);
      } else {
	for (rkey = keys; *rkey != 0; ++rkey) {
	  if (strcmp(ckey, *rkey) == 0) {
	    Setattr(nameobj, *rkey, Getattr(kw, "value"));
	    removeNode(kw);
	  }
	}
      }
    }
    kw = next;
  }
  if (matchlist) {
    Setattr(nameobj, "matchlist", matchlist);
    Delete(matchlist);
  }
}
Exemplo n.º 18
0
void
Swig_print_node(Node *obj) {
  Iterator ki;
  Node   *cobj;
  
  print_indent(0);
  Printf(stdout,"+++ %s ----------------------------------------\n", nodeType(obj));
  ki = First(obj);
  while (ki.key) {
    String *k = ki.key;
    if ((Cmp(k,"nodeType") == 0) || (Cmp(k,"firstChild") == 0) || (Cmp(k,"lastChild") == 0) ||
	(Cmp(k,"parentNode") == 0) || (Cmp(k,"nextSibling") == 0) ||
	(Cmp(k,"previousSibling") == 0) || (*(Char(k)) == '$')) {
      /* Do nothing */
    } else if (Cmp(k,"parms") == 0) {
      print_indent(2);
      Printf(stdout,"%-12s - %s\n", k, ParmList_protostr(Getattr(obj,k)));
    } else {
      DOH *o;
      char *trunc = "";
      print_indent(2);
      if (DohIsString(Getattr(obj,k))) {
	o = Str(Getattr(obj,k));
	if (Len(o) > 40) {
	  trunc = "...";
	}
	Printf(stdout,"%-12s - \"%(escape)-0.40s%s\"\n", k, o, trunc);
	Delete(o);
      } else {
	Printf(stdout,"%-12s - 0x%x\n", k, Getattr(obj,k));
      }
    }
    ki = Next(ki);
  }
  cobj = firstChild(obj);
  if (cobj) {
    indent_level += 6;
    Printf(stdout,"\n");
    Swig_print_tree(cobj);
    indent_level -= 6;
  } else {
    print_indent(1);
    Printf(stdout,"\n");
  }
}
Exemplo n.º 19
0
int ParmList_has_defaultargs(ParmList *p) {
  while (p) {
    if (Getattr(p, "value")) {
      return 1;
    }
    p = nextSibling(p);
  }
  return 0;
}
Exemplo n.º 20
0
int
Swig_directormethod(Node *n) {
  Node *classNode = Swig_methodclass(n);
  if (classNode) {
    Node *vtable = Getattr(classNode, "vtable");
    if (vtable) {
      String *name = Getattr(n, "name");
      String *decl = Getattr(n, "decl");
      String *method_id = NewStringf("%s|%s", name, decl);
      Hash *item = Getattr(vtable, method_id);
      Delete(method_id);
      if (item) {
        return (Getattr(item, "director") != 0);
      }
    }
  }
  return 0;
}
Exemplo n.º 21
0
int
Swig_VargetToFunction(Node *n) {
  String   *name, *nname;
  SwigType *type, *ty;

  name = Getattr(n,"name");
  type = Getattr(n,"type");

  nname = SwigType_namestr(name);
  ty = Swig_wrapped_var_type(type);

  Setattr(n,"wrap:action", Swig_cresult(ty,"result",Swig_wrapped_var_assign(type,nname)));
  Setattr(n,"type",ty);
  Delattr(n,"parms");
  Delete(nname);
  Delete(ty);
  return SWIG_OK;
}
Exemplo n.º 22
0
Arquivo: parms.c Projeto: kanbang/Colt
String *ParmList_protostr(ParmList *p) {
  String *out;
  SwigType *t;

  out = NewString("");
  while(p) {
    if (Getattr(p,"hidden")) {
      p = nextSibling(p);
      continue;
    }
    t = Getattr(p,"type");
    Printf(out,"%s", SwigType_str(t,0));
    p = nextSibling(p);
    if (p)
      Printf(out,",");
  }
  return out;
}
Exemplo n.º 23
0
int Wrapper_add_local(Wrapper *w, const_String_or_char_ptr name, const_String_or_char_ptr decl) {
  /* See if the local has already been declared */
  if (Getattr(w->localh, name)) {
    return -1;
  }
  Setattr(w->localh, name, decl);
  Printf(w->locals, "%s;\n", decl);
  return 0;
}
Exemplo n.º 24
0
static DOH *Swig_get_lattr(Node *n, List *lattr) {
  DOH *res = 0;
  int ilen = Len(lattr);
  int i;
  for (i = 0; n && (i < ilen); ++i) {
    String *nattr = Getitem(lattr, i);
    res = Getattr(n, nattr);
#ifdef SWIG_DEBUG
    if (!res) {
      Printf(stdout, "missing %s %s %s\n", nattr, Getattr(n, "name"), Getattr(n, "member"));
    } else {
      Printf(stdout, "lattr %d %s %s\n", i, nattr, DohIsString(res) ? res : Getattr(res, "name"));
    }
#endif
    n = res;
  }
  return res;
}
Exemplo n.º 25
0
Node *Swig_cparse_template_locate(String *name, Parm *tparms, Symtab *tscope) {
  Node *n = template_locate(name, tparms, tscope);	/* this function does what we want for templated classes */

  if (n) {
    String *nodeType = nodeType(n);
    int isclass = 0;
    assert(Equal(nodeType, "template"));
    isclass = (Equal(Getattr(n, "templatetype"), "class"));
    if (!isclass) {
      /* If not a templated class we must have a templated function.
         The template found is not necessarily the one we want when dealing with templated
         functions. We don't want any specialized templated functions as they won't have
         the default parameters. Lets look for the unspecialized template. Also make sure
         the number of template parameters is correct as it is possible to overload a
         templated function with different numbers of template parameters. */

      if (template_debug) {
	Printf(stdout, "    Not a templated class, seeking most appropriate templated function\n");
      }

      n = Swig_symbol_clookup_local(name, 0);
      while (n) {
	Parm *tparmsfound = Getattr(n, "templateparms");
	if (ParmList_len(tparms) == ParmList_len(tparmsfound)) {
	  /* successful match */
	  break;
	}
	/* repeat until we find a match with correct number of templated parameters */
	n = Getattr(n, "sym:nextSibling");
      }

      if (!n) {
	Swig_error(cparse_file, cparse_line, "Template '%s' undefined.\n", name);
      }

      if ((template_debug) && (n)) {
	Printf(stdout, "Templated function found: %p\n", n);
	Swig_print_node(n);
      }
    }
  }

  return n;
}
Exemplo n.º 26
0
String *Swig_cppconstructor_base_call(const_String_or_char_ptr name, ParmList *parms, int skip_self) {
    String *func;
    String *nname;
    int i = 0;
    int comma = 0;
    Parm *p = parms;
    SwigType *pt;
    if (skip_self) {
        if (p)
            p = nextSibling(p);
        i++;
    }
    nname = SwigType_namestr(name);
    func = NewStringEmpty();
    Printf(func, "new %s(", nname);
    while (p) {
        pt = Getattr(p, "type");
        if ((SwigType_type(pt) != T_VOID)) {
            String *rcaststr = 0;
            String *pname = 0;
            if (comma)
                Append(func, ",");
            if (!Getattr(p, "arg:byname")) {
                pname = Swig_cparm_name(p, i);
                i++;
            } else {
                pname = Getattr(p, "value");
                if (pname)
                    pname = Copy(pname);
                else
                    pname = Copy(Getattr(p, "name"));
            }
            rcaststr = SwigType_rcaststr(pt, pname);
            Append(func, rcaststr);
            Delete(rcaststr);
            comma = 1;
            Delete(pname);
        }
        p = nextSibling(p);
    }
    Append(func, ")");
    Delete(nname);
    return func;
}
Exemplo n.º 27
0
void
SwigType_add_template(SwigType *t, ParmList *parms) {
  Parm   *p;

  Append(t,"<(");
  p = parms;
  for (p = parms; p; p = nextSibling(p)) {
    String *v;
    if (Getattr(p,"default")) continue;
    if (p != parms) Append(t,",");
    v = Getattr(p,"value");
    if (v) {
      Append(t,v);
    } else {
      Append(t,Getattr(p,"type"));
    }
  }
  Append(t,")>");
}
char *DohGetChar(DOH *obj, const DOH *name) {
  DOH *val;
  val = Getattr(obj, (DOH *) name);
  if (!val)
    return 0;
  if (DohIsString(val)) {
    return (char *) Data(val);
  }
  return 0;
}
double DohGetDouble(DOH *obj, const DOH *name) {
  DOH *val;
  val = Getattr(obj, (DOH *) name);
  if (!val)
    return 0;
  if (DohIsString(val)) {
    return atof((char *) Data(val));
  }
  return 0;
}
String *Swig_cfunction_call(String_or_char *name, ParmList *parms) {
  String *func;
  int i = 0;
  int comma = 0;
  Parm *p = parms;
  String *nname;

  func = NewStringEmpty();
  nname = SwigType_namestr(name);

  /*
     SWIGTEMPLATEDISAMBIGUATOR is compiler dependent (swiglabels.swg),
     - SUN Studio 9 requires 'template', 
     - gcc-3.4 forbids the use of 'template'.
     the rest seems not caring very much,
   */
  if (SwigType_istemplate(name)) {
    String *prefix = Swig_scopename_prefix(nname);
    if (!prefix || Len(prefix) == 0) {
      Printf(func, "%s(", nname);
    } else {
      String *last = Swig_scopename_last(nname);
      Printf(func, "%s::SWIGTEMPLATEDISAMBIGUATOR %s(", prefix, last);
      Delete(last);
    }
    Delete(prefix);
  } else {
    Printf(func, "%s(", nname);
  }
  Delete(nname);

  while (p) {
    SwigType *pt = Getattr(p, k_type);
    if ((SwigType_type(pt) != T_VOID)) {
      SwigType *rpt = SwigType_typedef_resolve_all(pt);
      String *pname = Swig_cparm_name(p, i);
      String *rcaststr = SwigType_rcaststr(rpt, pname);

      if (comma) {
	Printv(func, ",", rcaststr, NIL);
      } else {
	Append(func, rcaststr);
      }
      Delete(rpt);
      Delete(pname);
      Delete(rcaststr);
      comma = 1;
      i++;
    }
    p = nextSibling(p);
  }
  Append(func, ")");
  return func;
}