mojoshader_compiler.c
author Ryan C. Gordon <icculus@icculus.org>
Sat, 20 Feb 2010 00:27:28 -0500
changeset 837 5f6528602658
parent 836 d975fa785f1e
child 838 37e901d1b7bf
permissions -rw-r--r--
Uncommented some grammar bits that got masked out in the calculator experiment.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
835
743e14b386f3 Added boilerplate comment to start of file.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
     1
/**
743e14b386f3 Added boilerplate comment to start of file.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
     2
 * MojoShader; generate shader programs from bytecode of compiled
743e14b386f3 Added boilerplate comment to start of file.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
     3
 *  Direct3D shaders.
743e14b386f3 Added boilerplate comment to start of file.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
     4
 *
743e14b386f3 Added boilerplate comment to start of file.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
     5
 * Please see the file LICENSE.txt in the source's root directory.
743e14b386f3 Added boilerplate comment to start of file.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
     6
 *
743e14b386f3 Added boilerplate comment to start of file.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
     7
 *  This file written by Ryan C. Gordon.
743e14b386f3 Added boilerplate comment to start of file.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
     8
 */
743e14b386f3 Added boilerplate comment to start of file.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
     9
709
6fbd0e20b40f Removed some ANSI C things from the HLSL grammar that shaders don't do.
Ryan C. Gordon <icculus@icculus.org>
parents: 706
diff changeset
    10
#define __MOJOSHADER_INTERNAL__ 1
6fbd0e20b40f Removed some ANSI C things from the HLSL grammar that shaders don't do.
Ryan C. Gordon <icculus@icculus.org>
parents: 706
diff changeset
    11
#include "mojoshader_internal.h"
706
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
716
94a804b54078 Cleaned up HLSL parser tracing.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
    13
#if DEBUG_COMPILER_PARSER
94a804b54078 Cleaned up HLSL parser tracing.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
    14
#define LEMON_SUPPORT_TRACING 1
94a804b54078 Cleaned up HLSL parser tracing.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
    15
#endif
94a804b54078 Cleaned up HLSL parser tracing.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
    16
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    17
typedef union TokenData
778
a43d07e5da68 Added some structure for user types (struct at the moment).
Ryan C. Gordon <icculus@icculus.org>
parents: 731
diff changeset
    18
{
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    19
    int64 i64;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    20
    double dbl;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    21
    const char *string;
778
a43d07e5da68 Added some structure for user types (struct at the moment).
Ryan C. Gordon <icculus@icculus.org>
parents: 731
diff changeset
    22
} TokenData;
a43d07e5da68 Added some structure for user types (struct at the moment).
Ryan C. Gordon <icculus@icculus.org>
parents: 731
diff changeset
    23
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    24
typedef struct StringBucket
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    25
{
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    26
    char *string;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    27
    struct StringBucket *next;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    28
} StringBucket;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    29
778
a43d07e5da68 Added some structure for user types (struct at the moment).
Ryan C. Gordon <icculus@icculus.org>
parents: 731
diff changeset
    30
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
    31
// Structures that make up the parse tree...
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    32
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    33
typedef enum Operator
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    34
{
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    35
    OP_START_RANGE_UNARY,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    36
    OP_POSTINCREMENT,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    37
    OP_POSTDECREMENT,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    38
    OP_PREINCREMENT,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    39
    OP_PREDECREMENT,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    40
    OP_NEGATE,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    41
    OP_COMPLEMENT,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    42
    OP_NOT,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    43
    OP_END_RANGE_UNARY,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    44
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    45
    OP_START_RANGE_BINARY,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    46
    OP_DEREF_ARRAY,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    47
    OP_CALLFUNC,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    48
    OP_DEREF_STRUCT,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    49
    OP_COMMA,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    50
    OP_MULTIPLY,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    51
    OP_DIVIDE,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    52
    OP_MODULO,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    53
    OP_ADD,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    54
    OP_SUBTRACT,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    55
    OP_LSHIFT,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    56
    OP_RSHIFT,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    57
    OP_LESSTHAN,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    58
    OP_GREATERTHAN,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    59
    OP_LESSTHANOREQUAL,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    60
    OP_GREATERTHANOREQUAL,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    61
    OP_EQUAL,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    62
    OP_NOTEQUAL,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    63
    OP_BINARYAND,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    64
    OP_BINARYXOR,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    65
    OP_BINARYOR,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    66
    OP_LOGICALAND,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    67
    OP_LOGICALOR,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    68
    OP_ASSIGN,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    69
    OP_MULASSIGN,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    70
    OP_DIVASSIGN,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    71
    OP_MODASSIGN,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    72
    OP_ADDASSIGN,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    73
    OP_SUBASSIGN,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    74
    OP_LSHIFTASSIGN,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    75
    OP_RSHIFTASSIGN,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    76
    OP_ANDASSIGN,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    77
    OP_XORASSIGN,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    78
    OP_ORASSIGN,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    79
    OP_END_RANGE_BINARY,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    80
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    81
    OP_START_RANGE_TERNARY,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    82
    OP_CONDITIONAL,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    83
    OP_END_RANGE_TERNARY,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    84
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    85
    OP_START_RANGE_DATA,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    86
    OP_IDENTIFIER,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    87
    OP_INT_LITERAL,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    88
    OP_FLOAT_LITERAL,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    89
    OP_STRING_LITERAL,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    90
    OP_END_RANGE_DATA,
837
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
    91
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
    92
    OP_CONSTRUCTOR,
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
    93
    OP_CAST
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    94
} Operator;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    95
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
    96
typedef enum VariableAttributes
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
    97
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
    98
    VARATTR_EXTERN = (1 << 0),
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
    99
    VARATTR_NOINTERPOLATION = (1 << 1),
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   100
    VARATTR_SHARED = (1 << 2),
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   101
    VARATTR_STATIC = (1 << 3),
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   102
    VARATTR_UNIFORM = (1 << 4),
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   103
    VARATTR_VOLATILE = (1 << 5),
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   104
    VARATTR_CONST = (1 << 6),
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   105
    VARATTR_ROWMAJOR = (1 << 7),
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   106
    VARATTR_COLUMNMAJOR = (1 << 8)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   107
} VariableAttributes;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   108
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   109
typedef enum IfAttributes
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   110
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   111
    IFATTR_NONE,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   112
    IFATTR_BRANCH,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   113
    IFATTR_FLATTEN,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   114
    IFATTR_IFALL,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   115
    IFATTR_IFANY,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   116
    IFATTR_PREDICATE,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   117
    IFATTR_PREDICATEBLOCK,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   118
} IfAttributes;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   119
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   120
typedef enum SwitchAttributes
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   121
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   122
    SWITCHATTR_NONE,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   123
    SWITCHATTR_FLATTEN,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   124
    SWITCHATTR_BRANCH,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   125
    SWITCHATTR_FORCECASE,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   126
    SWITCHATTR_CALL
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   127
} SwitchAttributes;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   128
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   129
static inline int operator_is_unary(const Operator op)
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   130
{
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   131
    return ((op > OP_START_RANGE_UNARY) && (op < OP_END_RANGE_UNARY));
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   132
} // operator_is_unary
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   133
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   134
static inline int operator_is_binary(const Operator op)
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   135
{
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   136
    return ((op > OP_START_RANGE_BINARY) && (op < OP_END_RANGE_BINARY));
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   137
} // operator_is_binary
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   138
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   139
static inline int operator_is_ternary(const Operator op)
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   140
{
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   141
    return ((op > OP_START_RANGE_TERNARY) && (op < OP_END_RANGE_TERNARY));
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   142
} // operator_is_ternary
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   143
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   144
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   145
typedef struct Expression
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   146
{
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   147
    Operator op;  // operator
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   148
} Expression;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   149
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   150
typedef struct ExpressionUnary
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   151
{
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   152
    Operator op;  // operator
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   153
    Expression *operand;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   154
} ExpressionUnary;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   155
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   156
typedef struct ExpressionBinary
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   157
{
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   158
    Operator op;  // operator
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   159
    Expression *left;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   160
    Expression *right;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   161
} ExpressionBinary;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   162
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   163
typedef struct ExpressionTernary
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   164
{
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   165
    Operator op;  // operator
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   166
    Expression *left;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   167
    Expression *center;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   168
    Expression *right;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   169
} ExpressionTernary;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   170
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   171
typedef struct ExpressionIdentifier
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   172
{
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   173
    Operator op;  // Always OP_IDENTIFIER
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   174
    const char *identifier;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   175
} ExpressionIdentifier;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   176
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   177
typedef struct ExpressionIntLiteral
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   178
{
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   179
    Operator op;  // Always OP_INT_LITERAL
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   180
    int64 value;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   181
} ExpressionIntLiteral;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   182
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   183
typedef struct ExpressionFloatLiteral
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   184
{
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   185
    Operator op;  // Always OP_FLOAT_LITERAL
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   186
    double value;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   187
} ExpressionFloatLiteral;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   188
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   189
typedef struct ExpressionStringLiteral
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   190
{
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   191
    Operator op;  // Always OP_STRING_LITERAL
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   192
    const char *string;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   193
} ExpressionStringLiteral;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   194
837
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   195
typedef struct ExpressionConstructor
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   196
{
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   197
    Operator op;  // Always OP_CONSTRUCTOR
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   198
    const char *datatype;
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   199
    Expression *args;
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   200
} ExpressionConstructor;
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   201
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   202
typedef struct ExpressionCast
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   203
{
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   204
    Operator op;  // Always OP_CAST
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   205
    const char *datatype;
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   206
    Expression *operand;
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   207
} ExpressionCast;
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   208
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   209
typedef enum CompilationUnitType
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   210
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   211
    COMPUNITTYPE_FUNCTION,  // function declaration or definition
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   212
    COMPUNITTYPE_TYPEDEF,   // typedef or struct
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   213
    COMPUNITTYPE_STRUCT,    // global struct
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   214
    COMPUNITTYPE_VARIABLE   // global variable
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   215
} CompilationUnitType;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   216
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   217
typedef struct CompilationUnit
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   218
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   219
    CompilationUnitType type;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   220
    struct CompilationUnit *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   221
} CompilationUnit;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   222
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   223
typedef enum FunctionStorageClass
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   224
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   225
    FNSTORECLS_NONE,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   226
    FNSTORECLS_INLINE
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   227
} FunctionStorageClass;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   228
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   229
typedef enum InputModifier
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   230
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   231
    INPUTMOD_NONE,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   232
    INPUTMOD_IN,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   233
    INPUTMOD_OUT,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   234
    INPUTMOD_INOUT,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   235
    INPUTMOD_UNIFORM
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   236
} InputModifier;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   237
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   238
typedef enum InterpolationModifier
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   239
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   240
    INTERPMOD_NONE,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   241
    INTERPMOD_LINEAR,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   242
    INTERPMOD_CENTROID,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   243
    INTERPMOD_NOINTERPOLATION,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   244
    INTERPMOD_NOPERSPECTIVE,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   245
    INTERPMOD_SAMPLE
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   246
} InterpolationModifier;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   247
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   248
typedef struct FunctionArguments
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   249
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   250
    InputModifier input_modifier;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   251
    const char *datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   252
    const char *identifier;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   253
    const char *semantic;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   254
    InterpolationModifier interpolation_modifier;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   255
    Expression *initializer;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   256
    struct FunctionArguments *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   257
} FunctionArguments;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   258
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   259
typedef struct FunctionSignature
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   260
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   261
    const char *datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   262
    const char *identifier;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   263
    FunctionArguments *args;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   264
    FunctionStorageClass storage_class;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   265
    const char *semantic;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   266
} FunctionSignature;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   267
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   268
typedef struct ScalarOrArray
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   269
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   270
    const char *identifier;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   271
    int isarray;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   272
    Expression *dimension;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   273
} ScalarOrArray;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   274
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   275
typedef struct Annotations
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   276
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   277
    const char *datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   278
    Expression *initializer;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   279
    struct Annotations *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   280
} Annotations;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   281
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   282
typedef struct PackOffset
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   283
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   284
    const char *ident1;   // !!! FIXME: rename this.
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   285
    const char *ident2;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   286
} PackOffset;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   287
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   288
typedef struct VariableLowLevel
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   289
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   290
    PackOffset *packoffset;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   291
    const char *register_name;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   292
} VariableLowLevel;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   293
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   294
typedef struct StructMembers
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   295
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   296
    const char *datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   297
    const char *semantic;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   298
    ScalarOrArray *details;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   299
    InterpolationModifier interpolation_mod;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   300
    struct StructMembers *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   301
} StructMembers;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   302
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   303
typedef struct StructDeclaration
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   304
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   305
    const char *name;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   306
    StructMembers *members;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   307
} StructDeclaration;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   308
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   309
typedef struct VariableDeclaration
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   310
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   311
    int attributes;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   312
    const char *datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   313
    StructDeclaration *anonymous_datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   314
    ScalarOrArray *details;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   315
    const char *semantic;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   316
    Annotations *annotations;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   317
    Expression *initializer;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   318
    VariableLowLevel *lowlevel;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   319
    struct VariableDeclaration *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   320
} VariableDeclaration;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   321
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   322
typedef enum StatementType
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   323
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   324
    STATEMENTTYPE_EMPTY,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   325
    STATEMENTTYPE_EXPRESSION,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   326
    STATEMENTTYPE_IF,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   327
    STATEMENTTYPE_SWITCH,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   328
    STATEMENTTYPE_FOR,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   329
    STATEMENTTYPE_DO,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   330
    STATEMENTTYPE_WHILE,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   331
    STATEMENTTYPE_RETURN,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   332
    STATEMENTTYPE_BREAK,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   333
    STATEMENTTYPE_CONTINUE,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   334
    STATEMENTTYPE_DISCARD,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   335
    STATEMENTTYPE_TYPEDEF,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   336
    STATEMENTTYPE_STRUCT,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   337
    STATEMENTTYPE_VARDECL,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   338
} StatementType;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   339
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   340
typedef struct Statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   341
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   342
    StatementType type;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   343
    struct Statement *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   344
} Statement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   345
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   346
typedef Statement EmptyStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   347
typedef Statement BreakStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   348
typedef Statement ContinueStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   349
typedef Statement DiscardStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   350
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   351
typedef struct ReturnStatement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   352
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   353
    StatementType type;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   354
    struct Statement *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   355
    Expression *expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   356
} ReturnStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   357
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   358
typedef struct ExpressionStatement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   359
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   360
    StatementType type;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   361
    struct Statement *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   362
    Expression *expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   363
} ExpressionStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   364
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   365
typedef struct IfStatement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   366
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   367
    StatementType type;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   368
    struct Statement *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   369
    int attributes;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   370
    Expression *expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   371
    Statement *statement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   372
    Statement *else_statement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   373
} IfStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   374
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   375
typedef struct SwitchCases
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   376
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   377
    Expression *expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   378
    Statement *statement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   379
    struct SwitchCases *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   380
} SwitchCases;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   381
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   382
typedef struct SwitchStatement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   383
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   384
    StatementType type;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   385
    struct Statement *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   386
    int attributes;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   387
    Expression *expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   388
    SwitchCases *cases;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   389
} SwitchStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   390
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   391
typedef struct WhileStatement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   392
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   393
    StatementType type;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   394
    struct Statement *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   395
    int64 unroll;  // # times to unroll, 0 to loop, -1 for compiler's choice.
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   396
    Expression *expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   397
    Statement *statement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   398
} WhileStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   399
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   400
typedef WhileStatement DoStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   401
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   402
typedef struct ForStatement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   403
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   404
    StatementType type;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   405
    struct Statement *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   406
    int64 unroll;  // # times to unroll, 0 to loop, -1 for compiler's choice.
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   407
    VariableDeclaration *var_decl;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   408
    Expression *initializer;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   409
    Expression *looptest;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   410
    Expression *counter;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   411
    Statement *statement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   412
} ForStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   413
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   414
typedef struct Typedef
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   415
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   416
    int isconst;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   417
    const char *datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   418
    ScalarOrArray *details;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   419
} Typedef;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   420
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   421
typedef struct TypedefStatement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   422
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   423
    StatementType type;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   424
    struct Statement *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   425
    Typedef *type_info;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   426
} TypedefStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   427
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   428
typedef struct VarDeclStatement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   429
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   430
    StatementType type;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   431
    struct Statement *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   432
    VariableDeclaration *decl;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   433
} VarDeclStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   434
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   435
typedef struct StructStatement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   436
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   437
    StatementType type;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   438
    struct Statement *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   439
    StructDeclaration *struct_info;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   440
} StructStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   441
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   442
typedef struct CompilationUnitFunction
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   443
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   444
    CompilationUnitType type;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   445
    struct CompilationUnit *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   446
    FunctionSignature *declaration;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   447
    Statement *definition;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   448
} CompilationUnitFunction;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   449
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   450
typedef struct CompilationUnitTypedef
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   451
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   452
    CompilationUnitType type;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   453
    struct CompilationUnit *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   454
    Typedef *type_info;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   455
} CompilationUnitTypedef;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   456
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   457
typedef struct CompilationUnitStruct
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   458
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   459
    CompilationUnitType type;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   460
    struct CompilationUnit *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   461
    StructDeclaration *struct_info;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   462
} CompilationUnitStruct;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   463
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   464
typedef struct CompilationUnitVariable
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   465
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   466
    CompilationUnitType type;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   467
    struct CompilationUnit *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   468
    VariableDeclaration *declaration;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   469
} CompilationUnitVariable;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   470
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   471
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   472
// Compile state, passed around all over the place.
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   473
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   474
typedef struct Context
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   475
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   476
    int isfail;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   477
    int out_of_memory;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   478
    MOJOSHADER_malloc malloc;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   479
    MOJOSHADER_free free;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   480
    void *malloc_data;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   481
    int error_count;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   482
    ErrorList *errors;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   483
    Preprocessor *preprocessor;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   484
    StringBucket *string_hashtable[256];
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   485
    const char *usertypes[512];  // !!! FIXME: dynamic allocation
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   486
    int usertype_count;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   487
    CompilationUnit *ast;  // Abstract Syntax Tree
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   488
} Context;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   489
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   490
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   491
// Convenience functions for allocators...
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   492
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   493
static inline void out_of_memory(Context *ctx)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   494
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   495
    ctx->isfail = ctx->out_of_memory = 1;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   496
} // out_of_memory
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   497
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   498
static inline void *Malloc(Context *ctx, const size_t len)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   499
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   500
    void *retval = ctx->malloc((int) len, ctx->malloc_data);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   501
    if (retval == NULL)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   502
        out_of_memory(ctx);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   503
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   504
} // Malloc
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   505
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   506
static inline char *StrDup(Context *ctx, const char *str)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   507
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   508
    char *retval = (char *) Malloc(ctx, strlen(str) + 1);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   509
    if (retval != NULL)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   510
        strcpy(retval, str);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   511
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   512
} // StrDup
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   513
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   514
static inline void Free(Context *ctx, void *ptr)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   515
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   516
    if (ptr != NULL)  // check for NULL in case of dumb free() impl.
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   517
        ctx->free(ptr, ctx->malloc_data);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   518
} // Free
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   519
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   520
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   521
// These functions are mostly for construction and cleanup of nodes in the
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   522
//  parse tree. Mostly this is simple allocation and initialization, so we
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   523
//  can do as little in the lemon code as possible, and then sort it all out
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   524
//  afterwards.
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   525
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   526
#define NEW_AST_NODE(cls) \
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   527
    cls *retval = Malloc(ctx, sizeof (cls)); \
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   528
    if (retval == NULL) { return NULL; } \
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   529
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   530
#define DELETE_AST_NODE(cls) do {\
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   531
    if (!cls) return; \
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   532
} while (0)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   533
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   534
static void delete_compilation_unit(Context *ctx, CompilationUnit *unit);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   535
static void delete_statement(Context *ctx, Statement *stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   536
837
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   537
static Expression *new_constructor_expr(Context *ctx, const char *datatype,
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   538
                                        Expression *args)
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   539
{
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   540
    NEW_AST_NODE(ExpressionConstructor);
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   541
    retval->op = OP_CONSTRUCTOR;
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   542
    retval->datatype = datatype;
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   543
    retval->args = args;
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   544
    return (Expression *) retval;
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   545
} // new_constructor_expr
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   546
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   547
static Expression *new_cast_expr(Context *ctx, const char *datatype,
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   548
                                 Expression *operand)
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   549
{
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   550
    NEW_AST_NODE(ExpressionCast);
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   551
    retval->op = OP_CAST;
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   552
    retval->datatype = datatype;
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   553
    retval->operand = operand;
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   554
    return (Expression *) retval;
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   555
} // new_cast_expr
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   556
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   557
static Expression *new_unary_expr(Context *ctx, const Operator op,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   558
                                  Expression *operand)
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   559
{
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   560
    NEW_AST_NODE(ExpressionUnary);
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   561
    assert(operator_is_unary(op));
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   562
    retval->op = op;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   563
    retval->operand = operand;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   564
    return (Expression *) retval;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   565
} // new_unary_expr
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   566
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   567
static Expression *new_binary_expr(Context *ctx, const Operator op,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   568
                                   Expression *left, Expression *right)
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   569
{
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   570
    NEW_AST_NODE(ExpressionBinary);
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   571
    assert(operator_is_binary(op));
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   572
    retval->op = op;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   573
    retval->left = left;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   574
    retval->right = right;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   575
    return (Expression *) retval;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   576
} // new_binary_expr
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   577
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   578
static Expression *new_ternary_expr(Context *ctx, const Operator op,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   579
                                    Expression *left, Expression *center,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   580
                                    Expression *right)
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   581
{
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   582
    NEW_AST_NODE(ExpressionTernary);
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   583
    assert(operator_is_ternary(op));
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   584
    retval->op = op;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   585
    retval->left = left;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   586
    retval->center = center;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   587
    retval->right = right;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   588
    return (Expression *) retval;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   589
} // new_ternary_expr
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   590
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   591
static Expression *new_identifier_expr(Context *ctx, const char *string)
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   592
{
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   593
    NEW_AST_NODE(ExpressionIdentifier);
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   594
    retval->op = OP_IDENTIFIER;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   595
    retval->identifier = string;  // cached; don't copy string.
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   596
    return (Expression *) retval;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   597
} // new_identifier_expr
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   598
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   599
static Expression *new_literal_int_expr(Context *ctx, const int64 value)
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   600
{
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   601
    NEW_AST_NODE(ExpressionIntLiteral);
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   602
    retval->op = OP_INT_LITERAL;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   603
    retval->value = value;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   604
    return (Expression *) retval;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   605
} // new_literal_int_expr
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   606
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   607
static Expression *new_literal_float_expr(Context *ctx, const double dbl)
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   608
{
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   609
    NEW_AST_NODE(ExpressionFloatLiteral);
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   610
    retval->op = OP_FLOAT_LITERAL;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   611
    retval->value = dbl;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   612
    return (Expression *) retval;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   613
} // new_literal_float_expr
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   614
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   615
static Expression *new_literal_string_expr(Context *ctx, const char *string)
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   616
{
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   617
    NEW_AST_NODE(ExpressionStringLiteral);
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   618
    retval->op = OP_STRING_LITERAL;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   619
    retval->string = string;  // cached; don't copy string.
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   620
    return (Expression *) retval;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   621
} // new_string_literal_expr
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   622
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   623
static void delete_expr(Context *ctx, Expression *expr)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   624
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   625
    DELETE_AST_NODE(expr);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   626
    if (operator_is_unary(expr->op))
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   627
    {
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   628
        const ExpressionUnary *unary = (const ExpressionUnary *) expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   629
        delete_expr(ctx, unary->operand);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   630
    } // if
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   631
    else if (operator_is_binary(expr->op))
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   632
    {
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   633
        const ExpressionBinary *binary = (const ExpressionBinary *) expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   634
        delete_expr(ctx, binary->left);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   635
        delete_expr(ctx, binary->right);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   636
    } // else if
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   637
    else if (operator_is_ternary(expr->op))
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   638
    {
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   639
        const ExpressionTernary *ternary = (const ExpressionTernary *) expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   640
        delete_expr(ctx, ternary->left);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   641
        delete_expr(ctx, ternary->center);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   642
        delete_expr(ctx, ternary->right);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   643
    } // else if
837
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   644
    else if (expr->op == OP_CAST)
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   645
    {
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   646
        delete_expr(ctx, ((ExpressionCast *) expr)->operand);
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   647
    } // else if
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   648
    else if (expr->op == OP_CONSTRUCTOR)
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   649
    {
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   650
        delete_expr(ctx, ((ExpressionConstructor *) expr)->args);
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   651
    } // else if
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   652
    Free(ctx, expr);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   653
} // delete_expr
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   654
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   655
static FunctionArguments *new_function_arg(Context *ctx,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   656
                                        const InputModifier inputmod,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   657
                                        const char *datatype,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   658
                                        const char *identifier,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   659
                                        const char *semantic,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   660
                                        const InterpolationModifier interpmod,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   661
                                        Expression *initializer)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   662
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   663
    NEW_AST_NODE(FunctionArguments);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   664
    retval->input_modifier = inputmod;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   665
    retval->datatype = datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   666
    retval->identifier = identifier;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   667
    retval->semantic = semantic;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   668
    retval->interpolation_modifier = interpmod;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   669
    retval->initializer = initializer;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   670
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   671
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   672
} // new_function_arg
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   673
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   674
static void delete_function_args(Context *ctx, FunctionArguments *args)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   675
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   676
    DELETE_AST_NODE(args);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   677
    delete_function_args(ctx, args->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   678
    delete_expr(ctx, args->initializer);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   679
    Free(ctx, args);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   680
} // delete_function_args
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   681
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   682
static FunctionSignature *new_function_signature(Context *ctx,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   683
                                                 const char *datatype,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   684
                                                 const char *identifier,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   685
                                                 FunctionArguments *args)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   686
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   687
    NEW_AST_NODE(FunctionSignature);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   688
    retval->datatype = datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   689
    retval->identifier = identifier;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   690
    retval->args = args;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   691
    retval->storage_class = FNSTORECLS_NONE;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   692
    retval->semantic = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   693
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   694
} // new_function_signature
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   695
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   696
static void delete_function_signature(Context *ctx, FunctionSignature *sig)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   697
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   698
    DELETE_AST_NODE(sig);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   699
    delete_function_args(ctx, sig->args);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   700
    Free(ctx, sig);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   701
} // delete_function_signature
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   702
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   703
static CompilationUnit *new_function(Context *ctx,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   704
                                     FunctionSignature *declaration,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   705
                                     Statement *definition)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   706
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   707
    NEW_AST_NODE(CompilationUnitFunction);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   708
    retval->type = COMPUNITTYPE_FUNCTION;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   709
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   710
    retval->declaration = declaration;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   711
    retval->definition = definition;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   712
    return (CompilationUnit *) retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   713
} // new_function
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   714
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   715
static void delete_function(Context *ctx, CompilationUnitFunction *unitfn)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   716
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   717
    DELETE_AST_NODE(unitfn);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   718
    delete_compilation_unit(ctx, unitfn->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   719
    delete_function_signature(ctx, unitfn->declaration);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   720
    delete_statement(ctx, unitfn->definition);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   721
    Free(ctx, unitfn);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   722
} // delete_function
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   723
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   724
static ScalarOrArray *new_scalar_or_array(Context *ctx, const char *ident,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   725
                                          const int isvec, Expression *dim)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   726
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   727
    NEW_AST_NODE(ScalarOrArray);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   728
    retval->identifier = ident;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   729
    retval->isarray = isvec;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   730
    retval->dimension = dim;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   731
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   732
} // new_scalar_or_array
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   733
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   734
static void delete_scalar_or_array(Context *ctx, ScalarOrArray *soa)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   735
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   736
    DELETE_AST_NODE(soa);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   737
    delete_expr(ctx, soa->dimension);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   738
    Free(ctx, soa);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   739
} // delete_scalar_or_array
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   740
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   741
static Typedef *new_typedef(Context *ctx, int isconst, const char *datatype,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   742
                            ScalarOrArray *soa)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   743
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   744
    NEW_AST_NODE(Typedef);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   745
    retval->isconst = isconst;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   746
    retval->datatype = datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   747
    retval->details = soa;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   748
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   749
} // new_typedef
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   750
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   751
static void delete_typedef(Context *ctx, Typedef *td)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   752
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   753
    DELETE_AST_NODE(td);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   754
    delete_scalar_or_array(ctx, td->details);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   755
    Free(ctx, td);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   756
} // delete_typedef
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   757
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   758
static PackOffset *new_pack_offset(Context *ctx, const char *a, const char *b)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   759
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   760
    NEW_AST_NODE(PackOffset);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   761
    retval->ident1 = a;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   762
    retval->ident2 = b;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   763
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   764
} // new_pack_offset
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   765
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   766
static void delete_pack_offset(Context *ctx, PackOffset *o)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   767
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   768
    DELETE_AST_NODE(o);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   769
    Free(ctx, o);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   770
} // delete_pack_offset
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   771
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   772
static VariableLowLevel *new_variable_lowlevel(Context *ctx, PackOffset *po,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   773
                                               const char *reg)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   774
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   775
    NEW_AST_NODE(VariableLowLevel);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   776
    retval->packoffset = po;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   777
    retval->register_name = reg;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   778
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   779
} // new_variable_lowlevel
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   780
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   781
static void delete_variable_lowlevel(Context *ctx, VariableLowLevel *vll)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   782
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   783
    DELETE_AST_NODE(vll);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   784
    delete_pack_offset(ctx, vll->packoffset);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   785
    Free(ctx, vll);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   786
} // delete_variable_lowlevel
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   787
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   788
static Annotations *new_annotation(Context *ctx, const char *datatype,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   789
                                   Expression *initializer)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   790
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   791
    NEW_AST_NODE(Annotations);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   792
    retval->datatype = datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   793
    retval->initializer = initializer;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   794
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   795
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   796
} // new_annotation
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   797
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   798
static void delete_annotation(Context *ctx, Annotations *annotations)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   799
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   800
    DELETE_AST_NODE(annotations);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   801
    delete_annotation(ctx, annotations->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   802
    delete_expr(ctx, annotations->initializer);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   803
    Free(ctx, annotations);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   804
} // delete_annotation
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   805
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   806
static VariableDeclaration *new_variable_declaration(Context *ctx,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   807
                                    ScalarOrArray *soa, const char *semantic,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   808
                                    Annotations *annotations, Expression *init,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   809
                                    VariableLowLevel *vll)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   810
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   811
    NEW_AST_NODE(VariableDeclaration)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   812
    retval->attributes = 0;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   813
    retval->datatype = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   814
    retval->anonymous_datatype = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   815
    retval->details = soa;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   816
    retval->semantic = semantic;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   817
    retval->annotations = annotations;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   818
    retval->initializer = init;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   819
    retval->lowlevel = vll;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   820
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   821
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   822
} // new_variable_declaration
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   823
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   824
static void delete_variable_declaration(Context *ctx, VariableDeclaration *dcl)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   825
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   826
    DELETE_AST_NODE(dcl);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   827
    delete_variable_declaration(ctx, dcl->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   828
    delete_scalar_or_array(ctx, dcl->details);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   829
    delete_annotation(ctx, dcl->annotations);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   830
    delete_expr(ctx, dcl->initializer);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   831
    delete_variable_lowlevel(ctx, dcl->lowlevel);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   832
    Free(ctx, dcl);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   833
} // delete_variable_declaration
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   834
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   835
static CompilationUnit *new_global_variable(Context *ctx,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   836
                                            VariableDeclaration *decl)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   837
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   838
    NEW_AST_NODE(CompilationUnitVariable);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   839
    retval->type = COMPUNITTYPE_FUNCTION;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   840
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   841
    retval->declaration = decl;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   842
    return (CompilationUnit *) retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   843
} // new_global_variable
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   844
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   845
static void delete_global_variable(Context *ctx, CompilationUnitVariable *var)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   846
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   847
    DELETE_AST_NODE(var);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   848
    delete_compilation_unit(ctx, var->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   849
    delete_variable_declaration(ctx, var->declaration);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   850
    Free(ctx, var);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   851
} // delete_global_variable
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   852
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   853
static CompilationUnit *new_global_typedef(Context *ctx, Typedef *td)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   854
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   855
    NEW_AST_NODE(CompilationUnitTypedef)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   856
    retval->type = COMPUNITTYPE_TYPEDEF;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   857
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   858
    retval->type_info = td;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   859
    return (CompilationUnit *) retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   860
} // new_global_typedef
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   861
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   862
static void delete_global_typedef(Context *ctx, CompilationUnitTypedef *unit)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   863
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   864
    DELETE_AST_NODE(unit);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   865
    delete_compilation_unit(ctx, unit->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   866
    delete_typedef(ctx, unit->type_info);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   867
    Free(ctx, unit);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   868
} // delete_global_typedef
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   869
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   870
static StructMembers *new_struct_member(Context *ctx, ScalarOrArray *soa,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   871
                                        const char *semantic)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   872
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   873
    NEW_AST_NODE(StructMembers);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   874
    retval->datatype = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   875
    retval->semantic = semantic;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   876
    retval->details = soa;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   877
    retval->interpolation_mod = INTERPMOD_NONE;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   878
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   879
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   880
} // new_struct_member
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   881
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   882
static void delete_struct_member(Context *ctx, StructMembers *member)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   883
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   884
    DELETE_AST_NODE(member);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   885
    delete_struct_member(ctx, member->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   886
    delete_scalar_or_array(ctx, member->details);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   887
    Free(ctx, member);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   888
} // delete_struct_member
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   889
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   890
static StructDeclaration *new_struct_declaration(Context *ctx,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   891
                                    const char *name, StructMembers *members)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   892
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   893
    NEW_AST_NODE(StructDeclaration);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   894
    retval->name = name;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   895
    retval->members = members;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   896
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   897
} // new_struct_declaration
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   898
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   899
static void delete_struct_declaration(Context *ctx, StructDeclaration *decl)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   900
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   901
    DELETE_AST_NODE(decl);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   902
    delete_struct_member(ctx, decl->members);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   903
    Free(ctx, decl);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   904
} // delete_struct_declaration
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   905
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   906
static CompilationUnit *new_global_struct(Context *ctx, StructDeclaration *sd)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   907
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   908
    NEW_AST_NODE(CompilationUnitStruct)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   909
    retval->type = COMPUNITTYPE_STRUCT;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   910
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   911
    retval->struct_info = sd;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   912
    return (CompilationUnit *) retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   913
} // new_global_struct
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   914
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   915
static void delete_global_struct(Context *ctx, CompilationUnitStruct *unit)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   916
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   917
    DELETE_AST_NODE(unit);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   918
    delete_compilation_unit(ctx, unit->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   919
    delete_struct_declaration(ctx, unit->struct_info);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   920
    Free(ctx, unit);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   921
} // delete_global_struct
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   922
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   923
static void delete_compilation_unit(Context *ctx, CompilationUnit *unit)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   924
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   925
    if (!unit) return;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   926
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   927
    // it's important to not recurse too deeply here, since you may have
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   928
    //  thousands of items in this linked list (each line of a massive
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   929
    //  function, for example). To avoid this, we iterate the list here,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   930
    //  deleting all children and making them think they have no reason
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   931
    //  to recurse in their own delete methods.
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   932
    // Please note that everyone should _try_ to delete their "next" member,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   933
    //  just in case, but hopefully this cleaned it out.
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   934
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   935
    CompilationUnit *i = unit->next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   936
    unit->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   937
    while (i)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   938
    {
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   939
        CompilationUnit *next = i->next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   940
        i->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   941
        delete_compilation_unit(ctx, i);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   942
        i = next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   943
    } // while
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   944
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   945
    switch (unit->type)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   946
    {
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   947
        #define DELETE_UNIT(typ, cls, fn) \
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   948
            case COMPUNITTYPE_##typ: delete_##fn(ctx, (cls *) unit); break;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   949
        DELETE_UNIT(FUNCTION, CompilationUnitFunction, function);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   950
        DELETE_UNIT(TYPEDEF, CompilationUnitTypedef, global_typedef);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   951
        DELETE_UNIT(VARIABLE, CompilationUnitVariable, global_variable);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   952
        DELETE_UNIT(STRUCT, CompilationUnitStruct, global_struct);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   953
        #undef DELETE_UNIT
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   954
        default: assert(0 && "missing cleanup code"); break;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   955
    } // switch
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   956
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   957
    // don't free (unit) here, the class-specific functions do it.
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   958
} // delete_compilation_unit
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   959
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   960
static Statement *new_typedef_statement(Context *ctx, Typedef *td)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   961
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   962
    NEW_AST_NODE(TypedefStatement)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   963
    retval->type = STATEMENTTYPE_TYPEDEF;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   964
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   965
    retval->type_info = td;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   966
    return (Statement *) retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   967
} // new_typedef_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   968
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   969
static void delete_typedef_statement(Context *ctx, TypedefStatement *stmt)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   970
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   971
    DELETE_AST_NODE(stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   972
    delete_statement(ctx, stmt->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   973
    delete_typedef(ctx, stmt->type_info);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   974
    Free(ctx, stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   975
} // delete_typedef_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   976
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   977
static Statement *new_return_statement(Context *ctx, Expression *expr)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   978
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   979
    NEW_AST_NODE(ReturnStatement);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   980
    retval->type = STATEMENTTYPE_RETURN;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   981
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   982
    retval->expr = expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   983
    return (Statement *) retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   984
} // new_return_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   985
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   986
static void delete_return_statement(Context *ctx, ReturnStatement *stmt)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   987
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   988
    DELETE_AST_NODE(stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   989
    delete_statement(ctx, stmt->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   990
    delete_expr(ctx, stmt->expr);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   991
    Free(ctx, stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   992
} // delete_return_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   993
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   994
static Statement *new_for_statement(Context *ctx, VariableDeclaration *decl,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   995
                                    Expression *initializer,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   996
                                    Expression *looptest, Expression *counter,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   997
                                    Statement *statement)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   998
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   999
    NEW_AST_NODE(ForStatement);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1000
    retval->type = STATEMENTTYPE_FOR;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1001
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1002
    retval->unroll = -1;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1003
    retval->var_decl = decl;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1004
    retval->initializer = initializer;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1005
    retval->looptest = looptest;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1006
    retval->counter = counter;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1007
    retval->statement = statement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1008
    return (Statement *) retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1009
} // new_for_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1010
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1011
static void delete_for_statement(Context *ctx, ForStatement *stmt)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1012
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1013
    DELETE_AST_NODE(stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1014
    delete_statement(ctx, stmt->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1015
    delete_variable_declaration(ctx, stmt->var_decl);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1016
    delete_expr(ctx, stmt->initializer);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1017
    delete_expr(ctx, stmt->looptest);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1018
    delete_expr(ctx, stmt->counter);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1019
    delete_statement(ctx, stmt->statement);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1020
    Free(ctx, stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1021
} // delete_for_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1022
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1023
static Statement *new_do_statement(Context *ctx, int64 unroll,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1024
                                   Statement *stmt, Expression *expr)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1025
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1026
    NEW_AST_NODE(DoStatement);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1027
    retval->type = STATEMENTTYPE_DO;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1028
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1029
    retval->unroll = unroll;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1030
    retval->expr = expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1031
    retval->statement = stmt;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1032
    return (Statement *) retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1033
} // new_do_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1034
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1035
static void delete_do_statement(Context *ctx, DoStatement *stmt)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1036
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1037
    DELETE_AST_NODE(stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1038
    delete_statement(ctx, stmt->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1039
    delete_statement(ctx, stmt->statement);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1040
    delete_expr(ctx, stmt->expr);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1041
    Free(ctx, stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1042
} // delete_do_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1043
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1044
static Statement *new_while_statement(Context *ctx, int64 unroll,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1045
                                      Expression *expr, Statement *stmt)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1046
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1047
    NEW_AST_NODE(WhileStatement);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1048
    retval->type = STATEMENTTYPE_WHILE;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1049
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1050
    retval->unroll = unroll;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1051
    retval->expr = expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1052
    retval->statement = stmt;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1053
    return (Statement *) retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1054
} // new_while_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1055
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1056
static void delete_while_statement(Context *ctx, WhileStatement *stmt)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1057
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1058
    DELETE_AST_NODE(stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1059
    delete_statement(ctx, stmt->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1060
    delete_statement(ctx, stmt->statement);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1061
    delete_expr(ctx, stmt->expr);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1062
    Free(ctx, stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1063
} // delete_while_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1064
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1065
static Statement *new_if_statement(Context *ctx, int attr, Expression *expr,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1066
                                   Statement *stmt, Statement *elsestmt)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1067
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1068
    NEW_AST_NODE(IfStatement);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1069
    retval->type = STATEMENTTYPE_IF;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1070
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1071
    retval->attributes = attr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1072
    retval->expr = expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1073
    retval->statement = stmt;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1074
    retval->else_statement = elsestmt;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1075
    return (Statement *) retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1076
} // new_if_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1077
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1078
static void delete_if_statement(Context *ctx, IfStatement *stmt)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1079
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1080
    DELETE_AST_NODE(stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1081
    delete_statement(ctx, stmt->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1082
    delete_expr(ctx, stmt->expr);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1083
    delete_statement(ctx, stmt->statement);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1084
    delete_statement(ctx, stmt->else_statement);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1085
    Free(ctx, stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1086
} // delete_if_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1087
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1088
static SwitchCases *new_switch_case(Context *ctx, Expression *expr,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1089
                                    Statement *stmt)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1090
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1091
    NEW_AST_NODE(SwitchCases);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1092
    retval->expr = expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1093
    retval->statement = stmt;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1094
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1095
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1096
} // new_switch_case
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1097
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1098
static void delete_switch_case(Context *ctx, SwitchCases *sc)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1099
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1100
    DELETE_AST_NODE(sc);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1101
    delete_switch_case(ctx, sc->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1102
    delete_expr(ctx, sc->expr);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1103
    delete_statement(ctx, sc->statement);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1104
    Free(ctx, sc);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1105
} // delete_switch_case
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1106
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1107
static Statement *new_empty_statement(Context *ctx)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1108
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1109
    NEW_AST_NODE(EmptyStatement);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1110
    retval->type = STATEMENTTYPE_EMPTY;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1111
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1112
    return (Statement *) retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1113
} // new_empty_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1114
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1115
static void delete_empty_statement(Context *ctx, EmptyStatement *stmt)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1116
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1117
    DELETE_AST_NODE(stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1118
    delete_statement(ctx, stmt->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1119
    Free(ctx, stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1120
} // delete_empty_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1121
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus