2 * Mesa 3-D graphics library
5 * Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * \file slang_compile_operation.c
27 * slang front-end compiler
32 #include "slang_compile.h"
36 int slang_operation_construct (slang_operation
*oper
)
38 oper
->type
= slang_oper_none
;
39 oper
->children
= NULL
;
40 oper
->num_children
= 0;
41 oper
->literal
= (float) 0;
42 oper
->a_id
= SLANG_ATOM_NULL
;
43 oper
->locals
= (slang_variable_scope
*) slang_alloc_malloc (sizeof (slang_variable_scope
));
44 if (oper
->locals
== NULL
)
46 _slang_variable_scope_ctr (oper
->locals
);
50 void slang_operation_destruct (slang_operation
*oper
)
54 for (i
= 0; i
< oper
->num_children
; i
++)
55 slang_operation_destruct (oper
->children
+ i
);
56 slang_alloc_free (oper
->children
);
57 slang_variable_scope_destruct (oper
->locals
);
58 slang_alloc_free (oper
->locals
);
61 int slang_operation_copy (slang_operation
*x
, const slang_operation
*y
)
66 if (!slang_operation_construct (&z
))
69 z
.children
= (slang_operation
*) slang_alloc_malloc (y
->num_children
* sizeof (slang_operation
));
70 if (z
.children
== NULL
)
72 slang_operation_destruct (&z
);
75 for (z
.num_children
= 0; z
.num_children
< y
->num_children
; z
.num_children
++)
76 if (!slang_operation_construct (&z
.children
[z
.num_children
]))
78 slang_operation_destruct (&z
);
81 for (i
= 0; i
< z
.num_children
; i
++)
82 if (!slang_operation_copy (&z
.children
[i
], &y
->children
[i
]))
84 slang_operation_destruct (&z
);
87 z
.literal
= y
->literal
;
89 if (!slang_variable_scope_copy (z
.locals
, y
->locals
))
91 slang_operation_destruct (&z
);
94 slang_operation_destruct (x
);