⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jstree.cpp

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    return 0;}/********************************************************** * * JSStatement * *********************************************************/JSStatement::JSStatement( JSNode *_code, JSNode *_next_code ) : JSNode(){    code = _code;    nextCode = _next_code;}int JSStatement::rightValue( JSScopeStack *_scopes, JSValue *_rv ){    int ret = 0;        if ( code )    {	ret = code->rightValue( _scopes, _rv );	if ( ret )	    return ret;    }        if ( nextCode )	ret = nextCode->rightValue( _scopes, _rv );        return ret;}/********************************************************** * * JSFunction * *********************************************************/JSFunction::JSFunction( const char *_name, JSParameter* _param, JSNode *_code ) : JSNode(){    parameters = _param;    code = _code;    name = _name;}int JSFunction::rightValue( JSScopeStack* , JSValue *rv ){    // This is NOT a call to this function. The programmer just wants a    // reference to this function ( read: pointer ).    JSFunctionObject *func = new JSFunctionObject( this );        rv->setObject( func );    rv->setAutoDelete( TRUE );    rv->setLeftValue( FALSE );        return 0;}int JSFunction::rightValue( JSScopeStack *_scopes, JSValue *_rv, JSParameterListObject* ){    // TODO: Scope change and fill parameters    return code->rightValue( _scopes, _rv );}/********************************************************** * * JSParameter * *********************************************************/JSParameter::JSParameter( const char *_name, JSParameter *_next ){    name = _name;    nextParameter = _next;}/********************************************************** * * JSFunctionCall * *********************************************************/JSFunctionCall::JSFunctionCall( JSNode *_function, JSArgument *_arguments ){    function = _function;    arguments = _arguments;}int JSFunctionCall::rightValue( JSScopeStack* _scopes, JSValue *rv ){    int ret = 0;        JSValue v;    ret = function->rightValue( _scopes, &v );    if ( ret )	return ret;    if ( ! v.getObject()->inherits( TYPE_JSFunctionObject ) )    {	printf("isA=%i\n",v.getObject()->isA());	return ERROR_JSNotAFunction;    }        JSParameterListObject param;    if ( arguments )    {	ret = arguments->rightValue( _scopes, &param );	if ( ret )	    return ret;    }        JSFunctionObject *func = (JSFunctionObject*)( v.getObject() );    // Add new temporary scope    _scopes->pushScope( new JSScope() );    if ( func->getObject() )    {	// Add obj to scope	_scopes->pushInstanceScope( func->getObject()->getScope() );    }        ret = func->getFunction()->rightValue( _scopes, rv, &param );    if ( func->getObject() )    {	// Remove obj from scope	_scopes->popInstanceScope();    }      // Remove temporary scope    _scopes->popScope();    return ret;}/********************************************************** * * JSConstructorCall * *********************************************************/JSConstructorCall::JSConstructorCall( JSNode *_function, JSArgument *_arguments ){    function = _function;    arguments = _arguments;}int JSConstructorCall::rightValue( JSScopeStack* _scopes, JSValue *rv ){    int ret = 0;        JSValue v;    ret = function->rightValue( _scopes, &v );    if ( ret )	return ret;    if ( ! v.getObject()->inherits( TYPE_JSFunctionObject ) )	return ERROR_JSNotAFunction;        JSParameterListObject param;    if ( arguments )    {	ret = arguments->rightValue( _scopes, &param );	if ( ret )	    return ret;    }    JSFunctionObject *func = (JSFunctionObject*)( v.getObject() );    JSUserDefinedObject *obj = new JSUserDefinedObject();    // Add obj to scope    _scopes->pushInstanceScope( obj->getScope() );    // Add new temporary scope    _scopes->pushScope( new JSScope() );        ret = func->getFunction()->rightValue( _scopes, &v, &param );    if ( ret )    {	delete obj;	return ret;    }    // Remove temporary scope    _scopes->popScope();    // Remove obj from scope    _scopes->popInstanceScope();        rv->setObject( obj );    rv->setAutoDelete( TRUE );    rv->setLeftValue( FALSE );    return ret;}/********************************************************** * * JSArgument * *********************************************************/JSArgument::JSArgument( JSNode *_code, JSArgument *_next ) : JSNode(){    code = _code;    nextArgument = _next;}int JSArgument::rightValue( JSScopeStack *_scopes, JSParameterListObject *_param ){    int ret = 0;        JSValue *v = new JSValue();    ret = code->rightValue( _scopes, v );    if ( ret )	return ret;        _param->appendValue( v );        if ( nextArgument )	ret = nextArgument->rightValue( _scopes, _param );        return ret;}/********************************************************** * * JSThis * *********************************************************/JSThis::JSThis() : JSNode(){}int JSThis::rightValue( JSScopeStack* _scopes, JSValue *rv ){    int ret = 0;        JSInstanceScope *s = _scopes->topInstanceScope();    if ( s == 0L )	return ERROR_JSNoInstance;	    rv->setObject( s->getObject() );    rv->setAutoDelete( FALSE );    rv->setLeftValue( FALSE );        return ret;}/********************************************************** * * JSMember * *********************************************************/JSMember::JSMember( JSNode *_obj, const char *_name ){    object = _obj;    name = _name;}JSMember::~JSMember(){    if ( object ) 	delete object;}    int JSMember::rightValue( JSScopeStack* _s, JSValue *rv ){    int ret = 0;        JSValue v;    ret = object->rightValue( _s, &v );    if ( ret )	return ret;        if ( ! v.getObject()->inherits( TYPE_JSUserDefinedObject ) )	return ERROR_JSUnknownIdentifier;        JSInstanceScope *s = ((JSUserDefinedObject*)v.getObject())->getScope();    // Test for variables.    // Mention that variables may be function pointers, too.    JSVariableObject* var = s->findVariable( name );    if ( var )    {	// Is it a reference to a function ?	if ( var->getValue()->inherits( TYPE_JSFunctionObject ) )	{	    JSFunctionObject *f = (JSFunctionObject*)( var->getValue()->copy() );	    f->setObject( (JSUserDefinedObject*)(v.getObject()) );	    rv->setObject( f );	    rv->setAutoDelete( TRUE );	    rv->setLeftValue( FALSE );	    return ret;	}	// It is a usual variable	rv->setObject( var->getValue() );	if ( var->isDynamic() )	    rv->setAutoDelete( TRUE );	else	    rv->setAutoDelete( FALSE );	rv->setLeftValue( FALSE );	return ret;    }    // Test for hard coded functions    JSFunctionObject* func = s->findFunction( name );    if ( !func )	return ERROR_JSUnknownIdentifier;    rv->setObject( func );    rv->setAutoDelete( FALSE );    rv->setLeftValue( FALSE );        return ret;}int JSMember::leftValue( JSScopeStack* _s, JSValue *rv ){    int ret = 0;        JSValue v;    ret = object->rightValue( _s, &v );    if ( ret )	return ret;        if ( ! v.getObject()->inherits( TYPE_JSUserDefinedObject ) )	return ERROR_JSUnknownIdentifier;        JSInstanceScope *s = ((JSUserDefinedObject*)v.getObject())->getScope();    // Test for variables.    // Mention that variables may be function pointers, too.    JSVariableObject* var = s->findVariable( name );    if ( var )    {	rv->setObject( var );	rv->setAutoDelete( FALSE );	rv->setLeftValue( TRUE );	return ret;    }    // Hard coded functions can not be overwritten    JSFunctionObject* func = s->findFunction( name );    if ( func )    {	rv->setObject( func );	rv->setAutoDelete( FALSE );	rv->setLeftValue( FALSE );	return ERROR_JSNotALeftValue;    }        // Insert new variable    s->insertObject( var = new JSVariableObject() );    var->setName( name );    rv->setObject( var );    rv->setAutoDelete( FALSE );    rv->setLeftValue( TRUE );        return ret;}/********************************************************** * * JSString * *********************************************************/JSString::JSString( const char *_string ){    object = new JSStringObject( _string );}JSString::~JSString(){    delete object;}int JSString::rightValue( JSScopeStack* , JSValue *rv ){    int ret = 0;     rv->setObject( object );    rv->setLeftValue( FALSE );    rv->setAutoDelete( FALSE );        return ret;}/********************************************************** * * JSNull * *********************************************************/JSNull::JSNull(){    object = new JSObject();}JSNull::~JSNull(){    delete object;}int JSNull::rightValue( JSScopeStack*, JSValue *rv ){    int ret = 0;     rv->setObject( object );    rv->setLeftValue( FALSE );    rv->setAutoDelete( FALSE );        return ret;}/********************************************************** * * JSArrayAccess * *********************************************************/JSArrayAccess::JSArrayAccess( JSNode *_array, JSNode *_index ){    array = _array;    index = _index;}int JSArrayAccess::rightValue( JSScopeStack* _scopes, JSValue *rv ){    int ret = 0;        JSValue v;    ret = array->rightValue( _scopes, &v );    if ( ret )	return ret;    if ( ! v.getObject()->inherits( TYPE_JSAbstractArrayObject ) )    {	printf("isA=%i\n",v.getObject()->isA());	return ERROR_JSNotAFunction;    }            JSAbstractArrayObject *a = (JSAbstractArrayObject*)( v.getObject() );        JSValue iv;    ret = index->rightValue( _scopes, &iv );    if ( ret )	return ret;        ret = a->rightValue( iv.getObject(), rv );    return ret;}int JSArrayAccess::leftValue( JSScopeStack* _scopes, JSValue *rv ){    int ret = 0;        JSValue v;    ret = array->rightValue( _scopes, &v );    if ( ret )	return ret;    if ( ! v.getObject()->inherits( TYPE_JSAbstractArrayObject ) )    {	printf("isA=%i\n",v.getObject()->isA());	return ERROR_JSNotAFunction;    }            JSAbstractArrayObject *a = (JSAbstractArrayObject*)( v.getObject() );        JSValue iv;    ret = index->rightValue( _scopes, &iv );    if ( ret )	return ret;        ret = a->leftValue( iv.getObject(), rv );    return ret;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -