Пример #1
0
 GrammarNode* Grammar::UnrollFuncExpansion(GrammarFunc* Node,
                                           const set<string>& DefVars)
 {
     auto const& Children = Node->GetChildren();
     const uint32 NumChildren = Children.size();
     vector<GrammarNode*> UnrolledChildren(NumChildren);
     
     for (uint32 i = 0; i < NumChildren; ++i) {
         UnrolledChildren[i] = UnrollExpansion(GenExtNode(Children[i], DefVars));
     }
     return MakeFunc(Node->GetOp()->GetName(), UnrolledChildren);
 }
Пример #2
0
/* (), fn(), [], <x, y, z>, . */
Expr *Term15(void)
{
	switch(token) 
	{
		/* 0 parameter functions returning floats */
		case FN_FRAND:
			return MakeFunc(eval_frand, 0, 0);

		/* 0 parameter functions returning vectors */
		case FN_VRAND:
			return MakeFunc(eval_vrand, 0, 1);

		/* 1 parameter functions returning floats */
		case FN_ABS:
			return MakeFunc(eval_abs, 1, 0);
		case FN_ACOS:
			return MakeFunc(eval_acos, 1, 0);
		case FN_ASIN:
			return MakeFunc(eval_asin, 1, 0);
		case FN_ATAN:
			return MakeFunc(eval_atan, 1, 0);
		case FN_CEIL:
			return MakeFunc(eval_ceil, 1, 0);
		case FN_CHECKER:
			return MakeFunc(eval_checker, 1, 0);
		case FN_COS:
			return MakeFunc(eval_cos, 1, 0);
		case FN_COSH:
			return MakeFunc(eval_cosh, 1, 0);
		case FN_EXP:
			return MakeFunc(eval_exp, 1, 0);
		case FN_FLOOR:
			return MakeFunc(eval_floor, 1, 0);
		case FN_INT:
			return MakeFunc(eval_int, 1, 0);
		case FN_IRAND:
			return MakeFunc(eval_irand, 1, 0);
		case FN_LOG:
			return MakeFunc(eval_log, 1, 0);
		case FN_LOG10:
			return MakeFunc(eval_log10, 1, 0);
		case FN_NOISE:
			return MakeFunc(eval_noise, 1, 0);
		case FN_ROUND:
			return MakeFunc(eval_round, 1, 0);
		case FN_SIN:
			return MakeFunc(eval_sin, 1, 0);
		case FN_SINH:
			return MakeFunc(eval_sinh, 1, 0);
		case FN_SQRT:
			return MakeFunc(eval_sqrt, 1, 0);
		case FN_TAN:
			return MakeFunc(eval_tan, 1, 0);
		case FN_TANH:
			return MakeFunc(eval_tanh, 1, 0);
		case FN_VMAG:
			return MakeFunc(eval_vmag, 1, 0);

		/* 1 parameter functions returning vectors */
		case FN_VNOISE:
			return MakeFunc(eval_vnoise, 1, 1);
		case FN_VNORM:
			return MakeFunc(eval_vnorm, 1, 1);

		/* 2 parameter functions returning floats */
		case FN_ATAN2:
			return MakeFunc(eval_atan2, 2, 0);
		case FN_HEXAGON:
			return MakeFunc(eval_hexagon, 2, 0);
		case FN_TURB:
			return MakeFunc(eval_turb, 2, 0);
		case FN_VDOT:
			return MakeFunc(eval_vdot, 2, 0);

		/* 2 parameter functions returning vectors */
		case FN_COLOR_MAP:
			return MakeHandleFunc(eval_color_map,
				DECL_COLOR_MAP, 1, 1);
		case FN_IMAGE_MAP:
			return MakeImageMapFunc(eval_image_map);
		case FN_SMOOTH_IMAGE_MAP:
			return MakeImageMapFunc(eval_smooth_image_map);
		case FN_VCROSS:
			return MakeFunc(eval_vcross, 2, 1);
		case FN_VTURB:
			return MakeFunc(eval_vturb, 2, 1);
		case FN_WRINKLE:
			return MakeFunc(eval_wrinkle, 2, 1);

		/* 3 parameter functions returning floats */
		case FN_CLAMP:
			return MakeFunc(eval_clamp, 3, 0);
		case FN_LEGENDRE:
			return MakeFunc(eval_legendre, 3, 0);
		case FN_LERP:
			return MakeFunc(eval_lerp, 3, 0);

		/* 3 parameter functions with indeterminate return type */
		case FN_CHECKER2:
			return MakeFunc(eval_checker2, 3, 0);

		/* 3 parameter functions returning vectors */
		case FN_VROTATE:
			return MakeFunc(eval_vrotate, 3, 1);
		case FN_VLERP:
			return MakeFunc(eval_vlerp, 3, 1);

		/* 4 parameter functions returning floats */
		case FN_TURB2:
			return MakeFunc(eval_turb2, 4, 0);

		/* 4 parameter functions returning vectors */
		case FN_VTURB2:
			return MakeFunc(eval_vturb2, 4, 1);

		/* 5 parameter functions with indeterminate return type */
		case FN_HEXAGON2:
			return MakeFunc(eval_hexagon2, 5, 0);

		case OP_LPAREN:
		{
			Expr *expr;
			token = GetToken();
			expr = Term0();
			if(token == OP_RPAREN)
				token = GetToken();
			else
				ErrUnknown(token, ")", "expression syntax");
			return expr;
		}
		break;

		case OP_LESSTHAN:  /* starting a vector triplet */
			return MakeVec();

		default:
			break;
	}
	return Atom();
}