~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

Viewing changes to src/mesa/shader/slang/slang_compile_operation.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
ImportĀ upstreamĀ versionĀ 6.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Mesa 3-D graphics library
3
 
 * Version:  6.5
 
3
 * Version:  6.5.2
4
4
 *
5
5
 * Copyright (C) 2005-2006  Brian Paul   All Rights Reserved.
6
6
 *
31
31
#include "imports.h"
32
32
#include "slang_compile.h"
33
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
 
 
 
34
 
 
35
/**
 
36
 * Init a slang_operation object
 
37
 */
 
38
GLboolean
 
39
slang_operation_construct(slang_operation * oper)
 
40
{
 
41
   oper->type = slang_oper_none;
 
42
   oper->children = NULL;
 
43
   oper->num_children = 0;
 
44
   oper->literal = (float) 0;
 
45
   oper->a_id = SLANG_ATOM_NULL;
 
46
   oper->locals =
 
47
      (slang_variable_scope *)
 
48
      slang_alloc_malloc(sizeof(slang_variable_scope));
 
49
   if (oper->locals == NULL)
 
50
      return GL_FALSE;
 
51
   _slang_variable_scope_ctr(oper->locals);
 
52
   return GL_TRUE;
 
53
}
 
54
 
 
55
void
 
56
slang_operation_destruct(slang_operation * oper)
 
57
{
 
58
   GLuint i;
 
59
 
 
60
   for (i = 0; i < oper->num_children; i++)
 
61
      slang_operation_destruct(oper->children + i);
 
62
   slang_alloc_free(oper->children);
 
63
   slang_variable_scope_destruct(oper->locals);
 
64
   slang_alloc_free(oper->locals);
 
65
}
 
66
 
 
67
/**
 
68
 * Recursively copy a slang_operation node.
 
69
 * \return GL_TRUE for success, GL_FALSE if failure
 
70
 */
 
71
GLboolean
 
72
slang_operation_copy(slang_operation * x, const slang_operation * y)
 
73
{
 
74
   slang_operation z;
 
75
   GLuint i;
 
76
 
 
77
   if (!slang_operation_construct(&z))
 
78
      return GL_FALSE;
 
79
   z.type = y->type;
 
80
   z.children = (slang_operation *)
 
81
      slang_alloc_malloc(y->num_children * sizeof(slang_operation));
 
82
   if (z.children == NULL) {
 
83
      slang_operation_destruct(&z);
 
84
      return GL_FALSE;
 
85
   }
 
86
   for (z.num_children = 0; z.num_children < y->num_children;
 
87
        z.num_children++) {
 
88
      if (!slang_operation_construct(&z.children[z.num_children])) {
 
89
         slang_operation_destruct(&z);
 
90
         return GL_FALSE;
 
91
      }
 
92
   }
 
93
   for (i = 0; i < z.num_children; i++) {
 
94
      if (!slang_operation_copy(&z.children[i], &y->children[i])) {
 
95
         slang_operation_destruct(&z);
 
96
         return GL_FALSE;
 
97
      }
 
98
   }
 
99
   z.literal = y->literal;
 
100
   z.a_id = y->a_id;
 
101
   if (!slang_variable_scope_copy(z.locals, y->locals)) {
 
102
      slang_operation_destruct(&z);
 
103
      return GL_FALSE;
 
104
   }
 
105
   slang_operation_destruct(x);
 
106
   *x = z;
 
107
   return GL_TRUE;
 
108
}
 
109
 
 
110
 
 
111
slang_operation *
 
112
slang_operation_new(GLuint count)
 
113
{
 
114
   return (slang_operation *) _mesa_calloc(count * sizeof(slang_operation));
 
115
}