Example #1
0
QString composeMessage( const QXmlStreamReader& xml ) {
    QString errorstr( xml.errorString() );
    errorstr += " at line " + QString::number(xml.lineNumber());
    errorstr += " (column " + QString::number(xml.columnNumber());
    errorstr += ")";
    return errorstr;
}
KeyboardWinAPI::KeyboardWinAPI (size_t window)
{
        win = (HWND)window;


        SetLastError(0);
        old_wndproc = (WNDPROC) SetWindowLong(win, GWL_WNDPROC,
                                              (LONG)::wndproc);
        if (!old_wndproc) {
            if (GetLastError()) CERR << "Could not trap keyboard events:  " << errorstr() << std::endl;
        }

        wmap[win] = this;
}
Example #3
0
void Shader::compile()
{
	glCompileShader(_shaderId);

	GLint status;
	glGetShaderiv(_shaderId, GL_COMPILE_STATUS, &status);
	if(status == GL_FALSE)
	{
		GLint length;
		glGetShaderiv(_shaderId, GL_INFO_LOG_LENGTH, &length);
		std::vector< char > errorstr(length);
		glGetShaderInfoLog(_shaderId, length, NULL, &errorstr[0]);
		throw std::runtime_error("Compile errors(s): " + std::string(&errorstr[0]));
	}
}
Example #4
0
static char *_set_link(struct robject *r, rp_t src, int argc, char **argv) {
	char *link;
	char *old;

	if (argc == 2) {
		link = argv[1];

		old = robject_get_data(r, "link");
		robject_set_data(r, "link", strdup(link));
		free(old);

		return strdup("T");
	}

	return errorstr(EINVAL);
}
Example #5
0
void ShaderProgram::link()
{
	std::for_each( shaders.begin(), shaders.end(), std::mem_fun( &Shader::compile ) );
	glLinkProgram( _programId );

	GLint status;
	glGetProgramiv(_programId, GL_LINK_STATUS, &status);
	if(status == GL_FALSE)
	{
		GLint length;
		glGetProgramiv(_programId, GL_INFO_LOG_LENGTH, &length);
		std::vector< char > errorstr(length);
		glGetProgramInfoLog(_programId, length, NULL, &errorstr[0]);
		throw std::runtime_error("Link error(s): " + std::string(&errorstr[0]));
	}

	_linked = true;
}
Example #6
0
static char *_find(struct robject *r, rp_t src, int argc, char **argv) {
	char *link;

	link = robject_get_data(r, "link");

	if (argc == 2) {
		if (link) {
			return saprintf(">> %s", link);
		}
		else {
			return rtoa(RP_CONS(getpid(), r->index));
		}
	}
	else if (argc == 3 && !strcmp(argv[1], "-L")) {
		return rtoa(RP_CONS(getpid(), r->index));
	}

	return errorstr(EINVAL);
}
Example #7
0
LEXEME *expression_lambda(LEXEME *lex, SYMBOL *funcsp, TYPE *atp, TYPE **tp, EXPRESSION **exp, int flags)
{
    LAMBDA *self;
    SYMBOL *vpl, *ths;
    HASHREC *hrl;
    TYPE *ltp;
    STRUCTSYM ssl;
    if (funcsp)
        funcsp->noinline = TRUE;
    IncGlobalFlag();
    self = Alloc(sizeof(LAMBDA));
    ltp = Alloc(sizeof(TYPE));
    ltp->type = bt_struct;
    ltp->syms = CreateHashTable(1);
    ltp->tags = CreateHashTable(1);
    ltp->size = 0;
    self->captured = CreateHashTable(1);
    self->oldSyms = localNameSpace->syms;
    self->oldTags = localNameSpace->tags;
    self->index = lambdaIndex;
    self->captureMode = cmNone;
    self->isMutable = FALSE;
    self->captureThis = FALSE;
    self->cls = makeID(sc_type, ltp, NULL, LambdaName());
    ltp->sp = self->cls;
    SetLinkerNames(self->cls, lk_cdecl);
    self->cls->islambda = TRUE;
    self->cls->structAlign = getAlign(sc_global, &stdpointer);
    self->func = makeID(sc_member, ltp, NULL, "$internalFunc");
    self->func->parentClass = self->cls;
    self->functp = &stdauto;
    self->enclosingFunc = theCurrentFunc;
    if (lambdas)
        lambdas->prev = self;
    self->next = lambdas;
    lambdas = self;
    
    localNameSpace->syms = CreateHashTable(1);
    localNameSpace->tags = CreateHashTable(1);
    if (lambdas->next)
    {
        self->lthis = lambdas->next->lthis;
    }
    else if (funcsp && funcsp->parentClass)
    {
        self->lthis = ((SYMBOL *)funcsp->tp->syms->table[0]->p);
    }
    lex = getsym(); // past [
    if (funcsp)
    {
        // can have a capture list;
        if (MATCHKW(lex, assign))
        {
            lex = getsym();
            if (MATCHKW(lex, comma) || MATCHKW(lex, closebr))
            {
                self->captureMode = cmValue;
                skip(&lex, comma);
            }
            else
            {
                lex = backupsym();
            }
        }
        else if (MATCHKW(lex, and))
        {
            lex = getsym();
            if (MATCHKW(lex, comma) || MATCHKW(lex, closebr))
            {
                self->captureMode = cmRef;
                skip(&lex, comma);
            }
            else
            {
                lex = backupsym();
            }
        }
        if (!MATCHKW(lex, comma) && !MATCHKW(lex, closebr))
        {
            do            
            {
                enum e_cm localMode = self->captureMode;
                if (MATCHKW(lex, comma))
                    skip(&lex, comma);
                if (MATCHKW(lex, kw_this))
                {
                    lex = getsym();
                    if (localMode == cmValue || !self->lthis)
                    {
                        error(ERR_CANNOT_CAPTURE_THIS);
                    }
                    else
                    {
                        if (self->captureThis)
                        {
                            error(ERR_CAPTURE_ITEM_LISTED_MULTIPLE_TIMES);
                        }
                        self->captureThis = TRUE;
                        lambda_capture(NULL, cmThis, TRUE);
                    }
                    continue;
                }
                else if (MATCHKW(lex, and))
                {
                    if (localMode == cmRef)
                    {
                        error(ERR_INVALID_LAMBDA_CAPTURE_MODE);
                    }
                    localMode = cmRef;
                    lex = getsym();
                }
                else 
                {
                    if (localMode == cmValue)
                    {
                        error(ERR_INVALID_LAMBDA_CAPTURE_MODE);
                    }
                    localMode = cmValue;
                }
                if (ISID(lex))
                {
                    SYMBOL *sp = search(lex->value.s.a, localNameSpace->syms);
                    LAMBDA *current = lambdas;
                    while (current && !sp)
                    {
                        sp = search(lex->value.s.a, current->oldSyms);
                        current = current->next;
                        
                    }
                    lex = getsym();
                    if (sp)
                    {
                        if (sp->packed)
                        {
                            if (!MATCHKW(lex, ellipse))
                                error(ERR_PACK_SPECIFIER_REQUIRED_HERE);
                            else
                                lex = getsym();
                        }
                        if (sp->packed)
                        {
                            int n;
                            TEMPLATEPARAMLIST * templateParam = sp->tp->templateParam->p->byPack.pack;
                            HASHREC *hr;
                            for (n=0; templateParam; templateParam = templateParam->next, n++);
                            hr = funcsp->tp->syms->table[0];
                            while (hr && ((SYMBOL *)hr->p) != sp)
                                hr = hr->next;
                            while (hr && n)
                            {
                                lambda_capture((SYMBOL *)hr->p, localMode, TRUE);
                                hr = hr->next;
                                n--;
                            }
                        }
                        else
                        {
                            lambda_capture(sp, localMode, TRUE);
                        }
                    }
                    else
                        errorstr(ERR_UNDEFINED_IDENTIFIER, lex->value.s.a);
                }
                else
                {
                    error(ERR_INVALID_LAMBDA_CAPTURE_MODE);
                }
            } while (MATCHKW(lex, comma));
        }
        needkw(&lex, closebr);
    }
    else
    {
        if (!MATCHKW(lex, closebr))
        {
            error(ERR_LAMBDA_CANNOT_CAPTURE);
        }
        else
        {
            lex = getsym();
        }
    }
    if (MATCHKW(lex, openpa))
    {
        TYPE *tpx = &stdvoid;
        HASHREC *hr;
        lex = getFunctionParams(lex, NULL, &self->func, &tpx, FALSE, sc_auto);
        self->funcargs = self->func->tp->syms->table[0];
        hr = self->func->tp->syms->table[0];
        while (hr)
        {
            SYMBOL *sym = (SYMBOL *)hr->p;
            if (sym->init)
            {
                error(ERR_CANNOT_DEFAULT_PARAMETERS_WITH_LAMBDA);
            }
            hr = hr->next;
        }
        if (MATCHKW(lex, kw_mutable))
        {
            HASHREC *hr = self->captured->table[0];
            while (hr)
            {
                LAMBDASP *lsp = (LAMBDASP *)hr->p;
                if (lsp->sym->lambdaMode == cmValue)
                {
                    lsp->sym->tp = basetype(lsp->sym->tp);
                }
                hr = hr->next;
            }
            self->isMutable = TRUE;
            
            lex = getsym();
        }
        ParseAttributeSpecifiers(&lex, funcsp, TRUE);
        if (MATCHKW(lex, pointsto))
        {
            lex = getsym();
            lex = get_type_id(lex, &self->functp, funcsp, sc_cast, FALSE, TRUE);
        }
    }
    else
    {
        TYPE *tp1 = Alloc(sizeof(TYPE));
        SYMBOL *spi;
        tp1->type = bt_func;
        tp1->size = getSize(bt_pointer);
        tp1->btp = &stdvoid;
        tp1->sp = self->func;
        self->func->tp = tp1;
        spi = makeID(sc_parameter, tp1, NULL, AnonymousName());
        spi->anonymous = TRUE;
        spi->tp = Alloc(sizeof(TYPE));
        spi->tp->type = bt_void;
        insert(spi, localNameSpace->syms);
        SetLinkerNames(spi, lk_cpp);
        self->func->tp->syms = localNameSpace->syms;
        self->funcargs = self->func->tp->syms->table[0];
        self->func->tp->syms->table[0] = NULL;
    }
    vpl = makeID(sc_parameter, &stdpointer, NULL, AnonymousName());
    vpl->assigned = vpl->used = TRUE;
    SetLinkerNames(vpl, lk_cdecl);
    hrl = Alloc(sizeof(HASHREC));
    hrl->p = (struct _hrintern_ *)vpl;
    hrl->next = lambdas->func->tp->syms->table[0];
    lambdas->func->tp->syms->table[0] = hrl;
    vpl = makeID(sc_parameter, &stdpointer, NULL, AnonymousName());
    vpl->assigned = vpl->used = TRUE;
    SetLinkerNames(vpl, lk_cdecl);
    hrl = Alloc(sizeof(HASHREC));
    hrl->p = (struct _hrintern_ *)vpl;
    hrl->next = lambdas->func->tp->syms->table[0];
    lambdas->func->tp->syms->table[0] = hrl;
    SetLinkerNames(lambdas->func, lk_cdecl);
    injectThisPtr(lambdas->func, basetype(lambdas->func->tp)->syms);
    lambdas->func->tp->btp = self->functp;
    lambdas->func->linkage = lk_virtual;
    lambdas->func->isInline = TRUE;
    ssl.str = self->cls;
    ssl.tmpl = NULL;
    addStructureDeclaration(&ssl);
    ths = makeID(sc_member, &stdpointer, NULL, "$this");
    lambda_insert(ths, lambdas);
    if (MATCHKW(lex, begin))
    {
        lex = body(lex, self->func);
    }
    else
    {
        error(ERR_LAMBDA_FUNCTION_BODY_EXPECTED);
    }
    dropStructureDeclaration();
    localNameSpace->syms = self->oldSyms;
    localNameSpace->tags = self->oldTags;
    inferType();
    finishClass();
    *exp = createLambda(0);
    *tp = lambdas->cls->tp;
    lambdas = lambdas->next;
    if (lambdas)
        lambdas->prev = NULL;
    DecGlobalFlag();
    return lex;
}
Example #8
0
SYMBOL *lambda_capture(SYMBOL *sym, enum e_cm mode, BOOLEAN isExplicit)
{
    if (lambdas)
    {
        if (mode == cmThis)
        {
            if (!sym || (lambdas->lthis && sym->parentClass == basetype(lambdas->lthis->tp)->btp->sp))
            {
                if (lambdas->captureThis)
                {
                    BOOLEAN errorflg = FALSE;
                    LAMBDA *check = lambdas;
                    // have to try to replicate the symbol into the current context
                    while (check && !error)
                    {
                        if (check->captureMode == cmNone)
                        {
                            if (isExplicit)
                            {
                                if (lambdas->prev)
                                {
                                    errorflg = TRUE;
                                    errorstr(ERR_EXPLICIT_CAPTURE_BLOCKED, "this");
                                }
                            }
                            else
                            {
                                errorflg = TRUE;
                                errorstr(ERR_IMPLICIT_CAPTURE_BLOCKED, "this");
                            }
                        }
                        else if (check->captureMode == cmValue && isExplicit)
                        {
                            errorflg = TRUE;
                            errorstr(ERR_EXPLICIT_CAPTURE_BLOCKED, "this");
                        }
                        check = check->next;
                    }
                    if (!errorflg)
                    {
                        check = lambdas;
                        while (check)
                        {
                            check->captureThis = TRUE;
                            check = check->next;
                        }
                    }
                }
                else
                {
                     errorstr(ERR_IMPLICIT_CAPTURE_BLOCKED, "this");
                }
            }
        }
        else
        {
            if (sym->parent != lambdas->func)
            {
                if (sym->storage_class != sc_auto && sym->storage_class != sc_parameter)
                {
                    error(ERR_MUST_CAPTURE_AUTO_VARIABLE);
                }
                else
                {
                    LAMBDA *current = lambdas;
                    SYMBOL *sym2 = NULL;
                    LAMBDA *check;
                    while (current)
                    {
                        LAMBDASP *lsp = (LAMBDASP *)search(sym->name, current->captured);
                        if (lsp)
                        {
                            sym2 = lsp->sym;
                            break;
                        }
                        current = current->next;
                    }
                    if (sym2)
                    {
                        if (lambdas == current && isExplicit)
                        {
                            error(ERR_CAPTURE_ITEM_LISTED_MULTIPLE_TIMES);        
                        }
                        sym = sym2;
                        current = current->prev;
                    }
                    else
                    {
                        current = lambdas;
                        while (current->next) current = current->next;
                    }
                    check = current;
                    // have to try to replicate the symbol into the current context
                    while (check)
                    {
                        if (check->captureMode == cmNone)
                        {
                            if (isExplicit)
                            {
                                if (check->prev)
                                {
                                    check = NULL;
                                    errorsym(ERR_EXPLICIT_CAPTURE_BLOCKED, sym);
                                }
                            }
                            else
                            {
                                check = NULL;
                                errorsym(ERR_IMPLICIT_CAPTURE_BLOCKED, sym);
                            }
                        }
                        if (check)
                            check = check->prev;
                    }
                    IncGlobalFlag();
                    while (current)
                    {
                        // we are replicating captures through intermediate lambdas
                        // to make it easier to handle inner lambda creation.
                        LAMBDASP *ins = Alloc(sizeof(LAMBDASP));
                        ins->name = sym->name;
                        ins->parent = sym;
                        sym = clonesym(sym);
                        sym->lambdaMode = mode == cmNone ? current->captureMode : mode;
                        sym->tp = lambda_type(sym->tp, sym->lambdaMode);
                        sym->storage_class = sc_member;
                        sym->parent = current->func;
                        sym->init = NULL;
                        lambda_insert(sym, current);
                        ins->sym = sym;
                        ins->enclosing = current;
                        insert((SYMBOL *)ins, current->captured);
                        current = current->prev;
                    }
                    DecGlobalFlag();
                }
            }
        }
    }
    return sym;
}
Example #9
0
font::font( FT_Face face, std::string fam, std::string style, double pixsize )
		: script::font( std::move( fam ), std::move( style ), pixsize ),
		  _face( face )
{
	auto err = FT_Select_Charmap( _face, FT_ENCODING_UNICODE );
	if ( err )
	{
		std::cerr << "ERROR selecting UNICODE charmap: [" << FT_Errors[err].code << "] " << FT_Errors[err].message << std::endl;
		if ( _face->charmaps )
		{
			err = FT_Set_Charmap( _face, _face->charmaps[0] );
			if ( err )
				throw std::runtime_error( errorstr( err ) );
		}
		else
			throw std::runtime_error( "Unable to select any character map" );
	}

	std::cout << "Need to add global DPI accessor somehow (multiple screens?)" << std::endl;
	static const int theDPI = 95;

	if ( FT_IS_SCALABLE( _face ) )
	{
		err = FT_Set_Char_Size( _face, static_cast<int>( pixsize * 64.0 ), 0,
								theDPI, theDPI );
		if ( err )
			throw std::runtime_error( "Unable to set character size" );
	}
	else if ( _face->num_fixed_sizes > 1 )
	{
		int targsize = static_cast<int>( pixsize );
		int bestSize[2];
		bestSize[0] = bestSize[1] = targsize;
		int i;
		for ( i = 0; i != _face->num_fixed_sizes; ++i )
		{
			if ( _face->available_sizes[i].width == targsize )
			{
				bestSize[1] = _face->available_sizes[i].height;
				break;
			}
			else if ( _face->available_sizes[i].width > targsize &&
					  bestSize[0] > _face->available_sizes[i].width )
			{
				bestSize[0] = _face->available_sizes[i].width;
				bestSize[1] = _face->available_sizes[i].height;
			}
		}

		if ( i == _face->num_fixed_sizes )
			_size = bestSize[0];

		// otherwise we have to use FT_Set_Pixel_Sizes
		err = FT_Set_Pixel_Sizes( _face, static_cast<FT_UInt>( bestSize[0] ), static_cast<FT_UInt>( bestSize[1] ) );
		if ( err )
			throw std::runtime_error( "Unable to set fixed character size" );
	}

	_extents.ascent = static_cast<double>( _face->size->metrics.ascender ) / 64.0;
	_extents.descent = static_cast<double>( _face->size->metrics.descender ) / 64.0;

	if ( FT_IS_SCALABLE( _face ) )
	{
		double scaleX = ( static_cast<double>( _face->size->metrics.x_ppem ) /
						  static_cast<double>( _face->units_per_EM ) );
		double scaleY = ( static_cast<double>( _face->size->metrics.y_ppem ) /
						  static_cast<double>( _face->units_per_EM ) );
		_extents.width = std::ceil( static_cast<double>( _face->bbox.xMax - _face->bbox.xMin ) * scaleX );
		_extents.height = static_cast<double>( _face->size->metrics.height ) / 64.0;
			// was: std::ceil( static_cast<double>( _face->bbox.yMax - _face->bbox.yMin ) * scaleY );

		_extents.max_x_advance = static_cast<double>( _face->max_advance_width ) * scaleX;
		_extents.max_y_advance = static_cast<double>( _face->max_advance_height ) * scaleY;
	}
	else
	{
		_extents.width = static_cast<double>( _face->size->metrics.max_advance ) / 64.0;
		_extents.height = static_cast<double>( _face->size->metrics.height ) / 64.0;

		_extents.max_x_advance = static_cast<double>( _face->size->metrics.max_advance ) / 64.0;
		_extents.max_y_advance = 0.0;
	}

}
Example #10
0
File: pe184.c Project: manish05/TCR
void clerror(char *s,cl_int err) {
	printf("%s: %s\n",s,errorstr(err));
	exit(1);
}