コード例 #1
0
/* #define SWIG_FAST_REC_SEARCH 1 */
String *Swig_rflag_search(Node *n, const String *attr, const String *noattr) {
  String *f = 0;
  n = Swig_methodclass(n);
  if (GetFlag(n, noattr)) {
    return 0;
  }
  f = GetFlagAttr(n, attr);
  if (f) {
    return f;
  } else {
    List *bl = Getattr(n, k_bases);
    if (bl) {
      Iterator bi;
      for (bi = First(bl); bi.item; bi = Next(bi)) {
	f = Swig_rflag_search(bi.item, attr, noattr);
	if (f) {
#ifdef SWIG_FAST_REC_SEARCH
	  SetFlagAttr(n, attr, f);
#endif
	  return f;
	}
      }
    }
  }
#ifdef SWIG_FAST_REC_SEARCH
  SetFlag(n, noattr);
#endif
  return 0;
}
コード例 #2
0
String *Swig_ref_call(Node *n, const String *lname) {
  Node *cn = Swig_methodclass(n);
  String *ref = Swig_rflag_search(cn, "feature:ref", "feature:noref");
  if (ref) {
    ref = NewString(ref);
    Replaceall(ref, "$this", lname);
    Replaceall(ref, "$self", lname);
  }
  return ref;
}
コード例 #3
0
String *Swig_unref_call(Node *n) {
  Node *cn = Swig_methodclass(n);
  String *unref = Swig_rflag_search(cn, "feature:unref", "feature:nounref");
  if (unref) {
    String *pname = Swig_cparm_name(0, 0);
    unref = NewString(unref);
    Replaceall(unref, "$this", pname);
    Replaceall(unref, "$self", pname);
    Delete(pname);
  }
  return unref;
}
コード例 #4
0
ファイル: cwrap.c プロジェクト: jumpinjackie/node-mapguide
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;
}
コード例 #5
0
int Swig_directorclass(Node *n) {
  Node *classNode = Swig_methodclass(n);
  assert(classNode != 0);
  return (Getattr(classNode, k_vtable) != 0);
}
コード例 #6
0
int Swig_ConstructorToFunction(Node *n, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags) {
  ParmList *parms;
  Parm *prefix_args;
  Parm *p;
  ParmList *directorparms;
  SwigType *type;
  Node *classNode;
  int use_director;

  classNode = Swig_methodclass(n);
  use_director = Swig_directorclass(n);

  parms = CopyParmList(nonvoid_parms(Getattr(n, k_parms)));

  /* Prepend the list of prefix_args (if any) */
  prefix_args = Getattr(n, k_directorprefixargs);
  if (prefix_args != NIL) {
    Parm *p2, *p3;

    directorparms = CopyParmList(prefix_args);
    for (p = directorparms; nextSibling(p); p = nextSibling(p));
    for (p2 = parms; p2; p2 = nextSibling(p2)) {
      p3 = CopyParm(p2);
      set_nextSibling(p, p3);
      Delete(p3);
      p = p3;
    }
  } else
    directorparms = parms;

  type = NewString(classname);
  SwigType_add_pointer(type);

  if (flags & CWRAP_EXTEND) {
    /* Constructors with default arguments are wrapped with additional constructor methods for each default argument,
     * however, only one extra %extend method is generated. */
    String *call;
    String *cres;
    String *defaultargs = Getattr(n, k_defaultargs);
    String *code = Getattr(n, k_code);
    String *membername = Swig_name_construct(classname);
    String *mangled = Swig_name_mangle(membername);

    /* Check if the constructor is overloaded.   If so, and it has code attached, we append an extra suffix
       to avoid a name-clash in the generated wrappers.  This allows overloaded constructors to be defined
       in C. */
    if (Getattr(n, k_symoverloaded) && code) {
      Append(mangled, Getattr(defaultargs ? defaultargs : n, k_symovername));
    }

    /* See if there is any code that we need to emit */
    if (!defaultargs && code) {
      Swig_add_extension_code(n, mangled, parms, type, code, cparse_cplusplus, k_self);
    }

    call = Swig_cfunction_call(mangled, parms);
    cres = Swig_cresult(type, k_result, call);
    Setattr(n, k_wrapaction, cres);
    Delete(cres);
    Delete(call);
    Delete(membername);
    Delete(mangled);
  } else {
    if (cplus) {
      /* if a C++ director class exists, create it rather than the original class */
      if (use_director) {
	Node *parent = Swig_methodclass(n);
	int abstract = Getattr(parent, k_abstract) != 0;
	String *name = Getattr(parent, k_symname);
	String *directorname = NewStringf("SwigDirector_%s", name);
	String *action = NewStringEmpty();
	String *tmp_none_comparison = Copy(none_comparison);
	String *director_call;
	String *nodirector_call;

	Replaceall(tmp_none_comparison, "$arg", "arg1");

	director_call = Swig_cppconstructor_director_call(directorname, directorparms);
	nodirector_call = Swig_cppconstructor_nodirector_call(classname, parms);

	if (abstract) {
	  /* whether or not the abstract class has been subclassed in python,
	   * create a director instance (there's no way to create a normal
	   * instance).  if any of the pure virtual methods haven't been
	   * implemented in the target language, calls to those methods will
	   * generate Swig::DirectorPureVirtualException exceptions.
	   */
	  String *cres = Swig_cresult(type, k_result, director_call);
	  Append(action, cres);
	  Delete(cres);
	} else {
	  /* (scottm): The code for creating a new director is now a string
	     template that gets passed in via the director_ctor argument.

	     $comparison : an 'if' comparison from none_comparison
	     $director_new: Call new for director class
	     $nondirector_new: Call new for non-director class
	   */
	  String *cres;
	  Append(action, director_ctor);
	  Replaceall(action, "$comparison", tmp_none_comparison);

	  cres = Swig_cresult(type, k_result, director_call);
	  Replaceall(action, "$director_new", cres);
	  Delete(cres);

	  cres = Swig_cresult(type, k_result, nodirector_call);
	  Replaceall(action, "$nondirector_new", cres);
	  Delete(cres);
	}
	Setattr(n, k_wrapaction, action);
	Delete(tmp_none_comparison);
	Delete(action);
	Delete(directorname);
      } else {
	String *call = Swig_cppconstructor_call(classname, parms);
	String *cres = Swig_cresult(type, k_result, call);
	Setattr(n, k_wrapaction, cres);
	Delete(cres);
	Delete(call);
      }
    } else {
      String *call = Swig_cconstructor_call(classname);
      String *cres = Swig_cresult(type, k_result, call);
      Setattr(n, k_wrapaction, cres);
      Delete(cres);
      Delete(call);
    }
  }
  Setattr(n, k_type, type);
  Setattr(n, k_parms, parms);
  Delete(type);
  if (directorparms != parms)
    Delete(directorparms);
  Delete(parms);
  return SWIG_OK;
}
コード例 #7
0
ファイル: cwrap.c プロジェクト: jumpinjackie/node-mapguide
int
Swig_ConstructorToFunction(Node *n, String *classname, 
			   String *none_comparison, String *director_ctor, int cplus, int flags)
{
  ParmList *parms;
  Parm     *prefix_args;
  Parm     *postfix_args;
  Parm     *p;
  ParmList *directorparms;
  SwigType *type;
  String   *membername;
  String   *mangled;
  Node     *classNode;
  int      use_director;
  
  classNode = Swig_methodclass(n);
  use_director = Swig_directorclass(n);

  membername = Swig_name_construct(classname);
  mangled = Swig_name_mangle(membername);

  parms = CopyParmList(nonvoid_parms(Getattr(n,"parms")));

  /* Prepend the list of prefix_args (if any) */
  prefix_args = Getattr(n,"director:prefix_args");
  if (prefix_args != NIL) {
    Parm *p2, *p3;

    directorparms = CopyParmList(prefix_args);
    for (p = directorparms; nextSibling(p); p = nextSibling(p));
    for (p2 = parms; p2; p2 = nextSibling(p2)) {
      p3 = CopyParm(p2);
      set_nextSibling(p, p3);
      p = p3;
    }
  } else
    directorparms = parms;

  postfix_args = Getattr(n,"director:postfix_args");
  if (postfix_args != NIL) {
    Parm *p2, *p3, *p4;

    if (prefix_args == NIL) /* no prefix args from above. */
      directorparms = CopyParmList(parms);

    if (directorparms != NIL) {
      p2 = directorparms;
      for ( ; nextSibling(p2); p2 = nextSibling(p2));
      for (p3 = postfix_args; p3; p3 = nextSibling(p3)) {
        p4 = CopyParm(p3);
        set_nextSibling(p2, p4);
        p2 = p4;
      }
    } else
      directorparms = CopyParmList(postfix_args);
  }

  type  = NewString(classname);
  SwigType_add_pointer(type);

  if (flags & CWRAP_EXTEND) {
    String *code = Getattr(n,"code");
    if (code) {
      String *wrap, *s;
      if (Getattr(n,"sym:overloaded") && code) {
	Append(mangled,Getattr(n,"sym:overname"));
      }
      s = NewStringf("%s(%s)", mangled, ParmList_str(parms));
      wrap = SwigType_str(type,s);
      Delete(s);
      Printv(wrap,code,"\n",NIL);
      Setattr(n,"wrap:code",wrap);
      Delete(wrap);
    }
    Setattr(n,"wrap:action", Swig_cresult(type,"result", Swig_cfunction_call(mangled,parms)));
  } else {
    if (cplus) {
      /* if a C++ director class exists, create it rather than the original class */
      if (use_director) {
  	int abstract = Getattr(n, "abstract") != 0;
	Node *parent = Swig_methodclass(n);
	String *name = Getattr(parent, "sym:name");
        String* directorname = NewStringf("SwigDirector_%s", name);
	String* action = NewString("");
	String* tmp_none_comparison = Copy(none_comparison);
	String* director_call;
	String* nodirector_call;
	
	Replaceall( tmp_none_comparison, "$arg", "arg1" );

	director_call = Swig_cppconstructor_director_call(directorname, directorparms);
	nodirector_call = Swig_cppconstructor_nodirector_call(classname, parms);

	if (abstract) {
	  /* whether or not the abstract class has been subclassed in python,
	   * create a director instance (there's no way to create a normal
	   * instance).  if any of the pure virtual methods haven't been
	   * implemented in the target language, calls to those methods will
	   * generate Swig::DirectorPureVirtualException exceptions.
	   */
	  Printv(action, Swig_cresult(type, "result", director_call), NIL);
	} else {
	  /* (scottm): The code for creating a new director is now a string
	     template that gets passed in via the director_ctor argument.

	     $comparison : an 'if' comparison from none_comparison
	     $director_new: Call new for director class
	     $nondirector_new: Call new for non-director class
	   */
	  Printv(action, director_ctor, NIL);
	  Replaceall( action, "$comparison", tmp_none_comparison);
	  Replaceall( action, "$director_new", 
		      Swig_cresult(type, "result", director_call) );
	  Replaceall( action, "$nondirector_new", 
		      Swig_cresult(type, "result", nodirector_call) );
	}
	Setattr(n, "wrap:action", action);
	Delete(tmp_none_comparison);
	Delete(action);
        Delete(directorname);
      } else {
        Setattr(n,"wrap:action", Swig_cresult(type,"result", Swig_cppconstructor_call(classname,parms)));
      }
    } else {
      Setattr(n,"wrap:action", Swig_cresult(type,"result", Swig_cconstructor_call(classname)));
    }
  }
  Setattr(n,"type",type);
  Setattr(n,"parms", parms);
  Delete(type);
  if (directorparms != parms)
    Delete(directorparms);
  Delete(parms);
  Delete(mangled);
  Delete(membername);
  return SWIG_OK;
}
コード例 #8
0
ファイル: cwrap.c プロジェクト: jumpinjackie/node-mapguide
int
Swig_directorbase(Node *n) {
  Node *classNode = Swig_methodclass(n);
  return (classNode && (Getattr(classNode, "directorBase") != 0));
}