コード例 #1
0
ファイル: misc.c プロジェクト: EemeliSyynimaa/yam2d
String *Swig_new_subdirectory(String *basedirectory, String *subdirectory) {
  String *error = 0;
  int current_directory = Len(basedirectory) == 0;

  if (current_directory || is_directory(basedirectory)) {
    Iterator it;
    String *dir = NewString(basedirectory);
    List *subdirs = Split(subdirectory, SWIG_FILE_DELIMITER[0], INT_MAX);

    for (it = First(subdirs); it.item; it = Next(it)) {
      int result;
      String *subdirectory = it.item;
      Printf(dir, "%s", subdirectory);
#ifdef _WIN32
      result = _mkdir(Char(dir));
#else
      result = mkdir(Char(dir), 0777);
#endif
      if (result != 0 && errno != EEXIST) {
	error = NewStringf("Cannot create directory %s: %s", dir, strerror(errno));
	break;
      }
      if (!is_directory(dir)) {
	error = NewStringf("Cannot create directory %s: it may already exist but not be a directory", dir);
	break;
      }
      Printf(dir, SWIG_FILE_DELIMITER);
    }
  } else {
    error = NewStringf("Cannot create subdirectory %s under the base directory %s. Either the base does not exist as a directory or it is not readable.", subdirectory, basedirectory);
  }
  return error;
}
コード例 #2
0
/* Create a name applying rename/namewarn if needed */
static String *apply_rename(String *newname, int fullname, String *prefix, String *name) {
  String *result = 0;
  if (newname && Len(newname)) {
    if (Strcmp(newname, "$ignore") == 0) {
      result = Copy(newname);
    } else {
      char *cnewname = Char(newname);
      if (cnewname) {
	int destructor = name && (*(Char(name)) == '~');
	String *fmt = newname;
	/* use name as a fmt, but avoid C++ "%" and "%=" operators */
	if (Len(newname) > 1 && strchr(cnewname, '%') && !(strcmp(cnewname, "%=") == 0)) {
	  if (fullname && prefix) {
	    result = NewStringf(fmt, prefix, name);
	  } else {
	    result = NewStringf(fmt, name);
	  }
	} else {
	  result = Copy(newname);
	}
	if (destructor && result && (*(Char(result)) != '~')) {
	  Insert(result, 0, "~");
	}
      }
    }
  }

  return result;
}
コード例 #3
0
/* -----------------------------------------------------------------------------
 * Swig_cargs()
 *
 * Emit all of the local variables for a list of parameters.  Returns the
 * number of parameters.
 * Default values for the local variables are only emitted if the compact default
 * argument behaviour is required.
 * ----------------------------------------------------------------------------- */
int Swig_cargs(Wrapper *w, ParmList *p) {
  int i = 0;
  int compactdefargs = ParmList_is_compactdefargs(p);

  while (p != 0) {
    String *lname = Swig_cparm_name(p, i);
    SwigType *pt = Getattr(p, k_type);
    if ((SwigType_type(pt) != T_VOID)) {
      String *local = 0;
      String *type = Getattr(p, k_type);
      /* default values only emitted if in compact default args mode */
      String *pvalue = (compactdefargs) ? Getattr(p, k_value) : 0;
      SwigType *altty = SwigType_alttype(type, 0);
      int tycode = SwigType_type(type);
      if (tycode == T_REFERENCE) {
	if (pvalue) {
	  SwigType *tvalue;
	  String *defname, *defvalue, *rvalue, *qvalue;
	  rvalue = SwigType_typedef_resolve_all(pvalue);
	  qvalue = SwigType_typedef_qualified(rvalue);
	  defname = NewStringf("%s_defvalue", lname);
	  tvalue = Copy(type);
	  SwigType_del_reference(tvalue);
	  tycode = SwigType_type(tvalue);
	  if (tycode != T_USER) {
	    /* plain primitive type, we copy the the def value */
	    String *lstr = SwigType_lstr(tvalue, defname);
	    defvalue = NewStringf("%s = %s", lstr, qvalue);
	    Delete(lstr);
	  } else {
	    /* user type, we copy the reference value */
	    String *str = SwigType_str(type, defname);
	    defvalue = NewStringf("%s = %s", str, qvalue);
	    Delete(str);
	  }
	  Wrapper_add_localv(w, defname, defvalue, NIL);
	  Delete(tvalue);
	  Delete(rvalue);
	  Delete(qvalue);
	  Delete(defname);
	  Delete(defvalue);
	}
      } else if (!pvalue && ((tycode == T_POINTER) || (tycode == T_STRING))) {
	pvalue = (String *) "0";
      }
      if (!altty) {
	local = Swig_clocal(pt, lname, pvalue);
      } else {
	local = Swig_clocal(altty, lname, pvalue);
	Delete(altty);
      }
      Wrapper_add_localv(w, lname, local, NIL);
      Delete(local);
      i++;
    }
    Delete(lname);
    p = nextSibling(p);
  }
  return (i);
}
コード例 #4
0
void Swig_name_nameobj_add(Hash *name_hash, List *name_list, String *prefix, String *name, SwigType *decl, Hash *nameobj) {
  String *nname = 0;
  if (name && Len(name)) {
    String *target_fmt = Getattr(nameobj, "targetfmt");
    nname = prefix ? NewStringf("%s::%s", prefix, name) : NewString(name);
    if (target_fmt) {
      String *tmp = NewStringf(target_fmt, nname);
      Delete(nname);
      nname = tmp;
    }
  }

  if (!nname || !Len(nname) || Getattr(nameobj, "fullname") ||	/* any of these options trigger a 'list' nameobj */
      Getattr(nameobj, "sourcefmt") || Getattr(nameobj, "matchlist") || Getattr(nameobj, "regextarget")) {
    if (decl)
      Setattr(nameobj, "decl", decl);
    if (nname && Len(nname))
      Setattr(nameobj, "targetname", nname);
    /* put the new nameobj at the beginnig of the list, such that the
       last inserted rule take precedence */
    Insert(name_list, 0, nameobj);
  } else {
    /* here we add an old 'hash' nameobj, simple and fast */
    Swig_name_object_set(name_hash, nname, decl, nameobj);
  }
  Delete(nname);
}
コード例 #5
0
ファイル: cwrap.c プロジェクト: jumpinjackie/node-mapguide
int
Swig_MembersetToFunction(Node *n, String *classname, int flags) {
  String   *name;
  ParmList *parms;
  Parm     *p;
  SwigType *t;
  SwigType *ty;
  SwigType *type;
  String   *membername;
  String   *mangled;
  String   *self= 0;

  if (flags & CWRAP_SMART_POINTER) {
    self = NewString("(*this)->");
  }

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

  membername = Swig_name_member(classname, Swig_name_set(name));
  mangled = Swig_name_mangle(membername);

  t = NewString(classname);
  SwigType_add_pointer(t);
  parms = NewParm(t,"self");
  Delete(t);

  ty = Swig_wrapped_var_type(type);
  p = NewParm(ty,name);
  set_nextSibling(parms,p);

  /* If the type is a pointer or reference.  We mark it with a special wrap:disown attribute */
  if (SwigType_check_decl(type,"p.")) {
    Setattr(p,"wrap:disown","1");
  }
  Delete(p);

  if (flags & CWRAP_EXTEND) {
    String *code = Getattr(n,"code");
    if (code) {
      String *s = NewStringf("void %s(%s)", mangled, ParmList_str(parms));
      Printv(s,code,"\n",NIL);
      Setattr(n,"wrap:code",s);
      Delete(s);
    }
    Setattr(n,"wrap:action", NewStringf("%s;\n", Swig_cfunction_call(mangled,parms)));
  } else {
    Setattr(n,"wrap:action", NewStringf("%s;\n", Swig_cmemberset_call(name,type,self)));
  }
  Setattr(n,"type","void");
  Setattr(n,"parms", parms);
  Delete(parms);
  Delete(ty);
  Delete(membername);
  Delete(mangled);
  Delete(self);
  return SWIG_OK;
}
コード例 #6
0
String *ParmList_str_multibrackets(ParmList *p) {
    String *out;
    String *parm_str = ParmList_str_defaultargs(p);
    if (ParmList_len(p) > 1)
        out = NewStringf("(%s)", parm_str);
    else
        out = NewStringf("%s", parm_str);
    Delete(parm_str);
    return out;
}
コード例 #7
0
Hash *Swig_name_nameobj_lget(List *namelist, Node *n, String *prefix, String *name, String *decl) {
  Hash *res = 0;
  if (namelist) {
    int len = Len(namelist);
    int i;
    int match = 0;
    for (i = 0; !match && (i < len); i++) {
      Hash *rn = Getitem(namelist, i);
      String *rdecl = Getattr(rn, "decl");
      if (rdecl && (!decl || !Equal(rdecl, decl))) {
	continue;
      } else if (Swig_name_match_nameobj(rn, n)) {
	String *tname = Getattr(rn, "targetname");
	if (tname) {
	  String *sfmt = Getattr(rn, "sourcefmt");
	  String *sname = 0;
	  int fullname = GetFlag(rn, "fullname");
	  int regextarget = GetFlag(rn, "regextarget");
	  if (sfmt) {
	    if (fullname && prefix) {
	      String *pname = NewStringf("%s::%s", prefix, name);
	      sname = NewStringf(sfmt, pname);
	      Delete(pname);
	    } else {
	      sname = NewStringf(sfmt, name);
	    }
	  } else {
	    if (fullname && prefix) {
	      sname = NewStringf("%s::%s", prefix, name);
	    } else {
	      sname = name;
	      DohIncref(name);
	    }
	  }
	  match = regextarget ? Swig_name_regexmatch_value(n, tname, sname)
	    : Swig_name_match_value(tname, sname);
	  Delete(sname);
	} else {
	  /* Applying the renaming rule may fail if it contains a %(regex)s expression that doesn't match the given name. */
	  String *sname = NewStringf(Getattr(rn, "name"), name);
	  if (sname) {
	    if (Len(sname))
	      match = 1;
	    Delete(sname);
	  }
	}
      }
      if (match) {
	res = rn;
	break;
      }
    }
  }
  return res;
}
コード例 #8
0
static String *Swig_wrapped_var_assign(SwigType *t, const String_or_char *name, int varcref) {
  if (SwigType_isclass(t)) {
    if (varcref) {
      return NewStringf("%s", name);
    } else {
      return NewStringf("&%s", name);
    }
  } else {
    return SwigType_lcaststr(t, name);
  }
}
コード例 #9
0
ファイル: naming.c プロジェクト: kanbang/Colt
DOH *
Swig_name_object_get(Hash *namehash, String *prefix, String *name, SwigType *decl) {
  String *tname;
  DOH    *rn = 0;
  Hash   *n;
  char   *ncdecl = 0;

  if (!namehash) return 0;

  /* DB: This removed to more tightly control feature/name matching */
  /*  if ((decl) && (SwigType_isqualifier(decl))) {
    ncdecl = strchr(Char(decl),'.');
    ncdecl++;
  }
  */

  /* Perform a class-based lookup (if class prefix supplied) */
  if (prefix) {
    if (Len(prefix)) {
      tname = NewStringf("%s::%s",prefix,name);
      n = Getattr(namehash,tname);
      rn = get_object(n,decl);
      if ((!rn) && ncdecl) rn = get_object(n,ncdecl);
      if (!rn) rn = get_object(n,0);
      Delete(tname);
    }
    /* A wildcard-based class lookup */
    if (!rn) {
      tname = NewStringf("*::%s",name);
      n = Getattr(namehash,tname);
      rn = get_object(n,decl);
      if ((!rn) && ncdecl) rn = get_object(n,ncdecl);
      if (!rn) rn = get_object(n,0);
      Delete(tname);
    }
  } else {
    /* Lookup in the global namespace only */
    tname = NewStringf("::%s",name);
    n = Getattr(namehash,tname);
    rn = get_object(n,decl);
    if ((!rn) && ncdecl) rn = get_object(n,ncdecl);
    if (!rn) rn = get_object(n,0);
    Delete(tname);
  }
  /* Catch-all */
  if (!rn) {
    n = Getattr(namehash,name);
    rn = get_object(n,decl);
    if ((!rn) && ncdecl) rn = get_object(n,ncdecl);
    if (!rn) rn = get_object(n,0);
  }
  return rn;
}
コード例 #10
0
/* -----------------------------------------------------------------------------
 * extension_code()
 *
 * Generates an extension function (a function defined in %extend)
 *
 *        return_type function_name(parms) code
 *
 * ----------------------------------------------------------------------------- */
static String *extension_code(const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus, const String *self) {
  String *parms_str = cplusplus ? ParmList_str_defaultargs(parms) : ParmList_str(parms);
  String *sig = NewStringf("%s(%s)", function_name, parms_str);
  String *rt_sig = SwigType_str(return_type, sig);
  String *body = NewStringf("SWIGINTERN %s", rt_sig);
  Printv(body, code, "\n", NIL);
  if (self)
    Replaceall(body, "$self", self);
  Delete(parms_str);
  Delete(sig);
  Delete(rt_sig);
  return body;
}
コード例 #11
0
int Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags) {
  SwigType *type;
  Parm *p;

  type = NewString(classname);
  SwigType_add_pointer(type);
  p = NewParm(type, k_self);
  Setattr(p, k_self, "1");
  Setattr(p, k_hidden, "1");
  Setattr(p, k_wrapdisown, "1");
  Delete(type);
  type = NewString("void");

  if (flags & CWRAP_EXTEND) {
    String *cres;
    String *call;
    String *membername, *mangled, *code;
    membername = Swig_name_destroy(classname);
    mangled = Swig_name_mangle(membername);
    code = Getattr(n, k_code);
    if (code) {
      Swig_add_extension_code(n, mangled, p, type, code, cparse_cplusplus, k_self);
    }
    call = Swig_cfunction_call(mangled, p);
    cres = NewStringf("%s;\n", call);
    Setattr(n, k_wrapaction, cres);
    Delete(membername);
    Delete(mangled);
    Delete(call);
    Delete(cres);
  } else {
    if (cplus) {
      String *call = Swig_cppdestructor_call(n);
      String *cres = NewStringf("%s\n", call);
      Setattr(n, k_wrapaction, cres);
      Delete(call);
      Delete(cres);
    } else {
      String *call = Swig_cdestructor_call(n);
      String *cres = NewStringf("%s\n", call);
      Setattr(n, k_wrapaction, cres);
      Delete(call);
      Delete(cres);
    }
  }
  Setattr(n, k_type, type);
  Setattr(n, k_parms, p);
  Delete(type);
  Delete(p);
  return SWIG_OK;
}
コード例 #12
0
static String *Swig_wrapped_var_deref(SwigType *t, String_or_char *name, int varcref) {
  if (SwigType_isclass(t)) {
    if (varcref) {
      if (cparse_cplusplus) {
	return NewStringf("*%s", name);
      } else {
	return NewStringf("%s", name);
      }
    } else {
      return NewStringf("*%s", name);
    }
  } else {
    return SwigType_rcaststr(t, name);
  }
}
コード例 #13
0
ファイル: tree.c プロジェクト: GSGroup/swig-v8
void Swig_restore(Node *n) {
  String *temp;
  int len;
  List *l;
  String *ns;
  Iterator ki;

  ns = Getattr(n, "view");
  assert(ns);

  l = NewList();

  temp = NewStringf("%s:", ns);
  len = Len(temp);

  for (ki = First(n); ki.key; ki = Next(ki)) {
    if (Strncmp(temp, ki.key, len) == 0) {
      Append(l, ki.key);
    }
  }
  for (ki = First(l); ki.item; ki = Next(ki)) {
    DOH *obj = Getattr(n, ki.item);
    Setattr(n, Char(ki.item) + len, obj);
    Delattr(n, ki.item);
  }
  Delete(l);
  Delete(temp);
}
コード例 #14
0
ファイル: stype.c プロジェクト: charlie5/swig4ada
static
void SwigType_add_default(String *def, SwigType *nr) {
  if (Strcmp(nr, "SWIGTYPE") == 0) {
    Append(def, "SWIGTYPE");
  } else {
    String *q = SwigType_isqualifier(nr) ? SwigType_pop(nr) : 0;
    if (q && strstr(Char(nr), "SWIGTYPE")) {
      Append(def, nr);
    } else {
      String *nd = SwigType_default(nr);
      if (nd) {
	String *bdef = nd;
	if (q) {
	  bdef = NewStringf("%s%s", q, nd);
	  if ((Strcmp(nr, bdef) == 0)) {
	    Delete(bdef);
	    bdef = nd;
	  } else {
	    Delete(nd);
	  }
	}
	Append(def, bdef);
	Delete(bdef);
      } else {
	Append(def, nr);
      }
    }
    Delete(q);
  }
}
コード例 #15
0
ファイル: cwrap.c プロジェクト: sunaku/swig-ruby-ffi
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;
}
コード例 #16
0
ファイル: cwrap.c プロジェクト: jumpinjackie/node-mapguide
String *
Swig_wrapped_var_deref(SwigType *t, String_or_char *name) {
  if (SwigType_isclass(t)) {
    return NewStringf("*%s",name);
  } else {
    return SwigType_rcaststr(t,name);
  }
}
コード例 #17
0
String *Swig_cparm_name(Parm *p, int i) {
  String *name = NewStringf("arg%d", i + 1);
  if (p) {
    Setattr(p, k_lname, name);
  }

  return name;
}
コード例 #18
0
ファイル: tree.c プロジェクト: GSGroup/swig-v8
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));
    }
  }
}
コード例 #19
0
ファイル: cwrap.c プロジェクト: jumpinjackie/node-mapguide
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);
}
コード例 #20
0
SwigType *SwigType_add_qualifier(SwigType *t, const_String_or_char_ptr qual) {
  String *newq;
  int sz, added = 0;
  char *q, *cqual;

  char *c = Char(t);
  cqual = Char(qual);

  if (!(strncmp(c, "q(", 2) == 0)) {
    String *temp = NewStringf("q(%s).", cqual);
    Insert(t, 0, temp);
    Delete(temp);
    return t;
  }

  /* The type already has a qualifier on it.  In this case, we first check to
     see if the qualifier is already specified.  In that case do nothing.
     If it is a new qualifier, we add it to the qualifier list in alphabetical
     order */

  sz = element_size(c);

  if (strstr(c, cqual)) {
    /* Qualifier already added */
    return t;
  }

  /* Add the qualifier to the existing list. */

  newq = NewString("q(");
  q = c + 2;
  q = strtok(q, " ).");
  while (q) {
    if (strcmp(cqual, q) < 0) {
      /* New qualifier is less that current qualifier.  We need to insert it */
      Append(newq, cqual);
      Append(newq, " ");
      Append(newq, q);
      added = 1;
    } else {
      Append(newq, q);
    }
    q = strtok(NULL, " ).");
    if (q) {
      Append(newq, " ");
    }
  }
  if (!added) {
    Append(newq, " ");
    Append(newq, cqual);
  }
  Append(newq, ").");
  Delslice(t, 0, sz);
  Insert(t, 0, newq);
  Delete(newq);
  return t;
}
コード例 #21
0
static void replace_nspace(String *name, const_String_or_char_ptr nspace) {
  if (nspace) {
    String *namspace = NewStringf("%s_", nspace);
    Replaceall(namspace, NSPACE_SEPARATOR, "_");
    Replace(name, "%n", namspace, DOH_REPLACE_ANY);
    Delete(namspace);
  } else {
    Replace(name, "%n", "", DOH_REPLACE_ANY);
  }
}
コード例 #22
0
ファイル: typeobj.c プロジェクト: 0xb1dd1e/swig
SwigType *SwigType_add_qualifier(SwigType *t, const_String_or_char_ptr qual) {
  List *qlist;
  String *allq, *newq;
  int i, sz;
  const char *cqprev = 0;
  const char *c = Char(t);
  const char *cqual = Char(qual);

  /* if 't' has no qualifiers and 'qual' is a single qualifier, simply add it */
  if ((strncmp(c, "q(", 2) != 0) && (strstr(cqual, " ") == 0)) {
    String *temp = NewStringf("q(%s).", cqual);
    Insert(t, 0, temp);
    Delete(temp);
    return t;
  }

  /* create string of all qualifiers */
  if (strncmp(c, "q(", 2) == 0) {
    allq = SwigType_parm(t);
    Append(allq, " ");
    SwigType_del_element(t);     /* delete old qualifier list from 't' */
  } else {
    allq = NewStringEmpty();
  }
  Append(allq, qual);

  /* create list of all qualifiers from string */
  qlist = Split(allq, ' ', INT_MAX);
  Delete(allq);

  /* sort in alphabetical order */
  SortList(qlist, Strcmp);

  /* create new qualifier string from unique elements of list */
  sz = Len(qlist);
  newq = NewString("q(");
  for (i = 0; i < sz; ++i) {
    String *q = Getitem(qlist, i);
    const char *cq = Char(q);
    if (cqprev == 0 || strcmp(cqprev, cq) != 0) {
      if (i > 0) {
        Append(newq, " ");
      }
      Append(newq, q);
      cqprev = cq;
    }
  }
  Append(newq, ").");
  Delete(qlist);

  /* replace qualifier string with new one */
  Insert(t, 0, newq);
  Delete(newq);
  return t;
}
コード例 #23
0
String *Swig_cppdestructor_call(Node *n) {
  String *unref = Swig_unref_call(n);
  if (unref) {
    return unref;
  } else {
    String *pname = Swig_cparm_name(0, 0);
    String *call = NewStringf("delete %s;", pname);
    Delete(pname);
    return call;
  }
}
コード例 #24
0
ファイル: cwrap.c プロジェクト: jumpinjackie/node-mapguide
int
Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags)
{
  SwigType *type;
  Parm     *p;
 
  type  = NewString(classname);
  SwigType_add_pointer(type);
  p = NewParm(type,"self");
  Delete(type);
  type = NewString("void");

  if (flags & CWRAP_EXTEND) {
    String *membername, *mangled, *code;
    membername = Swig_name_destroy(classname);
    mangled = Swig_name_mangle(membername);
    code = Getattr(n,"code");
    if (code) {
      String *s = NewStringf("void %s(%s)", mangled, ParmList_str(p));
      Printv(s,code,"\n",NIL);
      Setattr(n,"wrap:code",s);
      Delete(s);
    }
    Setattr(n,"wrap:action", NewStringf("%s;\n", Swig_cfunction_call(mangled,p)));
    Delete(membername);
    Delete(mangled);
  } else {
    if (cplus) {
      String* action = NewString("");
      Printf(action, "%s;\n", Swig_cppdestructor_call());
      Setattr(n,"wrap:action", action);
    } else {
      Setattr(n,"wrap:action", NewStringf("%s;\n", Swig_cdestructor_call()));
    }
  }
  Setattr(n,"type",type);
  Setattr(n,"parms", p);
  Delete(type);
  Delete(p);
  return SWIG_OK;
}
コード例 #25
0
ファイル: misc.c プロジェクト: JensMunkHansen/swig-matlab
String *Swig_new_subdirectory(String *basedirectory, String *subdirectory) {
  String *error = 0;
  struct stat st;
  int current_directory = basedirectory ? (Len(basedirectory) == 0 ? 1 : 0) : 0;

  if (current_directory || is_directory(basedirectory)) {
    Iterator it;
    String *dir = basedirectory ? NewString(basedirectory) : NewString("");
    List *subdirs = Split(subdirectory, SWIG_FILE_DELIMITER[0], INT_MAX);

    for (it = First(subdirs); it.item; it = Next(it)) {
      int statdir;
      String *subdirectory = it.item;
      Printf(dir, "%s", subdirectory);
      statdir = stat(Char(dir), &st);
      if (statdir == 0) {
	Printf(dir, SWIG_FILE_DELIMITER);
	if (S_ISDIR(st.st_mode)) {
	  continue;
	} else {
	  error = NewStringf("Cannot create directory %s", dir);
	  break;
	}
      } else {
#ifdef _WIN32
	int result = _mkdir(Char(dir));
#else
	int result = mkdir(Char(dir), 0777);
#endif
	Printf(dir, SWIG_FILE_DELIMITER);
	if (result != 0 && errno != EEXIST) {
	  error = NewStringf("Cannot create directory %s", dir);
	  break;
	}
      }
    }
  } else {
    error = NewStringf("Cannot create subdirectory %s under the base directory %s. Either the base does not exist as a directory or it is not readable.", subdirectory, basedirectory);
  }
  return error;
}
コード例 #26
0
void Swig_warn(const char *filename, int line, const char *msg) {
  String *key;
  if (!warnings) {
    warnings = NewHash();
  }
  key = NewStringf("%s:%d", filename, line);
  if (!Getattr(warnings, key)) {
    Printf(stderr, "swig-dev warning:%s:%d:%s\n", filename, line, msg);
    Setattr(warnings, key, key);
  }
  Delete(key);
}
コード例 #27
0
ファイル: misc.c プロジェクト: EemeliSyynimaa/yam2d
String *Swig_string_strip(String *s) {
  String *ns;
  if (!Len(s)) {
    ns = NewString(s);
  } else {
    const char *cs = Char(s);
    const char *ce = Strchr(cs, ']');
    if (*cs != '[' || !ce) {
      ns = NewString(s);
    } else {
      String *fmt = NewStringf("%%.%ds", ce-cs-1);
      String *prefix = NewStringf(fmt, cs+1);
      if (0 == Strncmp(ce+1, prefix, Len(prefix))) {
        ns = NewString(ce+1+Len(prefix));
      } else {
        ns = NewString(ce+1);
      }
    }
  }
  return ns;
}
コード例 #28
0
void Swig_name_object_inherit(Hash *namehash, String *base, String *derived) {
  Iterator ki;
  String *bprefix;
  String *dprefix;
  char *cbprefix;
  int plen;

  if (!namehash)
    return;

  bprefix = NewStringf("%s::", base);
  dprefix = NewStringf("%s::", derived);
  cbprefix = Char(bprefix);
  plen = strlen(cbprefix);
  for (ki = First(namehash); ki.key; ki = Next(ki)) {
    char *k = Char(ki.key);
    if (strncmp(k, cbprefix, plen) == 0) {
      Iterator oi;
      String *nkey = NewStringf("%s%s", dprefix, k + plen);
      Hash *n = ki.item;
      Hash *newh = Getattr(namehash, nkey);
      if (!newh) {
	newh = NewHash();
	Setattr(namehash, nkey, newh);
	Delete(newh);
      }
      for (oi = First(n); oi.key; oi = Next(oi)) {
	if (!Getattr(newh, oi.key)) {
	  String *ci = Copy(oi.item);
	  Setattr(newh, oi.key, ci);
	  Delete(ci);
	}
      }
      Delete(nkey);
    }
  }
  Delete(bprefix);
  Delete(dprefix);
}
コード例 #29
0
ファイル: tree.c プロジェクト: GSGroup/swig-v8
void Swig_save(const char *ns, Node *n, ...) {
  va_list ap;
  char *name;
  DOH *obj;

  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;

    /* Save a copy of the attribute */
    if (Setattr(n, NewStringf("%s:%s", ns, name), 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) {
	Setattr(n, NewStringf("%s:view", ns), view);
	Setattr(n, "view", NewString(ns));
      }
    } else {
      Setattr(n, "view", NewString(ns));
    }
  }
}
コード例 #30
0
ファイル: cwrap.c プロジェクト: jumpinjackie/node-mapguide
int
Swig_MembergetToFunction(Node *n, String *classname, int flags) {
  String   *name;
  ParmList *parms;
  SwigType *t;
  SwigType *ty;
  SwigType *type;
  String   *membername;
  String   *mangled;
  String   *self = 0;

  if (flags & CWRAP_SMART_POINTER) {
    self = NewString("(*this)->");
  }

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

  membername = Swig_name_member(classname, Swig_name_get(name));
  mangled = Swig_name_mangle(membername);

  t = NewString(classname);
  SwigType_add_pointer(t);
  parms = NewParm(t,"self");
  Delete(t);

  ty = Swig_wrapped_var_type(type);
  if (flags & CWRAP_EXTEND) {
    String *code = Getattr(n,"code");
    if (code) {
      String *tmp = NewStringf("%s(%s)", mangled, ParmList_str(parms));
      String *s = SwigType_str(ty,tmp);
      Delete(tmp);
      Printv(s,code,"\n",NIL);
      Setattr(n,"wrap:code",s);
      Delete(s);
    }
    Setattr(n,"wrap:action", Swig_cresult(ty,"result",Swig_cfunction_call(mangled,parms)));
  } else {
    Setattr(n,"wrap:action", Swig_cresult(ty,"result",Swig_cmemberget_call(name,type,self)));
  }
  Setattr(n,"type",ty);
  Setattr(n,"parms", parms);
  Delete(parms);
  Delete(ty);
  Delete(membername);
  Delete(mangled);
  return SWIG_OK;
}