示例#1
0
 public static bool Tcl_SetCommandInfo(Interp interp, string command, WrappedCommand value)
 {
     try
     {
         value = interp.getObjCommand(command);
         return(false);
     }
     catch
     {
         return(true);
     }
 }
        /// <summary>----------------------------------------------------------------------
        ///
        /// disposeCmd --
        ///
        /// Invoked when an object command for a slave interpreter is deleted;
        /// cleans up all state associated with the slave interpreter and destroys
        /// the slave interpreter.
        ///
        /// Results:
        /// None.
        ///
        /// Side effects:
        /// Cleans up all state associated with the slave interpreter and
        /// destroys the slave interpreter.
        ///
        /// ----------------------------------------------------------------------
        /// </summary>

        public void  disposeCmd()
        {
            // Unlink the slave from its master interpreter.

            SupportClass.HashtableRemove(masterInterp.slaveTable, path);

            // Set to null so that when the InterpInfo is cleaned up in the slave
            // it does not try to delete the command causing all sorts of grief.
            // See SlaveRecordDeleteProc().

            interpCmd = null;

            if (slaveInterp != null)
            {
                slaveInterp.dispose();
            }
        }
示例#3
0
        internal static bool isProc(WrappedCommand cmd)
        {
            return(cmd.cmd is Procedure);

            /*
             * // FIXME: do we really want to get the original command
             * // and test that? Methods like InfoCmd.InfoProcsCmd seem
             * // to do this already.
             *
             * WrappedCommand origCmd;
             *
             * origCmd = NamespaceCmd.getOriginalCommand(cmd);
             * if (origCmd != null) {
             * cmd = origCmd;
             * }
             * return (cmd.cmd instanceof Procedure);
             */
        }
示例#4
0
    /// <summary>----------------------------------------------------------------------
    /// 
    /// disposeCmd --
    /// 
    /// Invoked when an object command for a slave interpreter is deleted;
    /// cleans up all state associated with the slave interpreter and destroys
    /// the slave interpreter.
    /// 
    /// Results:
    /// None.
    /// 
    /// Side effects:
    /// Cleans up all state associated with the slave interpreter and
    /// destroys the slave interpreter.
    /// 
    /// ----------------------------------------------------------------------
    /// </summary>

    public void disposeCmd()
    {
      // Unlink the slave from its master interpreter.

      SupportClass.HashtableRemove( masterInterp.slaveTable, path );

      // Set to null so that when the InterpInfo is cleaned up in the slave
      // it does not try to delete the command causing all sorts of grief.
      // See SlaveRecordDeleteProc().

      interpCmd = null;

      if ( slaveInterp != null )
      {
        slaveInterp.dispose();
      }
    }
    internal static bool isProc( WrappedCommand cmd )
    {
      return ( cmd.cmd is Procedure );

      /*
      // FIXME: do we really want to get the original command
      // and test that? Methods like InfoCmd.InfoProcsCmd seem
      // to do this already.
			
      WrappedCommand origCmd;
			
      origCmd = NamespaceCmd.getOriginalCommand(cmd);
      if (origCmd != null) {
      cmd = origCmd;
      }
      return (cmd.cmd instanceof Procedure);
      */
    }
    public void createObjCommand( string cmdName, dxObjCmdProc proc, object clientData, dxCmdDeleteProc deleteProc )
    // Command object to associate with cmdName.
    {
      ImportRef oldRef = null;
      NamespaceCmd.Namespace ns;
      WrappedCommand cmd, refCmd;
      string tail;
      ImportedCmdData data;
      int _new;

      if ( deleted )
      {
        // The interpreter is being deleted.  Don't create any new
        // commands; it's not safe to muck with the interpreter anymore.

        return;
      }

      // Determine where the command should reside. If its name contains 
      // namespace qualifiers, we put it in the specified namespace; 
      // otherwise, we always put it in the global namespace.

      if ( cmdName.IndexOf( "::" ) != -1 )
      {
        // Java does not support passing an address so we pass
        // an array of size 1 and then assign arr[0] to the value
        NamespaceCmd.Namespace[] nsArr = new NamespaceCmd.Namespace[1];
        NamespaceCmd.Namespace[] dummyArr = new NamespaceCmd.Namespace[1];
        string[] tailArr = new string[1];

        NamespaceCmd.getNamespaceForQualName( this, cmdName, null, TCL.VarFlag.CREATE_NS_IF_UNKNOWN, nsArr, dummyArr, dummyArr, tailArr );

        ns = nsArr[0];
        tail = tailArr[0];

        if ( ( ns == null ) || ( (System.Object)tail == null ) )
        {
          return;
        }
      }
      else
      {
        ns = globalNs;
        tail = cmdName;
      }

      cmd = (WrappedCommand)ns.cmdTable[tail];
      if ( cmd != null )
      {
        /*
 * Command already exists. If its object-based Tcl_ObjCmdProc is
 * TclInvokeStringCommand, we just set its Tcl_ObjCmdProc to the
 * argument "proc". Otherwise, we delete the old command. 
 */
        if ( cmd.objProc != null && cmd.objProc.GetType().Name == "TclInvokeStringCommand" )
        {
          cmd.objProc = proc;
          cmd.objClientData = clientData;
          cmd.deleteProc = deleteProc;
          cmd.deleteData = clientData;
          return;
        }
        /*
         * Otherwise, we delete the old command.  Be careful to preserve
         * any existing import links so we can restore them down below.
         * That way, you can redefine a command and its import status
         * will remain intact.
         */
        oldRef = cmd.importRef;
        cmd.importRef = null;

        deleteCommandFromToken( cmd );

        // FIXME : create a test case for this condition!

        cmd = (WrappedCommand)ns.cmdTable[tail];
        if ( cmd != null )
        {
          // If the deletion callback recreated the command, just throw
          // away the new command (if we try to delete it again, we
          // could get stuck in an infinite loop).

          SupportClass.HashtableRemove( cmd.table, cmd.hashKey );
        }
      }

      cmd = new WrappedCommand();
      ns.cmdTable.Add( tail, cmd );
      cmd.table = ns.cmdTable;
      cmd.hashKey = tail;
      cmd.ns = ns;
      cmd.cmd = null;
      cmd.deleted = false;
      // FIXME : import feature not implemented
      //cmd.importRef = null;

      // TODO -- Determine if this is all correct
      cmd.objProc = proc;
      cmd.objClientData = clientData;
      //cmd.proc = TclInvokeObjectCommand;
      cmd.clientData = (object)cmd;
      cmd.deleteProc = deleteProc;
      cmd.deleteData = clientData;
      cmd.flags = 0;


      // Plug in any existing import references found above.  Be sure
      // to update all of these references to point to the new command.

      if ( oldRef != null )
      {
        cmd.importRef = oldRef;
        while ( oldRef != null )
        {
          refCmd = oldRef.importedCmd;
          data = (ImportedCmdData)refCmd.cmd;
          data.realCmd = cmd;
          oldRef = oldRef.next;
        }
      }

      // There are no shadowed commands in Jacl because they are only
      // used in the 8.0 compiler

      return;
    }
    internal void preventAliasLoop( Interp cmdInterp, WrappedCommand cmd )
    {
      // If we are not creating or renaming an alias, then it is
      // always OK to create or rename the command.

      if ( !( cmd.cmd is InterpAliasCmd ) )
      {
        return;
      }

      // OK, we are dealing with an alias, so traverse the chain of aliases.
      // If we encounter the alias we are defining (or renaming to) any in
      // the chain then we have a loop.

      InterpAliasCmd alias = (InterpAliasCmd)cmd.cmd;
      InterpAliasCmd nextAlias = alias;
      while ( true )
      {

        // If the target of the next alias in the chain is the same as
        // the source alias, we have a loop.

        WrappedCommand aliasCmd = nextAlias.getTargetCmd( this );
        if ( aliasCmd == null )
        {
          return;
        }
        if ( aliasCmd.cmd == cmd.cmd )
        {

          throw new TclException( this, "cannot define or rename alias \"" + alias.name + "\": would create a loop" );
        }

        // Otherwise, follow the chain one step further. See if the target
        // command is an alias - if so, follow the loop to its target
        // command. Otherwise we do not have a loop.

        if ( !( aliasCmd.cmd is InterpAliasCmd ) )
        {
          return;
        }
        nextAlias = (InterpAliasCmd)aliasCmd.cmd;
      }
    }
    protected internal int deleteCommandFromToken( WrappedCommand cmd )
    // Wrapper Token for command to delete.
    {
      if ( cmd == null )
      {
        return -1;
      }

      ImportRef ref_Renamed, nextRef;
      WrappedCommand importCmd;

      // The code here is tricky.  We can't delete the hash table entry
      // before invoking the deletion callback because there are cases
      // where the deletion callback needs to invoke the command (e.g.
      // object systems such as OTcl). However, this means that the
      // callback could try to delete or rename the command. The deleted
      // flag allows us to detect these cases and skip nested deletes.

      if ( cmd.deleted )
      {
        // Another deletion is already in progress.  Remove the hash
        // table entry now, but don't invoke a callback or free the
        // command structure.

        if ( (System.Object)cmd.hashKey != null && cmd.table != null )
        {
          SupportClass.HashtableRemove( cmd.table, cmd.hashKey );
          cmd.table = null;
          cmd.hashKey = null;
        }
        return 0;
      }

      cmd.deleted = true;
      if ( cmd.cmd is CommandWithDispose )
      {
        ( (CommandWithDispose)cmd.cmd ).disposeCmd();
      }
      if ( cmd.deleteProc != null )
      {
        cmd.deleteProc( ref cmd.objClientData );
      }
      // If this command was imported into other namespaces, then imported
      // commands were created that refer back to this command. Delete these
      // imported commands now.

      for ( ref_Renamed = cmd.importRef; ref_Renamed != null; ref_Renamed = nextRef )
      {
        nextRef = ref_Renamed.next;
        importCmd = ref_Renamed.importedCmd;
        deleteCommandFromToken( importCmd );
      }

      // FIXME : what does this mean? Is this a mistake in the C comment?

      // Don't use hPtr to delete the hash entry here, because it's
      // possible that the deletion callback renamed the command.
      // Instead, use cmdPtr->hptr, and make sure that no-one else
      // has already deleted the hash entry.

      if ( cmd.table != null )
      {
        SupportClass.HashtableRemove( cmd.table, cmd.hashKey );
        cmd.table = null;
        cmd.hashKey = null;
      }

      // Drop the reference to the Command instance inside the WrappedCommand

      cmd.cmd = null;

      // We do not need to cleanup the WrappedCommand because GC will get it.

      return 0;
    }
    internal string getCommandFullName( WrappedCommand cmd )
    // Token for the command.
    {
      Interp interp = this;
      StringBuilder name = new StringBuilder();

      // Add the full name of the containing namespace, followed by the "::"
      // separator, and the command name.

      if ( cmd != null )
      {
        if ( cmd.ns != null )
        {
          name.Append( cmd.ns.fullName );
          if ( cmd.ns != interp.globalNs )
          {
            name.Append( "::" );
          }
        }
        if ( cmd.table != null )
        {
          name.Append( cmd.hashKey );
        }
      }

      return name.ToString();
    }
示例#10
0
		/*
		*----------------------------------------------------------------------
		*
		* TclGetOriginalCommand -> getOriginalCommand
		*
		*	An imported command is created in a namespace when a "real" command
		*	is imported from another namespace. If the specified command is an
		*	imported command, this procedure returns the original command it
		*	refers to.
		*
		* Results:
		*	If the command was imported into a sequence of namespaces a, b,...,n
		*	where each successive namespace just imports the command from the
		*	previous namespace, this procedure returns the Tcl_Command token in
		*	the first namespace, a. Otherwise, if the specified command is not
		*	an imported command, the procedure returns null.
		*
		* Side effects:
		*	None.
		*
		*----------------------------------------------------------------------
		*/
		
		internal static WrappedCommand getOriginalCommand(WrappedCommand command)
		{
			WrappedCommand cmd = command;
			ImportedCmdData data;
			
			if (!(cmd.cmd is ImportedCmdData))
			{
				return null;
			}
			
			while (cmd.cmd is ImportedCmdData)
			{
				data = (ImportedCmdData) cmd.cmd;
				cmd = data.realCmd;
			}
			return cmd;
		}
示例#11
0
 static object sqlite3TestTextToPtr( Tcl_Interp interp, string z )
 {
   //object p ;
   //u64[] v = new u64[1];
   //u32 v2;
   //int zIndex = 0;
   //if ( z[0] == '0' && z[1] == 'x' )
   //{
   //  zIndex += 2;
   //}
   //v[0] = 0;
   //while ( zIndex < z.Length )* z )
   //{
   //  v[0] = ( v[0] << 4 ) + (ulong)testHexToInt( z[zIndex] );
   //  zIndex++;
   //}
   //if ( sizeof( object ) == sizeof( u64 ) )
   //{
   //  Marshal.Copy( v, 0, (IntPtr)p, 1 );// memcpy( &p, v, sizeof( p ) );
   //}
   //else
   //{
   //  Debug.Assert( sizeof( p ) == sizeof( v2 ) );
   //  v2 = (u32)v;
   //  memcpy( &p, v2, sizeof( p ) );
   //}
   WrappedCommand cmdInfo = new WrappedCommand();
   if ( TCL.Tcl_GetCommandInfo( interp, z, ref cmdInfo ) || cmdInfo == null )
   { return null; }
   else
   {
     return cmdInfo.objClientData;
   }
 }
示例#12
0
 /*
 ** Decode a pointer to an sqlite3_stmt object.
 */
 static int getStmtPointer(
 Tcl_Interp interp,
 string zArg,
 ref sqlite3_stmt ppStmt
 )
 {
   ppStmt = (sqlite3_stmt)sqlite3TestTextToPtr( interp, zArg );
   WrappedCommand cmdInfo = new WrappedCommand();
   if ( !TCL.Tcl_GetCommandInfo( interp, zArg, ref cmdInfo ) )
   {
     ppStmt = cmdInfo == null ? null : (sqlite3_stmt)cmdInfo.objClientData; ;
   }
   else
   {
     Debugger.Break();
   }
   return TCL.TCL_OK;
 }
示例#13
0
 /*
 ** Decode a pointer to an sqlite3 object.
 */
 static int getDbPointer( Tcl_Interp interp, string zA, ref sqlite3 ppDb )
 {
   SqliteDb p;
   WrappedCommand cmdInfo = new WrappedCommand();
   if ( !TCL.Tcl_GetCommandInfo( interp, zA, ref cmdInfo ) )
   {
     if ( cmdInfo == null )
     {
       ppDb = new sqlite3();
     }
     else
     {
       p = (SqliteDb)cmdInfo.objClientData;
       ppDb = p.db;
     }
   }
   else
   {
     Debugger.Break();// ppDb = (sqlite3)sqlite3TestTextToPtr( zA );
   }
   return TCL.TCL_OK;
 }
示例#14
0
    /*
    ** Decode a pointer to an sqlite3_stmt object.
    */
    static int getStmtPointer(
    Tcl_Interp interp,
    string zArg,
    out sqlite3_stmt ppStmt
    )
    {
      ppStmt = (sqlite3_stmt)sqlite3TestTextToPtr( interp, zArg );
      WrappedCommand cmdInfo = new WrappedCommand();
      TCL.Tcl_GetCommandInfo( interp, zArg, out cmdInfo );
      ppStmt = cmdInfo == null ? null : (sqlite3_stmt)cmdInfo.objClientData;

      return TCL.TCL_OK;
    }
示例#15
0
 /*
 ** Decode a pointer to an sqlite3 object.
 */
 static int getDbPointer( Tcl_Interp interp, string zA, out sqlite3 ppDb )
 {
   SqliteDb p;
   WrappedCommand cmdInfo = new WrappedCommand();
   if ( !TCL.Tcl_GetCommandInfo( interp, zA, out cmdInfo ) )
   {
     if ( cmdInfo == null )
     {
       ppDb = new sqlite3();
     }
     else
     {
       p = (SqliteDb)cmdInfo.objClientData;
       ppDb = p.db;
     }
   }
   else
   {
     ppDb = null;
   }
   return TCL.TCL_OK;
 }