mojoshader_compiler.c
author Ryan C. Gordon <icculus@icculus.org>
Wed, 13 Oct 2010 17:29:28 -0400
changeset 916 3738cd265707
parent 915 55b583afec46
child 917 85afb474f99d
permissions -rw-r--r--
Added a FIXME.
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
916
3738cd265707 Added a FIXME.
Ryan C. Gordon <icculus@icculus.org>
parents: 915
diff changeset
    17
// !!! FIXME: I'd like to lose this. It's really inefficient. Just keep a
3738cd265707 Added a FIXME.
Ryan C. Gordon <icculus@icculus.org>
parents: 915
diff changeset
    18
// !!! FIXME:  (tail) on these list structures instead?
855
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    19
#define REVERSE_LINKED_LIST(typ, head) { \
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    20
    if ((head) && (head->next)) { \
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    21
        typ *tmp = NULL; \
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    22
        typ *tmp1 = NULL; \
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    23
        while (head != NULL) { \
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    24
            tmp = head; \
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    25
            head = head->next; \
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    26
            tmp->next = tmp1; \
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    27
            tmp1 = tmp; \
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    28
        } \
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    29
        head = tmp; \
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    30
    } \
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    31
}
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    32
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    33
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
    34
{
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    35
    int64 i64;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    36
    double dbl;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    37
    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
    38
} TokenData;
a43d07e5da68 Added some structure for user types (struct at the moment).
Ryan C. Gordon <icculus@icculus.org>
parents: 731
diff changeset
    39
a43d07e5da68 Added some structure for user types (struct at the moment).
Ryan C. Gordon <icculus@icculus.org>
parents: 731
diff changeset
    40
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
    41
// 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
    42
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    43
typedef enum ASTNodeType
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    44
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    45
    AST_OP_START_RANGE,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    46
    AST_OP_START_RANGE_UNARY,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    47
    AST_OP_POSTINCREMENT,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    48
    AST_OP_POSTDECREMENT,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    49
    AST_OP_PREINCREMENT,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    50
    AST_OP_PREDECREMENT,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    51
    AST_OP_NEGATE,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    52
    AST_OP_COMPLEMENT,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    53
    AST_OP_NOT,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    54
    AST_OP_END_RANGE_UNARY,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    55
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    56
    AST_OP_START_RANGE_BINARY,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    57
    AST_OP_DEREF_ARRAY,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    58
    AST_OP_CALLFUNC,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    59
    AST_OP_DEREF_STRUCT,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    60
    AST_OP_COMMA,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    61
    AST_OP_MULTIPLY,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    62
    AST_OP_DIVIDE,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    63
    AST_OP_MODULO,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    64
    AST_OP_ADD,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    65
    AST_OP_SUBTRACT,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    66
    AST_OP_LSHIFT,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    67
    AST_OP_RSHIFT,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    68
    AST_OP_LESSTHAN,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    69
    AST_OP_GREATERTHAN,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    70
    AST_OP_LESSTHANOREQUAL,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    71
    AST_OP_GREATERTHANOREQUAL,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    72
    AST_OP_EQUAL,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    73
    AST_OP_NOTEQUAL,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    74
    AST_OP_BINARYAND,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    75
    AST_OP_BINARYXOR,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    76
    AST_OP_BINARYOR,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    77
    AST_OP_LOGICALAND,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    78
    AST_OP_LOGICALOR,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    79
    AST_OP_ASSIGN,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    80
    AST_OP_MULASSIGN,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    81
    AST_OP_DIVASSIGN,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    82
    AST_OP_MODASSIGN,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    83
    AST_OP_ADDASSIGN,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    84
    AST_OP_SUBASSIGN,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    85
    AST_OP_LSHIFTASSIGN,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    86
    AST_OP_RSHIFTASSIGN,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    87
    AST_OP_ANDASSIGN,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    88
    AST_OP_XORASSIGN,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    89
    AST_OP_ORASSIGN,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    90
    AST_OP_END_RANGE_BINARY,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    91
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    92
    AST_OP_START_RANGE_TERNARY,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    93
    AST_OP_CONDITIONAL,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    94
    AST_OP_END_RANGE_TERNARY,
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    95
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    96
    AST_OP_START_RANGE_DATA,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    97
    AST_OP_IDENTIFIER,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    98
    AST_OP_INT_LITERAL,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
    99
    AST_OP_FLOAT_LITERAL,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   100
    AST_OP_STRING_LITERAL,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   101
    AST_OP_END_RANGE_DATA,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   102
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   103
    AST_OP_START_RANGE_MISC,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   104
    AST_OP_CONSTRUCTOR,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   105
    AST_OP_CAST,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   106
    AST_OP_END_RANGE_MISC,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   107
    AST_OP_END_RANGE,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   108
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   109
    AST_COMPUNIT_START_RANGE,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   110
    AST_COMPUNIT_FUNCTION,    // function declaration or definition
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   111
    AST_COMPUNIT_TYPEDEF,     // typedef or struct
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   112
    AST_COMPUNIT_STRUCT,      // global struct
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   113
    AST_COMPUNIT_VARIABLE,    // global variable
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   114
    AST_COMPUNIT_END_RANGE,
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   115
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   116
    AST_STATEMENT_START_RANGE,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   117
    AST_STATEMENT_EMPTY,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   118
    AST_STATEMENT_EXPRESSION,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   119
    AST_STATEMENT_IF,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   120
    AST_STATEMENT_SWITCH,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   121
    AST_STATEMENT_FOR,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   122
    AST_STATEMENT_DO,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   123
    AST_STATEMENT_WHILE,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   124
    AST_STATEMENT_RETURN,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   125
    AST_STATEMENT_BREAK,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   126
    AST_STATEMENT_CONTINUE,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   127
    AST_STATEMENT_DISCARD,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   128
    AST_STATEMENT_TYPEDEF,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   129
    AST_STATEMENT_STRUCT,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   130
    AST_STATEMENT_VARDECL,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   131
    AST_STATEMENT_END_RANGE,
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   132
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   133
    AST_MISC_START_RANGE,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   134
    AST_FUNCTION_ARGS,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   135
    AST_FUNCTION_SIGNATURE,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   136
    AST_SCALAR_OR_ARRAY,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   137
    AST_TYPEDEF,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   138
    AST_PACK_OFFSET,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   139
    AST_VARIABLE_LOWLEVEL,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   140
    AST_ANNOTATION,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   141
    AST_VARIABLE_DECLARATION,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   142
    AST_STRUCT_DECLARATION,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   143
    AST_STRUCT_MEMBER,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   144
    AST_SWITCH_CASE,
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   145
    AST_MISC_END_RANGE,
837
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   146
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   147
    AST_END_RANGE
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   148
} ASTNodeType;
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   149
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   150
typedef struct ASTNode
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   151
{
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   152
    ASTNodeType type;
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   153
    const char *filename;
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   154
    uint32 line;
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   155
} ASTNode;
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   156
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   157
typedef enum VariableAttributes
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   158
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   159
    VARATTR_EXTERN = (1 << 0),
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   160
    VARATTR_NOINTERPOLATION = (1 << 1),
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   161
    VARATTR_SHARED = (1 << 2),
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   162
    VARATTR_STATIC = (1 << 3),
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   163
    VARATTR_UNIFORM = (1 << 4),
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   164
    VARATTR_VOLATILE = (1 << 5),
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   165
    VARATTR_CONST = (1 << 6),
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   166
    VARATTR_ROWMAJOR = (1 << 7),
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   167
    VARATTR_COLUMNMAJOR = (1 << 8)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   168
} VariableAttributes;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   169
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   170
typedef enum IfAttributes
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   171
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   172
    IFATTR_NONE,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   173
    IFATTR_BRANCH,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   174
    IFATTR_FLATTEN,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   175
    IFATTR_IFALL,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   176
    IFATTR_IFANY,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   177
    IFATTR_PREDICATE,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   178
    IFATTR_PREDICATEBLOCK,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   179
} IfAttributes;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   180
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   181
typedef enum SwitchAttributes
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   182
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   183
    SWITCHATTR_NONE,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   184
    SWITCHATTR_FLATTEN,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   185
    SWITCHATTR_BRANCH,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   186
    SWITCHATTR_FORCECASE,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   187
    SWITCHATTR_CALL
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   188
} SwitchAttributes;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   189
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   190
static inline int operator_is_unary(const ASTNodeType op)
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   191
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   192
    return ((op > AST_OP_START_RANGE_UNARY) && (op < AST_OP_END_RANGE_UNARY));
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   193
} // operator_is_unary
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   194
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   195
static inline int operator_is_binary(const ASTNodeType op)
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   196
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   197
    return ((op > AST_OP_START_RANGE_BINARY) && (op < AST_OP_END_RANGE_BINARY));
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   198
} // operator_is_binary
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   199
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   200
static inline int operator_is_ternary(const ASTNodeType op)
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   201
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   202
    return ((op > AST_OP_START_RANGE_TERNARY) && (op < AST_OP_END_RANGE_TERNARY));
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   203
} // operator_is_ternary
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   204
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   205
typedef struct ASTGeneric
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   206
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   207
    ASTNode ast;
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   208
} ASTGeneric;
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   209
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   210
typedef ASTGeneric Expression;
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   211
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   212
typedef struct ExpressionUnary
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   213
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   214
    ASTNode ast;
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   215
    Expression *operand;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   216
} ExpressionUnary;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   217
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   218
typedef struct ExpressionBinary
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   219
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   220
    ASTNode ast;
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   221
    Expression *left;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   222
    Expression *right;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   223
} ExpressionBinary;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   224
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   225
typedef struct ExpressionTernary
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   226
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   227
    ASTNode ast;
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   228
    Expression *left;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   229
    Expression *center;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   230
    Expression *right;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   231
} ExpressionTernary;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   232
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   233
typedef struct ExpressionIdentifier
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   234
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   235
    ASTNode ast;  // Always AST_OP_IDENTIFIER
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   236
    const char *identifier;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   237
} ExpressionIdentifier;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   238
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   239
typedef struct ExpressionIntLiteral
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   240
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   241
    ASTNode ast;  // Always AST_OP_INT_LITERAL
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   242
    int64 value;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   243
} ExpressionIntLiteral;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   244
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   245
typedef struct ExpressionFloatLiteral
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   246
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   247
    ASTNode ast;  // Always AST_OP_FLOAT_LITERAL
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   248
    double value;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   249
} ExpressionFloatLiteral;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   250
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   251
typedef struct ExpressionStringLiteral
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   252
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   253
    ASTNode ast;  // Always AST_OP_STRING_LITERAL
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   254
    const char *string;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   255
} ExpressionStringLiteral;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   256
837
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   257
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
   258
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   259
    ASTNode ast;  // Always AST_OP_CONSTRUCTOR
837
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   260
    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
   261
    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
   262
} ExpressionConstructor;
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   263
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   264
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
   265
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   266
    ASTNode ast;  // Always AST_OP_CAST
837
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   267
    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
   268
    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
   269
} ExpressionCast;
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   270
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   271
typedef struct CompilationUnit
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   272
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   273
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   274
    struct CompilationUnit *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   275
} CompilationUnit;
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
typedef enum FunctionStorageClass
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   278
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   279
    FNSTORECLS_NONE,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   280
    FNSTORECLS_INLINE
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   281
} FunctionStorageClass;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   282
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   283
typedef enum InputModifier
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   284
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   285
    INPUTMOD_NONE,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   286
    INPUTMOD_IN,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   287
    INPUTMOD_OUT,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   288
    INPUTMOD_INOUT,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   289
    INPUTMOD_UNIFORM
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   290
} InputModifier;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   291
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   292
typedef enum InterpolationModifier
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
    INTERPMOD_NONE,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   295
    INTERPMOD_LINEAR,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   296
    INTERPMOD_CENTROID,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   297
    INTERPMOD_NOINTERPOLATION,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   298
    INTERPMOD_NOPERSPECTIVE,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   299
    INTERPMOD_SAMPLE
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   300
} InterpolationModifier;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   301
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   302
typedef struct FunctionArguments
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   303
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   304
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   305
    InputModifier input_modifier;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   306
    const char *datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   307
    const char *identifier;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   308
    const char *semantic;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   309
    InterpolationModifier interpolation_modifier;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   310
    Expression *initializer;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   311
    struct FunctionArguments *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   312
} FunctionArguments;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   313
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   314
typedef struct FunctionSignature
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   315
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   316
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   317
    const char *datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   318
    const char *identifier;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   319
    FunctionArguments *args;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   320
    FunctionStorageClass storage_class;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   321
    const char *semantic;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   322
} FunctionSignature;
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
typedef struct ScalarOrArray
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   325
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   326
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   327
    const char *identifier;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   328
    int isarray;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   329
    Expression *dimension;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   330
} ScalarOrArray;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   331
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   332
typedef struct Annotations
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   333
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   334
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   335
    const char *datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   336
    Expression *initializer;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   337
    struct Annotations *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   338
} Annotations;
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 PackOffset
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   341
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   342
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   343
    const char *ident1;   // !!! FIXME: rename this.
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   344
    const char *ident2;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   345
} PackOffset;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   346
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   347
typedef struct VariableLowLevel
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   348
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   349
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   350
    PackOffset *packoffset;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   351
    const char *register_name;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   352
} VariableLowLevel;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   353
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   354
typedef struct StructMembers
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   355
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   356
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   357
    const char *datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   358
    const char *semantic;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   359
    ScalarOrArray *details;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   360
    InterpolationModifier interpolation_mod;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   361
    struct StructMembers *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   362
} StructMembers;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   363
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   364
typedef struct StructDeclaration
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   365
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   366
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   367
    const char *name;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   368
    StructMembers *members;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   369
} StructDeclaration;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   370
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   371
typedef struct VariableDeclaration
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   372
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   373
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   374
    int attributes;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   375
    const char *datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   376
    StructDeclaration *anonymous_datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   377
    ScalarOrArray *details;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   378
    const char *semantic;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   379
    Annotations *annotations;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   380
    Expression *initializer;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   381
    VariableLowLevel *lowlevel;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   382
    struct VariableDeclaration *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   383
} VariableDeclaration;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   384
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   385
typedef struct Statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   386
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   387
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   388
    struct Statement *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   389
} Statement;
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 Statement EmptyStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   392
typedef Statement BreakStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   393
typedef Statement ContinueStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   394
typedef Statement DiscardStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   395
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   396
typedef struct ReturnStatement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   397
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   398
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   399
    struct Statement *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   400
    Expression *expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   401
} ReturnStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   402
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   403
typedef struct ExpressionStatement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   404
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   405
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   406
    struct Statement *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   407
    Expression *expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   408
} ExpressionStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   409
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   410
typedef struct IfStatement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   411
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   412
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   413
    struct Statement *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   414
    int attributes;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   415
    Expression *expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   416
    Statement *statement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   417
    Statement *else_statement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   418
} IfStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   419
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   420
typedef struct SwitchCases
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   421
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   422
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   423
    Expression *expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   424
    Statement *statement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   425
    struct SwitchCases *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   426
} SwitchCases;
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 SwitchStatement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   429
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   430
    ASTNode ast;
836
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
    int attributes;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   433
    Expression *expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   434
    SwitchCases *cases;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   435
} SwitchStatement;
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
typedef struct WhileStatement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   438
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   439
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   440
    struct Statement *next;
854
65e06097e450 Filled in the rest of the missing print_ast() cases.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   441
    int64 unroll;  // # times to unroll, 0 to loop, negative for compiler's choice.
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   442
    Expression *expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   443
    Statement *statement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   444
} WhileStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   445
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   446
typedef WhileStatement DoStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   447
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   448
typedef struct ForStatement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   449
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   450
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   451
    struct Statement *next;
854
65e06097e450 Filled in the rest of the missing print_ast() cases.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   452
    int64 unroll;  // # times to unroll, 0 to loop, negative for compiler's choice.
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   453
    VariableDeclaration *var_decl;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   454
    Expression *initializer;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   455
    Expression *looptest;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   456
    Expression *counter;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   457
    Statement *statement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   458
} ForStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   459
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   460
typedef struct Typedef
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   461
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   462
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   463
    int isconst;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   464
    const char *datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   465
    ScalarOrArray *details;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   466
} Typedef;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   467
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   468
typedef struct TypedefStatement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   469
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   470
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   471
    struct Statement *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   472
    Typedef *type_info;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   473
} TypedefStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   474
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   475
typedef struct VarDeclStatement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   476
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   477
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   478
    struct Statement *next;
853
f6b69debce78 Bunch More Work on print_ast().
Ryan C. Gordon <icculus@icculus.org>
parents: 852
diff changeset
   479
    VariableDeclaration *declaration;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   480
} VarDeclStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   481
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   482
typedef struct StructStatement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   483
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   484
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   485
    struct Statement *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   486
    StructDeclaration *struct_info;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   487
} StructStatement;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   488
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   489
typedef struct CompilationUnitFunction
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   490
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   491
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   492
    struct CompilationUnit *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   493
    FunctionSignature *declaration;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   494
    Statement *definition;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   495
} CompilationUnitFunction;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   496
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   497
typedef struct CompilationUnitTypedef
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   498
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   499
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   500
    struct CompilationUnit *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   501
    Typedef *type_info;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   502
} CompilationUnitTypedef;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   503
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   504
typedef struct CompilationUnitStruct
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   505
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   506
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   507
    struct CompilationUnit *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   508
    StructDeclaration *struct_info;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   509
} CompilationUnitStruct;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   510
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   511
typedef struct CompilationUnitVariable
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   512
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   513
    ASTNode ast;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   514
    struct CompilationUnit *next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   515
    VariableDeclaration *declaration;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   516
} CompilationUnitVariable;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   517
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   518
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   519
// This tracks typedefs and structs, and notes when they enter/leave scope.
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   520
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   521
typedef struct UserTypeScopeStack
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   522
{
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   523
    const char *symbol;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   524
    const char *datatype;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   525
    struct UserTypeScopeStack *next;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   526
} UserTypeScopeStack;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   527
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   528
typedef struct UserTypeMap
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   529
{
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   530
    HashTable *types;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   531
    UserTypeScopeStack *scope;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   532
} UserTypeMap;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   533
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   534
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   535
// 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
   536
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   537
typedef struct Context
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   538
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   539
    int isfail;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   540
    int out_of_memory;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   541
    MOJOSHADER_malloc malloc;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   542
    MOJOSHADER_free free;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   543
    void *malloc_data;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   544
    int error_count;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   545
    ErrorList *errors;
858
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 857
diff changeset
   546
    StringCache *strcache;
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   547
    const char *sourcefile;  // current source file that we're parsing.
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   548
    unsigned int sourceline; // current line in sourcefile that we're parsing.
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   549
    UserTypeMap usertypes;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   550
    CompilationUnit *ast;  // Abstract Syntax Tree
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   551
} Context;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   552
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   553
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   554
// Convenience functions for allocators...
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   555
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   556
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
   557
{
842
1ea7f51250fb A little work on error handling in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 839
diff changeset
   558
    if (!ctx->out_of_memory) printf("out of memory\n");  // !!! FIXME: placeholder.
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   559
    ctx->isfail = ctx->out_of_memory = 1;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   560
} // out_of_memory
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   561
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   562
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
   563
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   564
    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
   565
    if (retval == NULL)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   566
        out_of_memory(ctx);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   567
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   568
} // Malloc
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   569
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   570
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
   571
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   572
    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
   573
    if (retval != NULL)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   574
        strcpy(retval, str);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   575
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   576
} // StrDup
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   577
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   578
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
   579
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   580
    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
   581
        ctx->free(ptr, ctx->malloc_data);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   582
} // Free
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   583
842
1ea7f51250fb A little work on error handling in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 839
diff changeset
   584
static void fail(Context *ctx, const char *str)
1ea7f51250fb A little work on error handling in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 839
diff changeset
   585
{
1ea7f51250fb A little work on error handling in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 839
diff changeset
   586
    // !!! FIXME: placeholder.
1ea7f51250fb A little work on error handling in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 839
diff changeset
   587
    (void) ctx;
843
d557c4336242 Keep track of token location when parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 842
diff changeset
   588
    printf("%s:%u: %s\n", ctx->sourcefile, ctx->sourceline, str);
842
1ea7f51250fb A little work on error handling in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 839
diff changeset
   589
} // fail
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   590
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   591
859
824d67791db0 Implemented StringMap, for future use.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   592
static void usertypemap_nuke(const void *k, const void *v, void *d) {/*no-op*/}
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   593
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   594
static int create_usertypemap(Context *ctx)
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   595
{
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   596
    UserTypeMap *map = &ctx->usertypes;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   597
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   598
    map->scope = NULL;
859
824d67791db0 Implemented StringMap, for future use.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   599
    map->types = hash_create(ctx, hash_hash_string, hash_keymatch_string,
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   600
                             usertypemap_nuke, 1, ctx->malloc, ctx->free,
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   601
                             ctx->malloc_data);
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   602
    if (!map->types)
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   603
    {
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   604
        out_of_memory(ctx);
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   605
        return 0;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   606
    } // if
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   607
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   608
    return 1;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   609
} // create_usertypemap
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   610
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   611
static void push_usertype(Context *ctx, const char *sym, const char *datatype)
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   612
{
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   613
    UserTypeMap *map = &ctx->usertypes;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   614
    UserTypeScopeStack *item;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   615
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   616
    item = (UserTypeScopeStack *) Malloc(ctx, sizeof (UserTypeScopeStack));
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   617
    if (item == NULL)
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   618
        return;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   619
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   620
    if (sym != NULL)
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   621
    {
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   622
        if (hash_insert(map->types, sym, datatype) == -1)
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   623
        {
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   624
            Free(ctx, item);
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   625
            return;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   626
        }
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   627
    } // if
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   628
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   629
    item->symbol = sym;  // cached strings, don't copy.
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   630
    item->datatype = datatype;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   631
    item->next = map->scope;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   632
    map->scope = item;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   633
} // push_usertype
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   634
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   635
static void pop_usertype(Context *ctx)
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   636
{
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   637
    UserTypeMap *map = &ctx->usertypes;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   638
    UserTypeScopeStack *item = map->scope;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   639
    if (!item)
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   640
        return;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   641
    if (item->symbol)
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   642
        hash_remove(map->types, item->symbol);
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   643
    map->scope = item->next;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   644
    Free(ctx, item);
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   645
} // pop_usertype
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   646
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   647
static void push_scope(Context *ctx)
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   648
{
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   649
    push_usertype(ctx, NULL, NULL);
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   650
} // push_scope
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   651
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   652
static void pop_scope(Context *ctx)
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   653
{
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   654
    UserTypeMap *map = &ctx->usertypes;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   655
    while ((map->scope) && (map->scope->symbol))
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   656
        pop_usertype(ctx);
850
473108b0366d Fixed pop_scope().
Ryan C. Gordon <icculus@icculus.org>
parents: 849
diff changeset
   657
473108b0366d Fixed pop_scope().
Ryan C. Gordon <icculus@icculus.org>
parents: 849
diff changeset
   658
    assert(map->scope != NULL);
473108b0366d Fixed pop_scope().
Ryan C. Gordon <icculus@icculus.org>
parents: 849
diff changeset
   659
    assert(map->scope->symbol == NULL);
473108b0366d Fixed pop_scope().
Ryan C. Gordon <icculus@icculus.org>
parents: 849
diff changeset
   660
    pop_usertype(ctx);
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   661
} // push_scope
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   662
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   663
static void destroy_usertypemap(Context *ctx)
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   664
{
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   665
    UserTypeMap *map = &ctx->usertypes;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   666
    while (map->scope)
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   667
        pop_usertype(ctx);
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   668
    hash_destroy(map->types);
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   669
} // destroy_usertypemap
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   670
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   671
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   672
// 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
   673
//  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
   674
//  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
   675
//  afterwards.
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   676
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   677
#define NEW_AST_NODE(retval, cls, typ) \
883
df6265a993bc Fixed C++ compiler error.
Ryan C. Gordon <icculus@icculus.org>
parents: 868
diff changeset
   678
    cls *retval = (cls *) Malloc(ctx, sizeof (cls)); \
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   679
    do { \
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   680
        if (retval == NULL) { return NULL; } \
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   681
        retval->ast.type = typ; \
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   682
        retval->ast.filename = ctx->sourcefile; \
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   683
        retval->ast.line = ctx->sourceline; \
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   684
    } while (0)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   685
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   686
#define DELETE_AST_NODE(cls) do { \
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   687
    if (!cls) return; \
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   688
} while (0)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   689
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   690
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
   691
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
   692
837
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   693
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
   694
                                        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
   695
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   696
    NEW_AST_NODE(retval, ExpressionConstructor, AST_OP_CONSTRUCTOR);
837
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   697
    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
   698
    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
   699
    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
   700
} // 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
   701
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   702
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
   703
                                 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
   704
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   705
    NEW_AST_NODE(retval, ExpressionCast, AST_OP_CAST);
837
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   706
    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
   707
    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
   708
    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
   709
} // 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
   710
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   711
static Expression *new_unary_expr(Context *ctx, const ASTNodeType op,
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   712
                                  Expression *operand)
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   713
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   714
    NEW_AST_NODE(retval, ExpressionUnary, op);
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   715
    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
   716
    retval->operand = operand;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   717
    return (Expression *) retval;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   718
} // new_unary_expr
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   719
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   720
static Expression *new_binary_expr(Context *ctx, const ASTNodeType op,
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   721
                                   Expression *left, Expression *right)
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   722
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   723
    NEW_AST_NODE(retval, ExpressionBinary, op);
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   724
    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
   725
    retval->left = left;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   726
    retval->right = right;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   727
    return (Expression *) retval;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   728
} // new_binary_expr
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   729
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   730
static Expression *new_ternary_expr(Context *ctx, const ASTNodeType op,
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   731
                                    Expression *left, Expression *center,
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   732
                                    Expression *right)
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   733
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   734
    NEW_AST_NODE(retval, ExpressionTernary, op);
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   735
    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
   736
    retval->left = left;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   737
    retval->center = center;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   738
    retval->right = right;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   739
    return (Expression *) retval;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   740
} // new_ternary_expr
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   741
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   742
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
   743
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   744
    NEW_AST_NODE(retval, ExpressionIdentifier, AST_OP_IDENTIFIER);
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   745
    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
   746
    return (Expression *) retval;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   747
} // new_identifier_expr
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   748
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   749
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
   750
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   751
    NEW_AST_NODE(retval, ExpressionIntLiteral, AST_OP_INT_LITERAL);
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   752
    retval->value = value;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   753
    return (Expression *) retval;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   754
} // new_literal_int_expr
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   755
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   756
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
   757
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   758
    NEW_AST_NODE(retval, ExpressionFloatLiteral, AST_OP_FLOAT_LITERAL);
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   759
    retval->value = dbl;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   760
    return (Expression *) retval;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   761
} // new_literal_float_expr
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   762
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   763
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
   764
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   765
    NEW_AST_NODE(retval, ExpressionStringLiteral, AST_OP_STRING_LITERAL);
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   766
    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
   767
    return (Expression *) retval;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   768
} // new_string_literal_expr
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   769
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   770
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
   771
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   772
    DELETE_AST_NODE(expr);
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   773
    if (operator_is_unary(expr->ast.type))
836
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
        const ExpressionUnary *unary = (const ExpressionUnary *) expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   776
        delete_expr(ctx, unary->operand);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   777
    } // if
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   778
    else if (operator_is_binary(expr->ast.type))
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   779
    {
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   780
        const ExpressionBinary *binary = (const ExpressionBinary *) expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   781
        delete_expr(ctx, binary->left);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   782
        delete_expr(ctx, binary->right);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   783
    } // else if
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   784
    else if (operator_is_ternary(expr->ast.type))
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   785
    {
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   786
        const ExpressionTernary *ternary = (const ExpressionTernary *) expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   787
        delete_expr(ctx, ternary->left);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   788
        delete_expr(ctx, ternary->center);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   789
        delete_expr(ctx, ternary->right);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   790
    } // else if
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   791
    else if (expr->ast.type == AST_OP_CAST)
837
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   792
    {
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   793
        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
   794
    } // else if
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   795
    else if (expr->ast.type == AST_OP_CONSTRUCTOR)
837
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   796
    {
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   797
        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
   798
    } // else if
845
d10d31b9b695 Removed incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 844
diff changeset
   799
d10d31b9b695 Removed incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 844
diff changeset
   800
    // rest of operators don't have extra data to free.
d10d31b9b695 Removed incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 844
diff changeset
   801
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   802
    Free(ctx, expr);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   803
} // delete_expr
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   804
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   805
static FunctionArguments *new_function_arg(Context *ctx,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   806
                                        const InputModifier inputmod,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   807
                                        const char *datatype,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   808
                                        const char *identifier,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   809
                                        const char *semantic,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   810
                                        const InterpolationModifier interpmod,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   811
                                        Expression *initializer)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   812
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   813
    NEW_AST_NODE(retval, FunctionArguments, AST_FUNCTION_ARGS);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   814
    retval->input_modifier = inputmod;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   815
    retval->datatype = datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   816
    retval->identifier = identifier;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   817
    retval->semantic = semantic;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   818
    retval->interpolation_modifier = interpmod;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   819
    retval->initializer = initializer;
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_function_arg
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_function_args(Context *ctx, FunctionArguments *args)
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(args);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   827
    delete_function_args(ctx, args->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   828
    delete_expr(ctx, args->initializer);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   829
    Free(ctx, args);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   830
} // delete_function_args
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   831
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   832
static FunctionSignature *new_function_signature(Context *ctx,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   833
                                                 const char *datatype,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   834
                                                 const char *identifier,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   835
                                                 FunctionArguments *args)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   836
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   837
    NEW_AST_NODE(retval, FunctionSignature, AST_FUNCTION_SIGNATURE);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   838
    retval->datatype = datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   839
    retval->identifier = identifier;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   840
    retval->args = args;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   841
    retval->storage_class = FNSTORECLS_NONE;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   842
    retval->semantic = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   843
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   844
} // new_function_signature
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   845
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   846
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
   847
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   848
    DELETE_AST_NODE(sig);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   849
    delete_function_args(ctx, sig->args);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   850
    Free(ctx, sig);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   851
} // delete_function_signature
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_function(Context *ctx,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   854
                                     FunctionSignature *declaration,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   855
                                     Statement *definition)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   856
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   857
    NEW_AST_NODE(retval, CompilationUnitFunction, AST_COMPUNIT_FUNCTION);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   858
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   859
    retval->declaration = declaration;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   860
    retval->definition = definition;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   861
    return (CompilationUnit *) retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   862
} // new_function
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
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
   865
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   866
    DELETE_AST_NODE(unitfn);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   867
    delete_compilation_unit(ctx, unitfn->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   868
    delete_function_signature(ctx, unitfn->declaration);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   869
    delete_statement(ctx, unitfn->definition);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   870
    Free(ctx, unitfn);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   871
} // delete_function
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
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
   874
                                          const int isvec, Expression *dim)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   875
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   876
    NEW_AST_NODE(retval, ScalarOrArray, AST_SCALAR_OR_ARRAY);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   877
    retval->identifier = ident;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   878
    retval->isarray = isvec;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   879
    retval->dimension = dim;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   880
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   881
} // new_scalar_or_array
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   882
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   883
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
   884
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   885
    DELETE_AST_NODE(soa);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   886
    delete_expr(ctx, soa->dimension);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   887
    Free(ctx, soa);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   888
} // delete_scalar_or_array
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 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
   891
                            ScalarOrArray *soa)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   892
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   893
    NEW_AST_NODE(retval, Typedef, AST_TYPEDEF);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   894
    retval->isconst = isconst;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   895
    retval->datatype = datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   896
    retval->details = soa;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   897
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   898
} // new_typedef
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   899
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   900
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
   901
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   902
    DELETE_AST_NODE(td);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   903
    delete_scalar_or_array(ctx, td->details);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   904
    Free(ctx, td);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   905
} // delete_typedef
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   906
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   907
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
   908
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   909
    NEW_AST_NODE(retval, PackOffset, AST_PACK_OFFSET);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   910
    retval->ident1 = a;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   911
    retval->ident2 = b;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   912
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   913
} // new_pack_offset
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_pack_offset(Context *ctx, PackOffset *o)
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(o);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   918
    Free(ctx, o);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   919
} // delete_pack_offset
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   920
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   921
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
   922
                                               const char *reg)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   923
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   924
    NEW_AST_NODE(retval, VariableLowLevel, AST_VARIABLE_LOWLEVEL);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   925
    retval->packoffset = po;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   926
    retval->register_name = reg;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   927
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   928
} // new_variable_lowlevel
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   929
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   930
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
   931
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   932
    DELETE_AST_NODE(vll);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   933
    delete_pack_offset(ctx, vll->packoffset);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   934
    Free(ctx, vll);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   935
} // delete_variable_lowlevel
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   936
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   937
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
   938
                                   Expression *initializer)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   939
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   940
    NEW_AST_NODE(retval, Annotations, AST_ANNOTATION);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   941
    retval->datatype = datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   942
    retval->initializer = initializer;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   943
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   944
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   945
} // new_annotation
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
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
   948
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   949
    DELETE_AST_NODE(annotations);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   950
    delete_annotation(ctx, annotations->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   951
    delete_expr(ctx, annotations->initializer);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   952
    Free(ctx, annotations);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   953
} // delete_annotation
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   954
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   955
static VariableDeclaration *new_variable_declaration(Context *ctx,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   956
                                    ScalarOrArray *soa, const char *semantic,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   957
                                    Annotations *annotations, Expression *init,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   958
                                    VariableLowLevel *vll)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   959
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   960
    NEW_AST_NODE(retval, VariableDeclaration, AST_VARIABLE_DECLARATION);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   961
    retval->attributes = 0;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   962
    retval->datatype = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   963
    retval->anonymous_datatype = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   964
    retval->details = soa;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   965
    retval->semantic = semantic;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   966
    retval->annotations = annotations;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   967
    retval->initializer = init;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   968
    retval->lowlevel = vll;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   969
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   970
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   971
} // new_variable_declaration
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   972
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   973
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
   974
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   975
    DELETE_AST_NODE(dcl);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   976
    delete_variable_declaration(ctx, dcl->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   977
    delete_scalar_or_array(ctx, dcl->details);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   978
    delete_annotation(ctx, dcl->annotations);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   979
    delete_expr(ctx, dcl->initializer);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   980
    delete_variable_lowlevel(ctx, dcl->lowlevel);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   981
    Free(ctx, dcl);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   982
} // delete_variable_declaration
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   983
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   984
static CompilationUnit *new_global_variable(Context *ctx,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   985
                                            VariableDeclaration *decl)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   986
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
   987
    NEW_AST_NODE(retval, CompilationUnitVariable, AST_COMPUNIT_VARIABLE);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   988
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   989
    retval->declaration = decl;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   990
    return (CompilationUnit *) retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   991
} // new_global_variable
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   992
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   993
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
   994
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   995
    DELETE_AST_NODE(var);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   996
    delete_compilation_unit(ctx, var->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   997
    delete_variable_declaration(ctx, var->declaration);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   998
    Free(ctx, var);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   999
} // delete_global_variable
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1000
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1001
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
  1002
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
  1003
    NEW_AST_NODE(retval, CompilationUnitTypedef, AST_COMPUNIT_TYPEDEF);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1004
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1005
    retval->type_info = td;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1006
    return (CompilationUnit *) retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1007
} // new_global_typedef
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1008
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1009
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
  1010
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1011
    DELETE_AST_NODE(unit);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1012
    delete_compilation_unit(ctx, unit->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1013
    delete_typedef(ctx, unit->type_info);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1014
    Free(ctx, unit);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1015
} // delete_global_typedef
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1016
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1017
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
  1018
                                        const char *semantic)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1019
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
  1020
    NEW_AST_NODE(retval, StructMembers, AST_STRUCT_MEMBER);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1021
    retval->datatype = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1022
    retval->semantic = semantic;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1023
    retval->details = soa;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1024
    retval->interpolation_mod = INTERPMOD_NONE;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1025
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1026
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1027
} // new_struct_member
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1028
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1029
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
  1030
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1031
    DELETE_AST_NODE(member);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1032
    delete_struct_member(ctx, member->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1033
    delete_scalar_or_array(ctx, member->details);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1034
    Free(ctx, member);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1035
} // delete_struct_member
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
static StructDeclaration *new_struct_declaration(Context *ctx,
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1038
                                    const char *name, StructMembers *members)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1039
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
  1040
    NEW_AST_NODE(retval, StructDeclaration, AST_STRUCT_DECLARATION);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1041
    retval->name = name;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1042
    retval->members = members;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1043
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1044
} // new_struct_declaration
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1045
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1046
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
  1047
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1048
    DELETE_AST_NODE(decl);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1049
    delete_struct_member(ctx, decl->members);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1050
    Free(ctx, decl);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1051
} // delete_struct_declaration
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1052
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1053
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
  1054
{
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
  1055
    NEW_AST_NODE(retval, CompilationUnitStruct, AST_COMPUNIT_STRUCT);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1056
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1057
    retval->struct_info = sd;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1058
    return (CompilationUnit *) retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1059
} // new_global_struct
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1060
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1061
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
  1062
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1063
    DELETE_AST_NODE(unit);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1064
    delete_compilation_unit(ctx, unit->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1065
    delete_struct_declaration(ctx, unit->struct_info);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1066
    Free(ctx, unit);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1067
} // delete_global_struct
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1068
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1069
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
  1070
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1071
    if (!unit) return;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1072
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1073
    // 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
  1074
    //  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
  1075
    //  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
  1076
    //  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
  1077
    //  to recurse in their own delete methods.
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1078
    // 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
  1079
    //  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
  1080
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1081
    CompilationUnit *i = unit->next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1082
    unit->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1083
    while (i)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1084
    {
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1085
        CompilationUnit *next = i->next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1086
        i->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1087
        delete_compilation_unit(ctx, i);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1088
        i = next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1089
    } // while
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1090
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
  1091
    switch (unit->ast.type)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1092
    {
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1093
        #define DELETE_UNIT(typ, cls, fn) \
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 843
diff changeset
  1094
            case AST_COMPUNIT_##typ: delete_##fn(ctx, (cls *) unit); break;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1095
        DELETE_UNIT(FUNCTION, CompilationUnitFunction, function);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1096
        DELETE_UNIT(TYPEDEF, CompilationUnitTypedef, global_typedef);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1097
        DELETE_UNIT(VARIABLE, CompilationUnitVariable, global_variable);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1098
        DELETE_UNIT(STRUCT, CompilationUnitStruct, global_struct);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff