示例#1
0
static void
vcc_Eval_Regsub(struct vcc *tl, struct expr **e, const struct symbol *sym)
{
	struct expr *e2;
	int all = sym->eval_priv == NULL ? 0 : 1;
	char *p;
	char buf[128];

	vcc_delete_expr(*e);
	SkipToken(tl, ID);
	SkipToken(tl, '(');

	vcc_expr0(tl, &e2, STRING);
	if (e2->fmt != STRING)
		vcc_expr_tostring(&e2, STRING);

	SkipToken(tl, ',');
	ExpectErr(tl, CSTR);
	p = vcc_regexp(tl);
	vcc_NextToken(tl);

	bprintf(buf, "VRT_regsub(sp, %d,\n\v1,\n%s\n", all, p);
	*e = vcc_expr_edit(STRING, buf, e2, *e);

	SkipToken(tl, ',');
	vcc_expr0(tl, &e2, STRING);
	if (e2->fmt != STRING)
		vcc_expr_tostring(&e2, STRING);
	*e = vcc_expr_edit(STRING, "\v1, \v2)", *e, e2);
	SkipToken(tl, ')');
}
示例#2
0
const char *ParseTexCoords(const char *pText, F3DSubObject &sub, int numPositions)
{
	SkipToken(pText, "{");

	// get num positions
	int numUV = GetInt(pText, &pText);
	MFDebug_Assert(numUV == numPositions, "Number of UV's does not match the number of verts in the mesh.");

	sub.uvs.resize(numUV);

	// read positions
	for(int a=0; a<numUV; a++)
	{
		sub.uvs[a].x = GetFloat(pText, &pText);
		sub.uvs[a].y = GetFloat(pText, &pText);

		if(a < numUV-1)
			SkipToken(pText, ",");
	}
	SkipToken(pText, ";");

	// map to faces
	for(int m=0; m<sub.matSubobjects.size(); m++)
	{
		int totalVerts = sub.matSubobjects[m].vertices.size();
		for(int a=0; a<totalVerts; a++)
		{
			sub.matSubobjects[m].vertices[a].uv1 = sub.matSubobjects[m].vertices[a].position;
		}
	}

	SkipToken(pText, "}");

	return pText;
}
示例#3
0
文件: parser.c 项目: markcheno/topaz
static void UnlessStatement(void)
{
	Int32 l1,l2;

	SkipToken(tUNLESS);
	
	Expr();
	
	if( Token==tTHEN ) NextToken();

	l1 = vm_genI(op_jz,0);
	
	StatementList();
	
	if( Token==tELSE )
	{
		SkipToken(tELSE);
		l2 = vm_genI(op_jmp,0);
		vm_patch(l1,vm_addr());
		l1 = l2;
		StatementList();
	}

	vm_patch(l1,vm_addr());

	SkipToken(tEND);
}
示例#4
0
文件: parser.c 项目: markcheno/topaz
static void FormalParamList(SymPtr func)
{
	SymPtr t,p;
	Int32 num,shift;

	SkipToken(tLPAREN);
	if(Token==tVARIABLE)
	{
		FormalParam();
		func->nargs++;
	}
	
	while( Token==tCOMMA )
	{
		SkipToken(tCOMMA);
		FormalParam();
		func->nargs++;
	}
	SkipToken(tRPAREN);		

	/* Reverse and shift the argument numbers (if any).
	   Arguments are located directly after the function. */
	p = func;
	shift = in_class ? 2 : 1;
	for( num=-func->nargs; num<0; num++ )
	{
		/* shift to make room for argc and maybe class  */
		t = p->next;
        p = t;
		p->num = num-shift;
	}
}
示例#5
0
文件: parser.c 项目: markcheno/topaz
static Int32 ActualParams(void)
{
	Int32 args=0;

	if( Token==tLPAREN )
	{
		SkipToken(tLPAREN);
		
		if( Token != tRPAREN ) 
		{
			Expr();
			args++;

			while( Token==tCOMMA )
			{
				SkipToken(tCOMMA);
				Expr();
				args++;
			}
		}
		SkipToken(tRPAREN);
	}

	return args;
}
示例#6
0
文件: parser.c 项目: markcheno/topaz
static void CaseStatement(void)
{
	Int32 ii=0;
	Int32 l1,l2[MAXCOND];

	SkipToken(tCASE);

	Expr();

	while( Token==tWHEN )
	{
		SkipToken(tWHEN);
		vm_gen0(op_dup);
		Expr();
		if( Token==tTHEN ) NextToken();
		vm_gen0(op_eql);
		l1 = vm_genI(op_jz,0);
		StatementList();
		l2[ii++] = vm_genI(op_jmp,0);
		vm_patch(l1,vm_addr());
	}
	
	if( Token==tELSE )
	{
		SkipToken(tELSE);
		StatementList();
	}

	while( --ii >= 0 )
		vm_patch(l2[ii],vm_addr());

	vm_gen0(op_pop);
	
	SkipToken(tEND);
}
示例#7
0
static void
vcc_Compound(struct vcc *tl)
{
	int i;

	SkipToken(tl, '{');
	Fb(tl, 1, "{\n");
	tl->indent += INDENT;
	C(tl, ";");
	while (1) {
		ERRCHK(tl);
		switch (tl->t->tok) {
		case '{':
			vcc_Compound(tl);
			break;
		case '}':
			vcc_NextToken(tl);
			tl->indent -= INDENT;
			Fb(tl, 1, "}\n");
			return;
		case CSRC:
			if (tl->allow_inline_c) {
				Fb(tl, 1, "%.*s\n",
				    (int) (tl->t->e - (tl->t->b + 2)),
				    tl->t->b + 1);
				vcc_NextToken(tl);
			} else {
				VSB_printf(tl->sb,
				    "Inline-C not allowed\n");
				vcc_ErrWhere(tl, tl->t);
			}
			break;
		case EOI:
			VSB_printf(tl->sb,
			    "End of input while in compound statement\n");
			tl->err = 1;
			return;
		case ID:
			if (vcc_IdIs(tl->t, "if")) {
				vcc_IfStmt(tl);
				break;
			} else {
				i = vcc_ParseAction(tl);
				ERRCHK(tl);
				if (i) {
					SkipToken(tl, ';');
					break;
				}
			}
			/* FALLTHROUGH */
		default:
			/* We deliberately do not mention inline C */
			VSB_printf(tl->sb,
			    "Expected an action, 'if', '{' or '}'\n");
			vcc_ErrWhere(tl, tl->t);
			return;
		}
	}
}
示例#8
0
void XFileLoader::ReadArray(istream& s, iter b, iter e)
{
	for (iter i = b; i != e; ++i)
	{
		if (i != b)
			SkipToken(s, XFileToken::Comma);
		ReadData(s, *i);
	}
	SkipToken(s, XFileToken::Semicolon);
}
示例#9
0
文件: parser.c 项目: markcheno/topaz
static SymPtr LookupIdent(char **name)
{
	SymPtr sym=NULL,parent;
	
    /* check this class only */
	if( in_class && Token==tSELF )
	{
		SkipToken(tSELF);
		SkipToken(tPERIOD);
		*name = GetIdent();
		sym = SymFindLevel(*name,(SymGetScope()-1));
	}
    /* check super class only */
	else if( in_class && Token==tSUPER && base_class->super!=NULL )
	{
	    SkipToken(tSUPER);
	    SkipToken(tPERIOD);
	    *name = GetIdent();
	    sym = SymFindLocal(*name,base_class->super);
        
	    if( sym!=NULL && sym->flags&SYM_PRIVATE )
	    {
		    compileError("attempt to access private field '%s'",*name);
		    NextToken();
		    return COMPILE_ERROR;
	    }
	}
	/* check all super classes */
    else if( in_class )
	{
        *name = GetIdent();
        parent=base_class->super;
        while(parent!=NULL)
        {
            sym = SymFindLocal(*name,parent);
            if(sym!=NULL) break;
            parent=parent->super;
        }
	   	if( sym!=NULL && sym->flags&SYM_PRIVATE )
	    {
		    compileError("attempt to access private field '%s'",*name);
		    NextToken();
		    return COMPILE_ERROR;
	    }
	}
    
    /* check globals */
    if( sym==NULL )
	{
		*name = GetIdent();
		sym = SymFind(*name);
	}
    
	return sym;
}
示例#10
0
static void
vcc_Conditional(struct vcc *tl)
{

	SkipToken(tl, '(');
	Fb(tl, 0, "(\n");
	L(tl, vcc_Expr(tl, BOOL));
	ERRCHK(tl);
	Fb(tl, 1, ")\n");
	SkipToken(tl, ')');
}
示例#11
0
static void
parse_hash_data(struct vcc *tl)
{
	vcc_NextToken(tl);
	SkipToken(tl, '(');

	Fb(tl, 1, "VRT_hashdata(ctx, ");
	vcc_Expr(tl, STRING_LIST);
	ERRCHK(tl);
	Fb(tl, 0, ");\n");
	SkipToken(tl, ')');
}
示例#12
0
文件: parser.c 项目: markcheno/topaz
static void MethodDefinition(void)
{
	Pointer name;
	SymPtr sym;
	Int32 l1,shift;
	
	SkipToken(tDEF);
	/* MatchToken(tVARIABLE); */

	name = GetIdent();
	/* maybe check for duplicates here? */
	sym = SymAdd(name);
	sym->kind = FUNCTION_KIND;
	sym->object.u.ival = vm_addr();
	sym->flags |= cur_scope;
	if( in_class && base_class!=NULL ) sym->clas=base_class;
    if( in_class && super_class!=NULL ) sym->super=super_class;
    
	NextToken();
	SymEnterScope();
	in_method=TRUE;
	l1 = vm_genI(op_link,0);
		
	/* check for any formal parameters */
	if( Token==tLPAREN )
	{
		FormalParamList(sym);
	}
	
	/* function statements */
	local_num=0;
	StatementList();
	sym->nlocs = local_num;

	/* backpatch any return statements */
	CheckReturn(sym);

	/* implicit return */
	shift = in_class ? 2 : 1;
	vm_genI(op_rts,sym->nlocs+sym->nargs+shift);
	
	/* reserve space for locals */
	vm_patch(l1,sym->nlocs);	
	
	SymExitScope(sym);
	in_method=FALSE;
	/* end of function */
	SkipToken(tEND);
	if( Token==tSEMI ) NextToken();
}
示例#13
0
文件: parser.c 项目: markcheno/topaz
static void ForStatement(void)
{
	Int32 l1,l2,l3,l4;
	
	SkipToken(tFOR);
	SkipToken(tLPAREN);
	
	/* init */
	if( Token != tSEMI )
	{
		AssignmentStatement();
        while( Token==tCOMMA )
        {
            SkipToken(tCOMMA);
    		AssignmentStatement();    
        }
	}
	SkipToken(tSEMI);
	
	/* cond */
	l1 = vm_addr();
    if( Token != tSEMI )
    {
	    Expr();
    }
    else
    {
    	vm_genI(op_pushint,1);
    }
	l2 = vm_genI(op_jnz,0);
	l3 = vm_genI(op_jmp,0);
	
	/* incr */
	SkipToken(tSEMI);
	vm_patch(l3,vm_addr());
	l4 = vm_addr();
    if( Token != tRPAREN )
    {
	    AssignmentStatement();
        while( Token==tCOMMA )
        {
            SkipToken(tCOMMA);
            AssignmentStatement();
        }
    }
	vm_genI(op_jmp,l1);
	
	/* statements */
	SkipToken(tRPAREN);
	vm_patch(l2,vm_addr());
	StatementList();
	vm_genI(op_jmp,l4);
	
	/* done */
	vm_patch(l3,vm_addr());
	CheckBreak();
	
	SkipToken(tEND);
}
示例#14
0
文件: parser.c 项目: markcheno/topaz
static Int32 Factor(void)
{
    Int32 type;
	
	switch(Token)
	{
	case tINTCONST:
		vm_genI(op_pushint,GetInt());
		NextToken();
        type=INT_TYPE;
		break;
	
	case tREALCONST:
		vm_genR(op_pushreal,GetReal());
		NextToken();
        type=REAL_TYPE;
		break;
		
	case tSTRINGCONST:
		vm_genS(op_pushstring,GetString());
		NextToken();
        type=STRING_TYPE;
		break;
		
	case tNOT:
        NextToken();
		type=Factor();
		vm_gen0(op_not);
		break;
		
	case tLPAREN:
		SkipToken(tLPAREN);
		type=Expr();
		SkipToken(tRPAREN);
		break;

	case tLBRACK:
		ArrayInitializer();
        type=ARRAY_TYPE;
		break;

	default:
		type=Rhs();
		break;
	}
    
    return type;
}
示例#15
0
static void
parse_error(struct vcc *tl)
{

	vcc_NextToken(tl);
	Fb(tl, 1, "VRT_error(sp,\n");
	if (tl->t->tok == '(') {
		vcc_NextToken(tl);
		vcc_Expr(tl, INT);
		if (tl->t->tok == ',') {
			Fb(tl, 1, ",\n");
			vcc_NextToken(tl);
			vcc_Expr(tl, STRING);
		} else
			Fb(tl, 1, ", 0\n");
		SkipToken(tl, ')');
	} else {
		vcc_Expr(tl, INT);
		if (tl->t->tok != ';') {
			Fb(tl, 1, ",\n");
			vcc_Expr(tl, STRING);
		} else
			Fb(tl, 1, ", 0\n");
	}
	Fb(tl, 1, ");\n");
	Fb(tl, 1, "VRT_done(sp, VCL_RET_ERROR);\n");
}
示例#16
0
static void
parse_set(struct vcc *tl)
{
	const struct var *vp;
	const struct arith *ap;
	enum var_type fmt;

	vcc_NextToken(tl);
	ExpectErr(tl, ID);
	vp = vcc_FindVar(tl, tl->t, 1, "cannot be set");
	ERRCHK(tl);
	assert(vp != NULL);
	Fb(tl, 1, "%s", vp->lname);
	vcc_NextToken(tl);
	fmt = vp->fmt;
	for (ap = arith; ap->type != VOID; ap++) {
		if (ap->type != fmt)
			continue;
		if (ap->oper != tl->t->tok)
			continue;
		if (ap->oper != '=')
			Fb(tl, 0, "%s %c ", vp->rname, *tl->t->b);
		vcc_NextToken(tl);
		fmt = ap->want;
		break;
	}
	if (ap->type == VOID)
		SkipToken(tl, ap->oper);
	if (fmt == STRING) {
		vcc_Expr(tl, STRING_LIST);
	} else {
		vcc_Expr(tl, fmt);
	}
	Fb(tl, 1, ");\n");
}
示例#17
0
void XFileLoader::ReadData<glm::mat4>(istream& s, glm::mat4& d)
{
	float elems[16];
    ReadArray(s, elems, elems + 16);
    d = make_mat4(elems);
	SkipToken(s, XFileToken::Semicolon);
}
示例#18
0
文件: parser.c 项目: markcheno/topaz
static Int32 ArrayValue(Int32 size)
{
	Int32 repeat;
	
	vm_gen0(op_dup);					/* var */

	if( Token==tINTCONST && LookAheadChar()=='x' )
	{
		/* Handle array repeat operator.
		   We must use an intconst because 
		   we need to know the array size 
		   at compile time. */
		repeat = GetInt();
		SkipChar();
		SkipToken(tINTCONST);
		vm_genI(op_pushint,size);		/* start-idx */
		size += repeat;
		vm_genI(op_pushint,size-1); 	/* end-idx   */
		Expr(); 						/* val       */
		vm_gen0(op_setslice);
	}
	else
	{
		/* single expression */
		vm_genI(op_pushint,size++); 	/* idx */
		Expr(); 						/* val */
		vm_gen0(op_setarray);
	}
	
	return size;
}
示例#19
0
const char *ParseAnimationSet(const char *pText)
{
	const char *pName = GetNextToken(pText, &pText);

	if(MFString_Compare(pName, "{"))
		SkipToken(pText, "{");

	const char *pTok = GetNextToken(pText, &pText);

	while(MFString_Compare(pTok, "}"))
	{
		if(!MFString_Compare(pTok, "Animation"))
		{
			pText = ParseAnimation(pText);
		}
		else
		{
			MFDebug_Warn(4, MFStr("Unexpected token '%s'\n", pTok));
			SkipSection(pText);
		}

		pTok = GetNextToken(pText, &pText);
	}

	return pText;
}
// -------------------------------------------------------------------
void ObjFileParser::getVector( std::vector<aiVector3D> &point3d_array ) {
    size_t numComponents( 0 );
    const char* tmp( &m_DataIt[0] );
    while( !IsLineEnd( *tmp ) ) {
        if ( !SkipSpaces( &tmp ) ) {
            break;
        }
        SkipToken( tmp );
        ++numComponents;
    }
    float x, y, z;
    if( 2 == numComponents ) {
        copyNextWord( m_buffer, BUFFERSIZE );
        x = ( float ) fast_atof( m_buffer );

        copyNextWord( m_buffer, BUFFERSIZE );
        y = ( float ) fast_atof( m_buffer );
        z = 0.0;
    } else if( 3 == numComponents ) {
        copyNextWord( m_buffer, BUFFERSIZE );
        x = ( float ) fast_atof( m_buffer );

        copyNextWord( m_buffer, BUFFERSIZE );
        y = ( float ) fast_atof( m_buffer );

        copyNextWord( m_buffer, BUFFERSIZE );
        z = ( float ) fast_atof( m_buffer );
    } else {
        throw DeadlyImportError( "OBJ: Invalid number of components" );
    }
    point3d_array.push_back( aiVector3D( x, y, z ) );
    m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
}
示例#21
0
static void
vxp_expr_group(struct vxp *vxp, struct vex **pvex)
{

	AN(pvex);
	AZ(*pvex);

	if (vxp->t->tok == '(') {
		SkipToken(vxp, '(');
		vxp_expr_or(vxp, pvex);
		ERRCHK(vxp);
		SkipToken(vxp, ')');
		return;
	}

	vxp_expr_cmp(vxp, pvex);
}
示例#22
0
static  void    DefOption( opt_entry *optn, char *ptr ) {
//=======================================================

// Define a macro.

    optn = optn;
    MacroDEFINE( ptr, SkipToken( ptr ) - ptr );
}
示例#23
0
文件: parser.c 项目: markcheno/topaz
static void UntilStatement(void)
{
	Int32 l1,l2;

	SkipToken(tUNTIL);

	l1 = vm_addr();
	Expr();
	if( Token==tDO ) NextToken();
	l2 = vm_genI(op_jnz,0);
	StatementList();
	vm_genI(op_jmp,l1);
	vm_patch(l2,vm_addr());
	CheckBreak();
	
	SkipToken(tEND);
}
示例#24
0
文件: parser.c 项目: markcheno/topaz
static void ProtectedStatement(void)
{
	SkipToken(tPROTECTED);
	cur_scope=SYM_PROTECTED;
	if(!in_class || in_method)
	{
		compileError("protected only valid inside a class definition");
	}
}
示例#25
0
文件: parser.c 项目: markcheno/topaz
static void PrivateStatement(void)
{
	SkipToken(tPRIVATE);
	cur_scope=SYM_PRIVATE;
	if(!in_class || in_method)
	{
		compileError("private only valid inside a class definition");
	}
}
示例#26
0
文件: parser.c 项目: markcheno/topaz
static void PublicStatement(void)
{
	SkipToken(tPUBLIC);
	cur_scope=SYM_PUBLIC;	
	if(!in_class || in_method)
	{
		compileError("public only valid inside a class definition");
	}
}
示例#27
0
文件: parser.c 项目: markcheno/topaz
static void IfStatement(void)
{
	Int32 ii=0;
	Int32 l1,l2[MAXCOND];
	
	SkipToken(tIF);
	
	Expr();
	
	if( Token==tTHEN ) 
		NextToken();
	
	l1 = vm_genI(op_jz,0);
	
	StatementList();

	l2[ii++] = vm_genI(op_jmp,0);
	
	while( Token==tELSIF )
	{
		SkipToken(tELSIF);
		vm_patch(l1,vm_addr());
		Expr();
		if( Token==tTHEN ) NextToken();
		l1 = vm_genI(op_jz,0);
		StatementList();
		l2[ii++] = vm_genI(op_jmp,0);
	}

	vm_patch(l1,vm_addr());
	
	if( Token==tELSE )
	{
		SkipToken(tELSE);
		StatementList();
	}

	while( --ii >= 0 )
	{
		vm_patch(l2[ii],vm_addr());
	}
	
	SkipToken(tEND);
}
示例#28
0
文件: parser.c 项目: markcheno/topaz
static void ArrayInitializer(void)
{
	Int32 label,size=0;
	
	label = vm_genI(op_pushint,0);
	vm_gen0(op_newarray);

	SkipToken(tLBRACK);
	size = ArrayValue(size);
	
	while( Token==tCOMMA )
	{
		SkipToken(tCOMMA);
		size = ArrayValue(size);
	}
	
	SkipToken(tRBRACK);
	vm_patch(label,size);
}
void
vcc_ParseRoundRobinDirector(struct vcc *tl)
{
	struct token *t_field, *t_be;
	int nelem;
	struct fld_spec *fs;
	const char *first;
	char *p;

	fs = vcc_FldSpec(tl, "!backend", NULL);

	Fc(tl, 0, "\nstatic const struct vrt_dir_round_robin_entry "
	    "vdrre_%.*s[] = {\n", PF(tl->t_dir));

	for (nelem = 0; tl->t->tok != '}'; nelem++) {	/* List of members */
		first = "";
		t_be = tl->t;
		vcc_ResetFldSpec(fs);

		SkipToken(tl, '{');
		Fc(tl, 0, "\t{");

		while (tl->t->tok != '}') {	/* Member fields */
			vcc_IsField(tl, &t_field, fs);
			ERRCHK(tl);
			if (vcc_IdIs(t_field, "backend")) {
				vcc_ParseBackendHost(tl, nelem, &p);
				ERRCHK(tl);
				AN(p);
				Fc(tl, 0, "%s .host = VGC_backend_%s",
				    first, p);
			} else {
				ErrInternal(tl);
			}
			first = ", ";
		}
		vcc_FieldsOk(tl, fs);
		if (tl->err) {
			VSB_printf(tl->sb,
			    "\nIn member host specification starting at:\n");
			vcc_ErrWhere(tl, t_be);
			return;
		}
		Fc(tl, 0, " },\n");
		vcc_NextToken(tl);
	}
	Fc(tl, 0, "};\n");
	Fc(tl, 0,
	    "\nstatic const struct vrt_dir_round_robin vgc_dir_priv_%.*s = {\n",
	    PF(tl->t_dir));
	Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(tl->t_dir));
	Fc(tl, 0, "\t.nmember = %d,\n", nelem);
	Fc(tl, 0, "\t.members = vdrre_%.*s,\n", PF(tl->t_dir));
	Fc(tl, 0, "};\n");
}
示例#30
0
文件: parser.c 项目: markcheno/topaz
static SymPtr FieldReference(SymPtr clas)
{
	SymPtr field,parent;
	char *fieldname;
	
	SkipToken(tPERIOD);
	fieldname = GetIdent();
	    
	/* lookup field in class and parents */
	parent=clas;
	while( parent!=NULL )
	{
		field = SymFindLocal(fieldname,parent);
		if( field!=NULL ) break;
		parent = parent->super;
	}

	if( field==NULL )
	{
		compileError("field '%s' not found",fieldname); 
		return NULL;
	}
	
	field->flags |= SYM_FIELD; /* MCC */
	
	if( field->flags&SYM_PRIVATE )
	{
		compileError("attempt to access private field '%s'",fieldname);
		return NULL;
	}
	
	if( field->flags&SYM_PROTECTED && !in_class )
	{
		compileError("attempt to access protected field '%s'",fieldname);
		return NULL;
	}

	NextToken();

	if( is_func_kind(field) )
    {
		return field;
    }
	
	if( is_global_kind(clas) )
	{
		vm_genI(op_getglobal,clas->num);
	}
	else if( is_local_kind(clas) )
	{
		vm_genI(op_getlocal,clas->num);
	}

	return field;
}