fix comments
[mesa.git] / src / mesa / shader / slang / slang_compile_operation.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25 /**
26 * \file slang_compile_operation.c
27 * slang front-end compiler
28 * \author Michal Krol
29 */
30
31 #include "imports.h"
32 #include "slang_compile.h"
33
34 /* slang_operation */
35
36 int slang_operation_construct (slang_operation *oper)
37 {
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)
45 return 0;
46 _slang_variable_scope_ctr (oper->locals);
47 return 1;
48 }
49
50 void slang_operation_destruct (slang_operation *oper)
51 {
52 unsigned int i;
53
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);
59 }
60
61 int slang_operation_copy (slang_operation *x, const slang_operation *y)
62 {
63 slang_operation z;
64 unsigned int i;
65
66 if (!slang_operation_construct (&z))
67 return 0;
68 z.type = y->type;
69 z.children = (slang_operation *) slang_alloc_malloc (y->num_children * sizeof (slang_operation));
70 if (z.children == NULL)
71 {
72 slang_operation_destruct (&z);
73 return 0;
74 }
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]))
77 {
78 slang_operation_destruct (&z);
79 return 0;
80 }
81 for (i = 0; i < z.num_children; i++)
82 if (!slang_operation_copy (&z.children[i], &y->children[i]))
83 {
84 slang_operation_destruct (&z);
85 return 0;
86 }
87 z.literal = y->literal;
88 z.a_id = y->a_id;
89 if (!slang_variable_scope_copy (z.locals, y->locals))
90 {
91 slang_operation_destruct (&z);
92 return 0;
93 }
94 slang_operation_destruct (x);
95 *x = z;
96 return 1;
97 }
98