Пример #1
0
Node* NodeTypeManager::Create(string name, Pipeline* p)
{
    auto info = TypeOf(name);
    if( info != 0 )
        return info->newInstance(p);
    return 0;
}
Пример #2
0
	DataNode& DataNode::SetValueRaw(const IObject& object)
	{
		struct helper
		{
			static void WriteObject(void* object, const ObjectType& type, DataNode& node)
			{
				for (auto baseType : type.GetBaseTypes())
				{
					const ObjectType* baseObjectType = dynamic_cast<const ObjectType*>(baseType.type);
					if (!baseObjectType)
						continue;

					void* baseObject = (*baseType.dynamicCastUpFunc)(object);
					WriteObject(baseObject, *baseObjectType, node);
				}

				for (auto field : type.GetFields())
				{
					auto srlzAttribute = field->GetAttribute<SerializableAttribute>();
					if (srlzAttribute)
						field->SerializeFromObject(object, *node.AddNode(field->GetName()));
				}
			}
		};

		if (object.GetType().IsBasedOn(TypeOf(ISerializable)))
			((const ISerializable&)object).OnSerialize(*this);

		const ObjectType& type = dynamic_cast<const ObjectType&>(object.GetType());
		void* objectPtr = type.DynamicCastFromIObject(const_cast<IObject*>(&object));

		helper::WriteObject(objectPtr, type, *this);

		return *this;
	}
Пример #3
0
static struct code *
code_pointer(lispobj object)
{
    lispobj *headerp, header;
    int type, len;

    headerp = (lispobj *) PTR(object);
    header = *headerp;
    type = TypeOf(header);

    switch (type) {
      case type_CodeHeader:
	  break;
      case type_ReturnPcHeader:
      case type_FunctionHeader:
      case type_ClosureFunctionHeader:
	  len = HEADER_LENGTH(header);
	  if (len == 0)
	      headerp = NULL;
	  else
	      headerp -= len;
	  break;
      default:
	  headerp = NULL;
    }

    return (struct code *) headerp;
}
Пример #4
0
/**
 * Add new child node after given node
 */
static Node *_build_node(Node *node, unsigned char *string, unsigned short length)
{
	Node *next_node;
	if (length >= 1) {
		Node new_node;

		_node_init(&new_node, (BMapNode){(BMap){NULL, 0}}, NULL);
		_node_array_init(&new_node);

		//TODO: If key length <= sizeof(ptr) don't malloc,
		// Just turn pointer into a union and store the array inline.
		if(length > 1) {
			_node_set_array(&new_node, length-1);
			memcpy(new_node.array, string+1, length-1);
		}
		Result(BMapEntryNodePtr) result = bmap_node_insert(&node->children, string[0], new_node);
		if(TypeOf(result) == Type(Result, Ok)) {
			next_node = &result.data->node;
		}
		trace_node("BUILD-NODE", next_node);
	} else {
		next_node = node;
		trace_node("REUSE-NODE", next_node);
	}
	return next_node;
}
Пример #5
0
	void WindowsManager::SetWindowsLayout(WindowsLayout layout)
	{
		for (auto wnd : layout.windows)
		{
			IEditorWindow* editorWindow = o2EditorWindows.mEditorWindows.FindMatch([&](IEditorWindow* x) {
				return x->mWindow->GetName() == wnd.Key();
			});

			if (!editorWindow)
			{
				o2Debug.Log("Can't restore window with name:" + wnd.Key());
				continue;
			}

			if (DockableWindow* dockWnd = editorWindow->mWindow)
			{
				editorWindow->Show();
				*dockWnd->layout = wnd.Value();
			}
		}

		layout.RestoreDock(&layout.mainDock, o2EditorWindows.mMainDockPlace);

		for (auto wnd : o2EditorWindows.mEditorWindows)
		{
			bool hide = !layout.windows.ContainsKey(wnd->mWindow->GetName()) && 
				wnd->mWindow->GetParent()->GetType() != TypeOf(DockWindowPlace);

			if (hide)
				wnd->Hide();
		}
	}
Пример #6
0
static int EndTry( void )
{
    int         parent_scope;
    TREEPTR     expr;
    TREEPTR     func;
    TREEPTR     tree;
    TYPEPTR     typ;
    int         expr_type;

    DropBreakLabel();           /* _leave jumps to this label */
    parent_scope = BlockStack->parent_index;
    tree = LeafNode( OPR_TRY );
    tree->op.st.try_index = BlockStack->try_index;
    tree->op.st.parent_scope = parent_scope;
    AddStmt( tree );
    if( (CurToken == T__EXCEPT) || (CurToken == T___EXCEPT) ) {
        NextToken();
        BlockStack->block_type = T__EXCEPT;
        BlockStack->break_label = NextLabel();
        Jump( BlockStack->break_label );
        DeadCode = 0;
        tree = LeafNode( OPR_EXCEPT );
        tree->op.st.try_sym_handle = DummyTrySymbol();
        tree->op.st.parent_scope = parent_scope;
        AddStmt( tree );
        CompFlags.exception_filter_expr = 1;
        expr = RValue( BracketExpr() );
        CompFlags.exception_filter_expr = 0;
        CompFlags.exception_handler = 1;
        typ = TypeOf( expr );
        expr_type = DataTypeOf( typ );
        if( expr_type != TYPE_VOID ) {
            if( expr_type > TYPE_ULONG ) {
                CErr1( ERR_EXPR_MUST_BE_INTEGRAL );
            }
        }
        func = VarLeaf( SymGetPtr( SymExcept ), SymExcept );
        func->op.opr = OPR_FUNCNAME;
        expr = ExprNode( NULL, OPR_PARM, expr );
        expr->expr_type = typ;
        expr->op.result_type = typ;
        tree = ExprNode( func, OPR_CALL, expr );
        tree->expr_type = GetType( TYPE_VOID );
        AddStmt( tree );
        return( 1 );
    } else if( (CurToken == T__FINALLY) || (CurToken == T___FINALLY) ) {
        CompFlags.in_finally_block = 1;
        NextToken();
        BlockStack->block_type = T__FINALLY;
        DeadCode = 0;
        tree = LeafNode( OPR_FINALLY );
        tree->op.st.try_sym_handle = DummyTrySymbol();
        tree->op.st.parent_scope = parent_scope;
        AddStmt( tree );
        return( 1 );
    }
    return( 0 );
}
Пример #7
0
	Vector<UnknownPtr> AssetsFoldersTree::GetFoldersTreeNodeChilds(UnknownPtr object)
	{
		AssetTree::AssetNode* assetTreeNode = object;

		if (assetTreeNode)
		{
			return assetTreeNode->children.
				FindAll([](AssetTree::AssetNode* x) { return x->assetType == &TypeOf(FolderAsset); }).
				Select<UnknownPtr>([](AssetTree::AssetNode* x) { return UnknownPtr(x); });
		}
		else
		{
			const AssetTree& assetsTree = o2Assets.GetAssetsTree();

			return assetsTree.mRootAssets.
				FindAll([](AssetTree::AssetNode* x) { return x->assetType == &TypeOf(FolderAsset); }).
				Select<UnknownPtr>([](AssetTree::AssetNode* x) { return UnknownPtr(x); });
		}
	}
Пример #8
0
/* check an entry to make sure it's a variable */
void CheckVar(char name)
{
    char tmp_buf[MAX_BUF];
    if (!InTable(name)) {
        Undefined(name);
    }
    if (TypeOf(name) != 'v') {
        sprintf(tmp_buf, "%c is not a variable", name);
        Abort(tmp_buf);
    }
}
Пример #9
0
	void WindowsManager::InitializeWindows()
	{
		auto windowTypes = TypeOf(IEditorWindow).GetDerivedTypes();

		for (auto type : windowTypes)
		{
			IEditorWindow* newWindow = (IEditorWindow*)type->CreateSample();
			mEditorWindows.Add(newWindow);
		}

		for (auto wnd : mEditorWindows)
			wnd->PostInitializeWindow();
	}
Пример #10
0
static void SwitchStmt( void )
{
    SWITCHPTR   sw;
    TREEPTR     tree;
    TYPEPTR     typ;
    int         switch_type;

    StartNewBlock();
    NextToken();
    sw = (SWITCHPTR)CMemAlloc( sizeof( SWITCHDEFN ) );
    sw->prev_switch = SwitchStack;
    sw->low_value = ~0l;
    sw->high_value = 0;
    sw->case_format = "%ld";        /* assume signed cases */
    SwitchStack = sw;
    switch_type = TYPE_INT;         /* assume int */
    tree = RValue( BracketExpr() );
    typ = TypeOf( tree );
    if( typ->decl_type == TYPE_ENUM ) typ = typ->object;
    if( typ->decl_type == TYPE_UFIELD ) {
        if( typ->u.f.field_width == (TARGET_INT * 8) ) {
            sw->case_format = "%lu";
            switch_type = TYPE_UINT;
        }
    }
    switch( typ->decl_type ) {
    case TYPE_USHORT:
    case TYPE_UINT:
        sw->case_format = "%lu";
        switch_type = TYPE_UINT;
    case TYPE_CHAR:
    case TYPE_UCHAR:
    case TYPE_SHORT:
    case TYPE_INT:
    case TYPE_FIELD:
    case TYPE_UFIELD:
        break;
    case TYPE_ULONG:
        sw->case_format = "%lu";
        switch_type = TYPE_ULONG;
        break;
    case TYPE_LONG:
        switch_type = TYPE_LONG;
        break;
    default:
        CErr1( ERR_INVALID_TYPE_FOR_SWITCH );
    }
    tree = ExprNode( 0, OPR_SWITCH, tree );
    tree->op.switch_info = sw;
    AddStmt( tree );
}
Пример #11
0
	WindowsLayout WindowsManager::GetWindowsLayout()
	{
		WindowsLayout res;

		res.mainDock.RetrieveLayout(o2EditorWindows.mMainDockPlace);

		for (auto widget : EditorUIRoot.GetRootWidget()->GetChildWidgets())
		{
			if (widget->GetType() == TypeOf(DockableWindow))
				res.windows.Add(widget->name, *widget->layout);
		}

		return res;
	}
Пример #12
0
const NodeTypeInfo* NodeTypeManager::RegisterNode( string nodeName
        , const NodeLayoutDescriptor& layout, NodeUpdater* updater )
{
    SCOPEDBLOCK("NodeTypeManager::RegisterNode");

    auto existing = TypeOf(nodeName);
    if ( existing != 0 )
        return existing;

    auto info = new NodeTypeInfo;
    info->_name = nodeName;
    info->_updater = updater;
    info->_layout = layout;

    _types[nodeName] = info;
    return info;
}
Пример #13
0
			static void ReadObject(void* object, void* source, const ObjectType& type, const DataNode& node)
			{
				for (auto baseType : type.GetBaseTypes())
				{
					const ObjectType* baseObjectType = dynamic_cast<const ObjectType*>(baseType.type);
					if (!baseObjectType)
						continue;

					void* baseObject = (*baseType.dynamicCastUpFunc)(object);
					void* baseSourceObject = (*baseType.dynamicCastUpFunc)(source);
					ReadObject(baseObject, baseSourceObject, *baseObjectType, node);
				}

				for (auto field : type.GetFields())
				{
					if (!field->GetAttribute<SerializableAttribute>())
						continue;

					auto fldNode = node.GetNode(field->GetName());
					if (fldNode)
					{
						if (field->GetType()->IsBasedOn(TypeOf(IObject)))
						{
							bool usedConverter = false;
							for (auto conv : mDataConverters)
							{
								if (conv->IsConvertsType(field->GetType()))
								{
									conv->FromData(field->GetValuePtr(object), node);
									usedConverter = true;
									break;
								}
							}

							if (usedConverter)
								continue;

							fldNode->GetValueDelta(*(IObject*)field->GetValuePtr(object),
												   *(IObject*)field->GetValuePtr(source));
						}
						else field->DeserializeFromObject(object, *fldNode);
					}
					else field->CopyValue(object, source);
				}
			}
Пример #14
0
bool SearchTerm::is_valid() const {
  // We can accept also a zero value in these cases
  if (operator_ == SearchTerm::Op_NumericDate) {
    return value_.toInt() >= 0;
  } else if (operator_ == SearchTerm::Op_RelativeDate) {
    return (value_.toInt() >= 0 && value_.toInt() < second_value_.toInt());
  }

  switch (TypeOf(field_)) {
    case Type_Text:    return !value_.toString().isEmpty();
    case Type_Date:    return value_.toInt() != 0;
    case Type_Number:  return value_.toInt() >= 0;
    case Type_Rating:  return value_.toFloat() >= 0.0;
    case Type_Time:    return true;
    case Type_Invalid: return false;
  }
  return false;
}
Пример #15
0
static void ParseArg (ArgDesc* Arg, Type* Type)
/* Parse one argument but do not push it onto the stack. Make all fields in
 * Arg valid.
 */
{
    /* We have a prototype, so chars may be pushed as chars */
    Arg->Flags = CF_FORCECHAR;

    /* Remember the required argument type */
    Arg->ArgType = Type;

    /* Read the expression we're going to pass to the function */
    MarkedExprWithCheck (hie1, &Arg->Expr);

    /* Remember the actual argument type */
    Arg->Type = Arg->Expr.Type;

    /* Convert this expression to the expected type */
    TypeConversion (&Arg->Expr, Type);

    /* Remember the following code position */
    GetCodePos (&Arg->Load);

    /* If the value is a constant, set the flag, otherwise load it into the
     * primary register.
     */
    if (ED_IsConstAbsInt (&Arg->Expr) && ED_CodeRangeIsEmpty (&Arg->Expr)) {
        /* Remember that we have a constant value */
        Arg->Flags |= CF_CONST;
    } else {
        /* Load into the primary */
        LoadExpr (CF_NONE, &Arg->Expr);
    }

    /* Remember the following code position */
    GetCodePos (&Arg->Push);
    GetCodePos (&Arg->End);

    /* Use the type of the argument for the push */
    Arg->Flags |= TypeOf (Arg->Expr.Type);
}
Пример #16
0
/*
========================
idSWFScriptVar::PrintToConsole
========================
*/
void idSWFScriptVar::PrintToConsole() const
{
	idLib::Printf( "Object type: %s\n", TypeOf() );
	
	if( IsObject() )
	{
		GetObject()->PrintToConsole();
	}
	else if( IsNumeric() )
	{
		idLib::Printf( "%d\n", ToInteger() );
	}
	else if( IsString() )
	{
		idLib::Printf( "%s\n", ToString().c_str() );
	}
	else
	{
		idLib::Printf( "unknown\n" );
	}
}
Пример #17
0
static void LoadConstant (unsigned Flags, ExprDesc* Expr)
/* Load the primary register with some constant value. */
{
    switch (ED_GetLoc (Expr)) {

        case E_LOC_ABS:
            /* Number constant */
            g_getimmed (Flags | TypeOf (Expr->Type) | CF_CONST, Expr->IVal, 0);
            break;

        case E_LOC_GLOBAL:
            /* Global symbol, load address */
            g_getimmed ((Flags | CF_EXTERNAL) & ~CF_CONST, Expr->Name, Expr->IVal);
            break;

        case E_LOC_STATIC:
        case E_LOC_LITERAL:
            /* Static symbol or literal, load address */
            g_getimmed ((Flags | CF_STATIC) & ~CF_CONST, Expr->Name, Expr->IVal);
            break;

        case E_LOC_REGISTER:
            /* Register variable. Taking the address is usually not
             * allowed.
             */
            if (IS_Get (&AllowRegVarAddr) == 0) {
                Error ("Cannot take the address of a register variable");
            }
            g_getimmed ((Flags | CF_REGVAR) & ~CF_CONST, Expr->Name, Expr->IVal);
            break;

        case E_LOC_STACK:
            g_leasp (Expr->IVal);
            break;

        default:
            Internal ("Unknown constant type: %04X", Expr->Flags);
    }
}
Пример #18
0
	void DataNode::GetValueRaw(IObject& object) const
	{

		struct helper
		{
			static void ReadObject(void* object, const ObjectType& type, const DataNode& node)
			{
				for (auto baseType : type.GetBaseTypes())
				{
					const ObjectType* baseObjectType = dynamic_cast<const ObjectType*>(baseType.type);
					if (!baseObjectType)
						continue;

					void* baseObject = (*baseType.dynamicCastUpFunc)(object);
					ReadObject(baseObject, *baseObjectType, node);
				}

				for (auto field : type.GetFields())
				{
					auto srlzAttribute = field->GetAttribute<SerializableAttribute>();
					if (srlzAttribute)
					{
						auto fldNode = node.GetNode(field->GetName());
						if (fldNode)
							field->DeserializeFromObject(object, *fldNode);
					}
				}
			}
		};

		const ObjectType& type = dynamic_cast<const ObjectType&>(object.GetType());
		void* objectPtr = type.DynamicCastFromIObject(const_cast<IObject*>(&object));
		helper::ReadObject(objectPtr, type, *this);

		if (object.GetType().IsBasedOn(TypeOf(ISerializable)))
			((ISerializable&)object).OnDeserialized(*this);
	}
Пример #19
0
	void ProcHierarchy(String& hierarchy, Widget* widget, int level)
	{
		String sideNames[] = { "Hor", "Ver" };

		for (int i = 0; i < level; i++)
			hierarchy += ' ';

		hierarchy += widget->GetName();

		if (widget->GetType() == TypeOf(DockWindowPlace))
		{
			hierarchy += ": ";
			hierarchy += (String)(bool)((DockWindowPlace*)widget)->interactable;
			hierarchy += " ";
			hierarchy += sideNames[(int)((DockWindowPlace*)widget)->GetResizibleDir()];
			RectF rt = widget->layout->GetWorldRect();
			hierarchy += (String)rt.left + " " + (String)rt.bottom + " " + (String)rt.right + " " + (String)rt.top;
		}

		hierarchy += '\n';

		for (auto child : widget->GetChildWidgets())
			ProcHierarchy(hierarchy, child, level + 1);
	}
Пример #20
0
void NewFunc (SymEntry* Func)
/* Parse argument declarations and function body. */
{
    int         C99MainFunc = 0;/* Flag for C99 main function returning int */
    SymEntry*   Param;

    /* Get the function descriptor from the function entry */
    FuncDesc* D = Func->V.F.Func;

    /* Allocate the function activation record for the function */
    CurrentFunc = NewFunction (Func);

    /* Reenter the lexical level */
    ReenterFunctionLevel (D);

    /* Check if the function header contains unnamed parameters. These are
     * only allowed in cc65 mode.
     */
    if ((D->Flags & FD_UNNAMED_PARAMS) != 0 && (IS_Get (&Standard) != STD_CC65)) {
        Error ("Parameter name omitted");
    }

    /* Declare two special functions symbols: __fixargs__ and __argsize__.
     * The latter is different depending on the type of the function (variadic
     * or not).
     */
    AddConstSym ("__fixargs__", type_uint, SC_DEF | SC_CONST, D->ParamSize);
    if (D->Flags & FD_VARIADIC) {
        /* Variadic function. The variable must be const. */
        static const Type T[] = { TYPE(T_UCHAR | T_QUAL_CONST), TYPE(T_END) };
        AddLocalSym ("__argsize__", T, SC_DEF | SC_REF | SC_AUTO, 0);
    } else {
        /* Non variadic */
        AddConstSym ("__argsize__", type_uchar, SC_DEF | SC_CONST, D->ParamSize);
    }

    /* Function body now defined */
    Func->Flags |= SC_DEF;

    /* Special handling for main() */
    if (strcmp (Func->Name, "main") == 0) {

        /* Mark this as the main function */
        CurrentFunc->Flags |= FF_IS_MAIN;

        /* Main cannot be a fastcall function */
        if (IsQualFastcall (Func->Type)) {
            Error ("`main' cannot be declared as __fastcall__");
        }

        /* If cc65 extensions aren't enabled, don't allow a main function that
         * doesn't return an int.
         */
        if (IS_Get (&Standard) != STD_CC65 && CurrentFunc->ReturnType[0].C != T_INT) {
            Error ("`main' must always return an int");
        }

        /* Add a forced import of a symbol that is contained in the startup
         * code. This will force the startup code to be linked in.
         */
        g_importstartup ();

        /* If main() takes parameters, generate a forced import to a function
         * that will setup these parameters. This way, programs that do not
         * need the additional code will not get it.
         */
        if (D->ParamCount > 0 || (D->Flags & FD_VARIADIC) != 0) {
            g_importmainargs ();
        }

        /* Determine if this is a main function in a C99 environment that
         * returns an int.
         */
        if (IsTypeInt (F_GetReturnType (CurrentFunc)) &&
            IS_Get (&Standard) == STD_C99) {
            C99MainFunc = 1;
        }
    }

    /* Allocate code and data segments for this function */
    Func->V.F.Seg = PushSegments (Func);

    /* Allocate a new literal pool */
    PushLiteralPool (Func);

    /* If this is a fastcall function, push the last parameter onto the stack */
    if (IsQualFastcall (Func->Type) && D->ParamCount > 0) {

        unsigned Flags;

        /* Fastcall functions may never have an ellipsis or the compiler is buggy */
        CHECK ((D->Flags & FD_VARIADIC) == 0);

        /* Generate the push */
        if (IsTypeFunc (D->LastParam->Type)) {
            /* Pointer to function */
            Flags = CF_PTR;
        } else {
            Flags = TypeOf (D->LastParam->Type) | CF_FORCECHAR;
        }
        g_push (Flags, 0);
    }

    /* Generate function entry code if needed */
    g_enter (TypeOf (Func->Type), F_GetParamSize (CurrentFunc));

    /* If stack checking code is requested, emit a call to the helper routine */
    if (IS_Get (&CheckStack)) {
        g_stackcheck ();
    }

    /* Setup the stack */
    StackPtr = 0;

    /* Walk through the parameter list and allocate register variable space
     * for parameters declared as register. Generate code to swap the contents
     * of the register bank with the save area on the stack.
     */
    Param = D->SymTab->SymHead;
    while (Param && (Param->Flags & SC_PARAM) != 0) {

        /* Check for a register variable */
        if (SymIsRegVar (Param)) {

            /* Allocate space */
            int Reg = F_AllocRegVar (CurrentFunc, Param->Type);

            /* Could we allocate a register? */
            if (Reg < 0) {
                /* No register available: Convert parameter to auto */
                CvtRegVarToAuto (Param);
            } else {
                /* Remember the register offset */
                Param->V.R.RegOffs = Reg;

                /* Generate swap code */
                g_swap_regvars (Param->V.R.SaveOffs, Reg, CheckedSizeOf (Param->Type));
            }
        }

        /* Next parameter */
        Param = Param->NextSym;
    }

    /* Need a starting curly brace */
    ConsumeLCurly ();

    /* Parse local variable declarations if any */
    DeclareLocals ();

    /* Remember the current stack pointer. All variables allocated elsewhere
     * must be dropped when doing a return from an inner block.
     */
    CurrentFunc->TopLevelSP = StackPtr;

    /* Now process statements in this block */
    while (CurTok.Tok != TOK_RCURLY && CurTok.Tok != TOK_CEOF) {
        Statement (0);
    }

    /* If this is not a void function, and not the main function in a C99
     * environment returning int, output a warning if we didn't see a return
     * statement.
     */
    if (!F_HasVoidReturn (CurrentFunc) && !F_HasReturn (CurrentFunc) && !C99MainFunc) {
        Warning ("Control reaches end of non-void function");
    }

    /* If this is the main function in a C99 environment returning an int, let
     * it always return zero. Note: Actual return statements jump to the return
     * label defined below.
     * The code is removed by the optimizer if unused.
     */
    if (C99MainFunc) {
        g_getimmed (CF_INT | CF_CONST, 0, 0);
    }

    /* Output the function exit code label */
    g_defcodelabel (F_GetRetLab (CurrentFunc));

    /* Restore the register variables */
    F_RestoreRegVars (CurrentFunc);

    /* Generate the exit code */
    g_leave ();

    /* Emit references to imports/exports */
    EmitExternals ();

    /* Emit function debug info */
    F_EmitDebugInfo ();
    EmitDebugInfo ();

    /* Leave the lexical level */
    LeaveFunctionLevel ();

    /* Eat the closing brace */
    ConsumeRCurly ();

    /* Restore the old literal pool, remembering the one for the function */
    Func->V.F.LitPool = PopLiteralPool ();

    /* Switch back to the old segments */
    PopSegments ();

    /* Reset the current function pointer */
    FreeFunction (CurrentFunc);
    CurrentFunc = 0;
}
Пример #21
0
// display the value and type of a given parameter
template <typename T> void Display(T t)
{
    std::cout << "Value[" << t << "]   type[" << TypeOf(t) << "]" << std::endl;
}
Пример #22
0
QString SearchTerm::ToSql() const {
    QString col = FieldColumnName(field_);
    QString date = DateName(date_, true);
    QString value = value_.toString();
    value.replace('\'', "''");

    QString second_value;

    bool special_date_query = (operator_ == SearchTerm::Op_NumericDate || operator_ == SearchTerm::Op_NumericDateNot ||
                               operator_ == SearchTerm::Op_RelativeDate);

    // Floating point problems...
    // Theoretically 0.0 == 0 stars, 0.1 == 0.5 star, 0.2 == 1 star etc.
    // but in reality we need to consider anything from [0.05, 0.15) range
    // to be 0.5 star etc.
    // To make this simple, I transform the ranges to integeres and then
    // operate on ints: [0.0, 0.05) -> 0, [0.05, 0.15) -> 1 etc.
    if (TypeOf(field_) == Type_Rating) {
        col = "CAST ((" + col + " + 0.05) * 10 AS INTEGER)";
        value = "CAST ((" + value + " + 0.05) * 10 AS INTEGER)";
    } else if (TypeOf(field_) == Type_Date) {
        if (!special_date_query) {
            // We have the exact date
            // The calendar widget specifies no time so ditch the possible time part
            // from integers representing the dates.
            col = "DATE(" + col + ", 'unixepoch', 'localtime')";
            value = "DATE(" + value + ", 'unixepoch', 'localtime')";
        } else {
            // We have a numeric date, consider also the time for more precision
            col = "DATETIME(" + col + ", 'unixepoch', 'localtime')";
            second_value = second_value_.toString();
            second_value.replace('\'', "''");
            if (date == "weeks") {
                // Sqlite doesn't know weeks, transform them to days
                date = "days";
                value = QString::number(value_.toInt()*7);
                second_value = QString::number(second_value_.toInt()*7);
            }
        }
    } else if (TypeOf(field_) == Type_Time) {
        // Convert seconds to nanoseconds
        value = "CAST (" + value + " *1000000000 AS INTEGER)";
    }

    switch (operator_) {
    case Op_Contains:
        return col + " LIKE '%" + value + "%'";
    case Op_NotContains:
        return col + " NOT LIKE '%" + value + "%'";
    case Op_StartsWith:
        return col + " LIKE '" + value + "%'";
    case Op_EndsWith:
        return col + " LIKE '%" + value + "'";
    case Op_Equals:
        if (TypeOf(field_) == Type_Text)
            return col + " LIKE '" + value + "'";
        else if (TypeOf(field_) == Type_Rating ||
                 TypeOf(field_) == Type_Date ||
                 TypeOf(field_) == Type_Time)
            return col + " = " + value;
        else
            return col + " = '" + value + "'";
    case Op_GreaterThan:
        if (TypeOf(field_) == Type_Rating ||
                TypeOf(field_) == Type_Date ||
                TypeOf(field_) == Type_Time)
            return col + " > " + value;
        else
            return col + " > '" + value + "'";
    case Op_LessThan:
        if (TypeOf(field_) == Type_Rating ||
                TypeOf(field_) == Type_Date ||
                TypeOf(field_) == Type_Time)
            return col + " < " + value;
        else
            return col + " < '" + value + "'";
    case Op_NumericDate:
        return col + " > " + "DATETIME('now', '-" + value + " " + date +"', 'localtime')";
    case Op_NumericDateNot:
        return col + " < " + "DATETIME('now', '-" + value + " " + date +"', 'localtime')";
    case Op_RelativeDate:
        // Consider the time range before the first date but after the second one
        return "(" + col + " < " + "DATETIME('now', '-" + value + " " + date +"', 'localtime') AND " +
               col + " > " + "DATETIME('now', '-" + second_value + " " + date +"', 'localtime'))";
    case Op_NotEquals:
        if (TypeOf(field_) == Type_Text) {
            return col + " <> '" + value + "'";
        } else {
            return col + " <> " + value;
        }
    }

    return QString();
}
Пример #23
0
static void DoConversion (ExprDesc* Expr, const Type* NewType)
/* Emit code to convert the given expression to a new type. */
{
    Type*    OldType;
    unsigned OldSize;
    unsigned NewSize;


    /* Remember the old type */
    OldType = Expr->Type;

    /* If we're converting to void, we're done. Note: This does also cover a
     * conversion void -> void.
     */
    if (IsTypeVoid (NewType)) {
        ED_MakeRVal (Expr);     /* Never an lvalue */
        goto ExitPoint;
    }

    /* Don't allow casts from void to something else. */
    if (IsTypeVoid (OldType)) {
        Error ("Cannot convert from `void' to something else");
        goto ExitPoint;
    }

    /* Get the sizes of the types. Since we've excluded void types, checking
     * for known sizes makes sense here.
     */
    OldSize = CheckedSizeOf (OldType);
    NewSize = CheckedSizeOf (NewType);

    /* lvalue? */
    if (ED_IsLVal (Expr)) {

        /* We have an lvalue. If the new size is smaller than the new one,
         * we don't need to do anything. The compiler will generate code
         * to load only the portion of the value that is actually needed.
         * This works only on a little endian architecture, but that's
         * what we support.
         * If both sizes are equal, do also leave the value alone.
         * If the new size is larger, we must convert the value.
         */
        if (NewSize > OldSize) {
            /* Load the value into the primary */
            LoadExpr (CF_NONE, Expr);

            /* Emit typecast code */
            g_typecast (TypeOf (NewType), TypeOf (OldType) | CF_FORCECHAR);

            /* Value is now in primary and an rvalue */
            ED_MakeRValExpr (Expr);
        }

    } else if (ED_IsLocAbs (Expr)) {

        /* A cast of a constant numeric value to another type. Be sure
         * to handle sign extension correctly.
         */

        /* Get the current and new size of the value */
        unsigned OldBits = OldSize * 8;
        unsigned NewBits = NewSize * 8;

        /* Check if the new datatype will have a smaller range. If it
         * has a larger range, things are ok, since the value is
         * internally already represented by a long.
         */
        if (NewBits <= OldBits) {

            /* Cut the value to the new size */
            Expr->IVal &= (0xFFFFFFFFUL >> (32 - NewBits));

            /* If the new type is signed, sign extend the value */
            if (IsSignSigned (NewType)) {
                if (Expr->IVal & (0x01UL << (NewBits-1))) {
                    /* Beware: Use the safe shift routine here. */
                    Expr->IVal |= shl_l (~0UL, NewBits);
                }
            }
        }

    } else {
Пример #24
0
void LoadExpr (unsigned Flags, struct ExprDesc* Expr)
/* Load an expression into the primary register if it is not already there. */
{
    if (ED_IsLVal (Expr)) {

        /* Dereferenced lvalue. If this is a bit field its type is unsigned.
         * But if the field is completely contained in the lower byte, we will
         * throw away the high byte anyway and may therefore load just the
         * low byte.
         */
        if (ED_IsBitField (Expr)) {
            Flags |= (Expr->BitOffs + Expr->BitWidth <= CHAR_BITS)? CF_CHAR : CF_INT;
            Flags |= CF_UNSIGNED;
        } else {
            Flags |= TypeOf (Expr->Type);
        }
        if (ED_NeedsTest (Expr)) {
            Flags |= CF_TEST;
        }

        switch (ED_GetLoc (Expr)) {

            case E_LOC_ABS:
                /* Absolute: numeric address or const */
                g_getstatic (Flags | CF_ABSOLUTE, Expr->IVal, 0);
                break;

            case E_LOC_GLOBAL:
                /* Global variable */
                g_getstatic (Flags | CF_EXTERNAL, Expr->Name, Expr->IVal);
                break;

            case E_LOC_STATIC:
            case E_LOC_LITERAL:
                /* Static variable or literal in the literal pool */
                g_getstatic (Flags | CF_STATIC, Expr->Name, Expr->IVal);
                break;

            case E_LOC_REGISTER:
                /* Register variable */
                g_getstatic (Flags | CF_REGVAR, Expr->Name, Expr->IVal);
                break;

            case E_LOC_STACK:
                /* Value on the stack */
                g_getlocal (Flags, Expr->IVal);
                break;

            case E_LOC_PRIMARY:
                /* The primary register - just test if necessary */
                if (Flags & CF_TEST) {
                    g_test (Flags);
                }
                break;

            case E_LOC_EXPR:
                /* Reference to address in primary with offset in Expr */
                g_getind (Flags, Expr->IVal);
                break;

            default:
                Internal ("Invalid location in LoadExpr: 0x%04X", ED_GetLoc (Expr));
        }

        /* Handle bit fields. The actual type may have been casted or
         * converted, so be sure to always use unsigned ints for the
         * operations.
         */
        if (ED_IsBitField (Expr)) {
            unsigned F = CF_INT | CF_UNSIGNED | CF_CONST | (Flags & CF_TEST);
            /* Shift right by the bit offset */
            g_asr (F, Expr->BitOffs);
            /* And by the width if the field doesn't end on an int boundary */
            if (Expr->BitOffs + Expr->BitWidth != CHAR_BITS &&
                Expr->BitOffs + Expr->BitWidth != INT_BITS) {
                g_and (F, (0x0001U << Expr->BitWidth) - 1U);
            }
        }

        /* Expression was tested */
        ED_TestDone (Expr);

    } else {
        /* An rvalue */
        if (ED_IsLocExpr (Expr)) {
            if (Expr->IVal != 0) {
                /* We have an expression in the primary plus a constant
                 * offset. Adjust the value in the primary accordingly.
                 */
                Flags |= TypeOf (Expr->Type);
                g_inc (Flags | CF_CONST, Expr->IVal);
            }
        } else {
            /* Constant of some sort, load it into the primary */
            LoadConstant (Flags, Expr);
        }

        /* Are we testing this value? */
        if (ED_NeedsTest (Expr)) {
            /* Yes, force a test */
            Flags |= TypeOf (Expr->Type);
            g_test (Flags);
            ED_TestDone (Expr);
        }
    }

}
Пример #25
0
	const Type* SpriteViewer::GetViewingObjectType() const
	{
		return &TypeOf(Sprite);
	}
Пример #26
0
	SpriteViewer::SpriteViewer()
	{
		PushScopeEnterOnStack scope;

		auto layout = mnew VerticalLayout();
		layout->borderTop = 5;
		layout->expandWidth = true;
		layout->expandHeight = false;
		layout->fitByChildren = true;

		mViewWidget = layout;

		auto commonFieldsLayout = mnew VerticalLayout();
		commonFieldsLayout->spacing = 5;
		commonFieldsLayout->expandWidth = true;
		commonFieldsLayout->expandHeight = false;
		commonFieldsLayout->fitByChildren = true;
		layout->AddChild(commonFieldsLayout);

		const Type& spriteType = TypeOf(Sprite);

		mImageProperty = dynamic_cast<ImageAssetProperty*>(
			o2EditorProperties.BuildField(commonFieldsLayout, spriteType, "image", "", mFieldProperties, mOnChildFieldChangeCompleted, onChanged));

		mSizePivotProperty = dynamic_cast<Vec2FProperty*>(
			o2EditorProperties.BuildField(commonFieldsLayout, spriteType, "szPivot", "", mFieldProperties, mOnChildFieldChangeCompleted, onChanged));

		mPivotProperty = dynamic_cast<Vec2FProperty*>(
			o2EditorProperties.BuildField(commonFieldsLayout, spriteType, "pivot", "", mFieldProperties, mOnChildFieldChangeCompleted, onChanged));

		mColorProperty = dynamic_cast<ColorProperty*>(
			o2EditorProperties.BuildField(commonFieldsLayout, spriteType, "color", "", mFieldProperties, mOnChildFieldChangeCompleted, onChanged));

		mAlphaProperty = dynamic_cast<FloatProperty*>(
			o2EditorProperties.BuildField(commonFieldsLayout, spriteType, "transparency", "", mFieldProperties, mOnChildFieldChangeCompleted, onChanged));

		mModeProperty = dynamic_cast<EnumProperty*>(
			o2EditorProperties.BuildField(commonFieldsLayout, spriteType, "mode", "", mFieldProperties, mOnChildFieldChangeCompleted, onChanged));

		mModeProperty->onChanged += [&](IPropertyField* x) { OnModeSelected(); };

		mHiddenProperties = o2UI.CreateWidget<VerticalLayout>();
		mHiddenProperties->expandWidth = true;
		mHiddenProperties->expandHeight = false;
		mHiddenProperties->fitByChildren = true;
		layout->AddChild(mHiddenProperties);

		// Fill properties
		mFillPropertiesSpoiler = o2UI.CreateWidget<Spoiler>();
		mHiddenProperties->AddChild(mFillPropertiesSpoiler);

		auto fillSpace = mnew Widget();
		fillSpace->layout->minHeight = 5;
		mFillPropertiesSpoiler->AddChildWidget(fillSpace);

		mFillProperty = dynamic_cast<FloatProperty*>(
			o2EditorProperties.BuildField(mFillPropertiesSpoiler, spriteType, "fill", "", mFieldProperties, mOnChildFieldChangeCompleted, onChanged));

		// Slice properties
		mSlicedPropertiesSpoiler = o2UI.CreateWidget<Spoiler>();
		mHiddenProperties->AddChild(mSlicedPropertiesSpoiler);

		auto sliceSpace = mnew Widget();
		sliceSpace->layout->minHeight = 5;
		mSlicedPropertiesSpoiler->AddChildWidget(sliceSpace);

		mSliceBorderProperty = dynamic_cast<BorderIProperty*>(
			o2EditorProperties.BuildField(mSlicedPropertiesSpoiler, spriteType, "sliceBorder", "", mFieldProperties, mOnChildFieldChangeCompleted, onChanged));

		// Slice properties
		mTiledPropertiesSpoiler = o2UI.CreateWidget<Spoiler>();
		mHiddenProperties->AddChild(mTiledPropertiesSpoiler);

		auto tiledSpace = mnew Widget();
		tiledSpace->layout->minHeight = 5;
		mTiledPropertiesSpoiler->AddChildWidget(tiledSpace);

		mTileScaleProperty = dynamic_cast<FloatProperty*>(
			o2EditorProperties.BuildField(mTiledPropertiesSpoiler, spriteType, "tileScale", "", mFieldProperties, mOnChildFieldChangeCompleted, onChanged));
	}
Пример #27
0
	const Type* Asset::IMetaInfo::GetAssetType() const
	{
		return &TypeOf(Asset);
	}
Пример #28
0
	Vector<const Type*> FolderAssetConverter::GetProcessingAssetsTypes() const
	{
		Vector<const Type*> res;
		res.Add(&TypeOf(FolderAsset));
		return res;
	}
Пример #29
0
	const Type& AssetRef::GetAssetType() const
	{
		return TypeOf(Asset);
	}
Пример #30
0
std::string CInternalFilesZFXY::GetType()
{
  return TypeOf();
}