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.
25 #ifndef SLANG_COMPILE_OPERATION_H
26 #define SLANG_COMPILE_OPERATION_H
28 #if defined __cplusplus
34 * Types of slang operations.
35 * These are the types of the AST (abstract syntax tree) nodes.
36 * [foo] indicates a sub-tree or reference to another type of node
38 typedef enum slang_operation_type_
41 SLANG_OPER_BLOCK_NO_NEW_SCOPE
, /* "{" sequence "}" */
42 SLANG_OPER_BLOCK_NEW_SCOPE
, /* "{" sequence "}" */
43 SLANG_OPER_VARIABLE_DECL
, /* [type] [var] or [var] = [expr] */
45 SLANG_OPER_BREAK
, /* "break" statement */
46 SLANG_OPER_CONTINUE
, /* "continue" statement */
47 SLANG_OPER_DISCARD
, /* "discard" (kill fragment) statement */
48 SLANG_OPER_RETURN
, /* "return" [expr] */
49 SLANG_OPER_GOTO
, /* jump to label */
50 SLANG_OPER_LABEL
, /* a jump target */
51 SLANG_OPER_EXPRESSION
, /* [expr] */
52 SLANG_OPER_IF
, /* "if" [0] then [1] else [2] */
53 SLANG_OPER_WHILE
, /* "while" [cond] [body] */
54 SLANG_OPER_DO
, /* "do" [body] "while" [cond] */
55 SLANG_OPER_FOR
, /* "for" [init] [while] [incr] [body] */
56 SLANG_OPER_VOID
, /* nop */
57 SLANG_OPER_LITERAL_BOOL
, /* "true" or "false" */
58 SLANG_OPER_LITERAL_INT
, /* integer literal */
59 SLANG_OPER_LITERAL_FLOAT
, /* float literal */
60 SLANG_OPER_IDENTIFIER
, /* var name, func name, etc */
61 SLANG_OPER_SEQUENCE
, /* [expr] "," [expr] "," etc */
62 SLANG_OPER_ASSIGN
, /* [var] "=" [expr] */
63 SLANG_OPER_ADDASSIGN
, /* [var] "+=" [expr] */
64 SLANG_OPER_SUBASSIGN
, /* [var] "-=" [expr] */
65 SLANG_OPER_MULASSIGN
, /* [var] "*=" [expr] */
66 SLANG_OPER_DIVASSIGN
, /* [var] "/=" [expr] */
67 /*SLANG_OPER_MODASSIGN, */
68 /*SLANG_OPER_LSHASSIGN, */
69 /*SLANG_OPER_RSHASSIGN, */
70 /*SLANG_OPER_ORASSIGN, */
71 /*SLANG_OPER_XORASSIGN, */
72 /*SLANG_OPER_ANDASSIGN, */
73 SLANG_OPER_SELECT
, /* [expr] "?" [expr] ":" [expr] */
74 SLANG_OPER_LOGICALOR
, /* [expr] "||" [expr] */
75 SLANG_OPER_LOGICALXOR
, /* [expr] "^^" [expr] */
76 SLANG_OPER_LOGICALAND
, /* [expr] "&&" [expr] */
77 /*SLANG_OPER_BITOR, */
78 /*SLANG_OPER_BITXOR, */
79 /*SLANG_OPER_BITAND, */
80 SLANG_OPER_EQUAL
, /* [expr] "==" [expr] */
81 SLANG_OPER_NOTEQUAL
, /* [expr] "!=" [expr] */
82 SLANG_OPER_LESS
, /* [expr] "<" [expr] */
83 SLANG_OPER_GREATER
, /* [expr] ">" [expr] */
84 SLANG_OPER_LESSequal
, /* [expr] "<=" [expr] */
85 SLANG_OPER_GREATERequal
, /* [expr] ">=" [expr] */
86 /*SLANG_OPER_LSHIFT, */
87 /*SLANG_OPER_RSHIFT, */
88 SLANG_OPER_ADD
, /* [expr] "+" [expr] */
89 SLANG_OPER_SUBTRACT
, /* [expr] "-" [expr] */
90 SLANG_OPER_MULTIPLY
, /* [expr] "*" [expr] */
91 SLANG_OPER_DIVIDE
, /* [expr] "/" [expr] */
92 /*SLANG_OPER_MODULUS, */
93 SLANG_OPER_PREINCREMENT
, /* "++" [var] */
94 SLANG_OPER_PREDECREMENT
, /* "--" [var] */
95 SLANG_OPER_PLUS
, /* "-" [expr] */
96 SLANG_OPER_MINUS
, /* "+" [expr] */
97 /*SLANG_OPER_COMPLEMENT, */
98 SLANG_OPER_NOT
, /* "!" [expr] */
99 SLANG_OPER_SUBSCRIPT
, /* [expr] "[" [expr] "]" */
100 SLANG_OPER_CALL
, /* [func name] [param] [param] [...] */
101 SLANG_OPER_FIELD
, /* i.e.: ".next" or ".xzy" or ".xxx" etc */
102 SLANG_OPER_POSTINCREMENT
, /* [var] "++" */
103 SLANG_OPER_POSTDECREMENT
/* [var] "--" */
104 } slang_operation_type
;
108 * A slang_operation is basically a compiled instruction (such as assignment,
109 * a while-loop, a conditional, a multiply, a function call, etc).
110 * The AST (abstract syntax tree) is built from these nodes.
111 * NOTE: This structure could have been implemented as a union of simpler
112 * structs which would correspond to the operation types above.
114 typedef struct slang_operation_
116 slang_operation_type type
;
117 struct slang_operation_
*children
;
119 GLfloat literal
[4]; /**< Used for float, int and bool values */
120 GLuint literal_size
; /**< 1, 2, 3, or 4 */
121 slang_atom a_id
; /**< type: asm, identifier, call, field */
122 slang_variable_scope
*locals
; /**< local vars for scope */
123 struct slang_function_
*fun
; /**< If type == SLANG_OPER_CALL */
124 struct slang_variable_
*var
; /**< If type == slang_oper_identier */
129 slang_operation_construct(slang_operation
*);
132 slang_operation_destruct(slang_operation
*);
135 slang_operation_copy(slang_operation
*, const slang_operation
*);
137 extern slang_operation
*
138 slang_operation_new(GLuint count
);
141 slang_operation_delete(slang_operation
*oper
);
143 extern slang_operation
*
144 slang_operation_grow(GLuint
*numChildren
, slang_operation
**children
);
146 extern slang_operation
*
147 slang_operation_insert(GLuint
*numChildren
, slang_operation
**children
,
155 #endif /* SLANG_COMPILE_OPERATION_H */