mojoshader_compiler.c
author Ryan C. Gordon <icculus@icculus.org>
Mon, 22 Nov 2010 13:24:04 -0500
changeset 958 02e7826c8c75
parent 945 f00ea3986db8
child 964 e8c09c28162e
permissions -rw-r--r--
Fixed some AST operations to be integer-only.
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
921
97b879e372c6 Added a FIXME.
Ryan C. Gordon <icculus@icculus.org>
parents: 920
diff changeset
    10
// !!! FIXME: this needs to be split into separate source files:
97b879e372c6 Added a FIXME.
Ryan C. Gordon <icculus@icculus.org>
parents: 920
diff changeset
    11
// !!! FIXME:  parse, AST, IR, etc. The problem is we need to deal with the
97b879e372c6 Added a FIXME.
Ryan C. Gordon <icculus@icculus.org>
parents: 920
diff changeset
    12
// !!! FIXME:  "Context" struct being passed around everywhere.
97b879e372c6 Added a FIXME.
Ryan C. Gordon <icculus@icculus.org>
parents: 920
diff changeset
    13
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
    14
#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
    15
#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
    16
716
94a804b54078 Cleaned up HLSL parser tracing.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
    17
#if DEBUG_COMPILER_PARSER
94a804b54078 Cleaned up HLSL parser tracing.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
    18
#define LEMON_SUPPORT_TRACING 1
94a804b54078 Cleaned up HLSL parser tracing.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
    19
#endif
94a804b54078 Cleaned up HLSL parser tracing.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
    20
916
3738cd265707 Added a FIXME.
Ryan C. Gordon <icculus@icculus.org>
parents: 915
diff changeset
    21
// !!! 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
    22
// !!! 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
    23
#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
    24
    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
    25
        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
    26
        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
    27
        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
    28
            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
    29
            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
    30
            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
    31
            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
    32
        } \
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    33
        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
    34
    } \
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    35
}
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    36
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
    37
static inline int operator_is_unary(const MOJOSHADER_astNodeType op)
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
    38
{
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
    39
    return ( (op > MOJOSHADER_AST_OP_START_RANGE_UNARY) &&
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
    40
             (op < MOJOSHADER_AST_OP_END_RANGE_UNARY) );
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
    41
} // operator_is_unary
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
    42
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
    43
static inline int operator_is_binary(const MOJOSHADER_astNodeType op)
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
    44
{
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
    45
    return ( (op > MOJOSHADER_AST_OP_START_RANGE_BINARY) &&
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
    46
             (op < MOJOSHADER_AST_OP_END_RANGE_BINARY) );
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
    47
} // operator_is_binary
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
    48
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
    49
static inline int operator_is_ternary(const MOJOSHADER_astNodeType op)
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
    50
{
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
    51
    return ( (op > MOJOSHADER_AST_OP_START_RANGE_TERNARY) &&
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
    52
             (op < MOJOSHADER_AST_OP_END_RANGE_TERNARY) );
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
    53
} // operator_is_ternary
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
    54
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
    55
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    56
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
    57
{
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    58
    int64 i64;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    59
    double dbl;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    60
    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
    61
} TokenData;
a43d07e5da68 Added some structure for user types (struct at the moment).
Ryan C. Gordon <icculus@icculus.org>
parents: 731
diff changeset
    62
a43d07e5da68 Added some structure for user types (struct at the moment).
Ryan C. Gordon <icculus@icculus.org>
parents: 731
diff changeset
    63
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
    64
// This tracks data types and variables, and notes when they enter/leave scope.
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
    65
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
    66
typedef struct SymbolScope
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
    67
{
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
    68
    const char *symbol;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
    69
    const char *datatype;
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
    70
    struct SymbolScope *next;
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
    71
} SymbolScope;
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
    72
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
    73
typedef struct SymbolMap
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
    74
{
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
    75
    HashTable *hash;
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
    76
    SymbolScope *scope;
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
    77
} SymbolMap;
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
    78
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
    79
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
    80
// 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
    81
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
    82
typedef struct Context
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
    83
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
    84
    int isfail;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
    85
    int out_of_memory;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
    86
    MOJOSHADER_malloc malloc;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
    87
    MOJOSHADER_free free;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
    88
    void *malloc_data;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
    89
    ErrorList *errors;
935
bef902f8b4d9 More filling in of API details. Framework is mostly complete now.
Ryan C. Gordon <icculus@icculus.org>
parents: 932
diff changeset
    90
    ErrorList *warnings;
858
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 857
diff changeset
    91
    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
    92
    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
    93
    unsigned int sourceline; // current line in sourcefile that we're parsing.
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
    94
    SymbolMap usertypes;
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
    95
    SymbolMap variables;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
    96
    MOJOSHADER_astNode *ast;  // Abstract Syntax Tree
932
079c62f868eb Filled in some stubs to flesh out the AST API.
Ryan C. Gordon <icculus@icculus.org>
parents: 931
diff changeset
    97
    const char *source_profile;
923
859fc7151d43 Fill in some default strings in the cache, so we can always compare by pointer.
Ryan C. Gordon <icculus@icculus.org>
parents: 922
diff changeset
    98
859fc7151d43 Fill in some default strings in the cache, so we can always compare by pointer.
Ryan C. Gordon <icculus@icculus.org>
parents: 922
diff changeset
    99
    // These are entries allocated in the strcache, so these pointers are
859fc7151d43 Fill in some default strings in the cache, so we can always compare by pointer.
Ryan C. Gordon <icculus@icculus.org>
parents: 922
diff changeset
   100
    //  valid from shortly after we create the cache until we destroy it
859fc7151d43 Fill in some default strings in the cache, so we can always compare by pointer.
Ryan C. Gordon <icculus@icculus.org>
parents: 922
diff changeset
   101
    //  with the rest of the context. This makes it so we can compare common
859fc7151d43 Fill in some default strings in the cache, so we can always compare by pointer.
Ryan C. Gordon <icculus@icculus.org>
parents: 922
diff changeset
   102
    //  strings by pointer without having to hash them every time, so long as
859fc7151d43 Fill in some default strings in the cache, so we can always compare by pointer.
Ryan C. Gordon <icculus@icculus.org>
parents: 922
diff changeset
   103
    //  we're comparing a string pointer we know came from this string cache.
929
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   104
    // The first batch are simplifed datatype strings ("b" == bool, etc).
923
859fc7151d43 Fill in some default strings in the cache, so we can always compare by pointer.
Ryan C. Gordon <icculus@icculus.org>
parents: 922
diff changeset
   105
    const char *str_b;  // "b"
859fc7151d43 Fill in some default strings in the cache, so we can always compare by pointer.
Ryan C. Gordon <icculus@icculus.org>
parents: 922
diff changeset
   106
    const char *str_f;  // "f"
859fc7151d43 Fill in some default strings in the cache, so we can always compare by pointer.
Ryan C. Gordon <icculus@icculus.org>
parents: 922
diff changeset
   107
    const char *str_i;  // "i"
925
2a7cae5f1d68 Added some more basic datatype strings to the initial string cache.
Ryan C. Gordon <icculus@icculus.org>
parents: 924
diff changeset
   108
    const char *str_u;  // "u"
2a7cae5f1d68 Added some more basic datatype strings to the initial string cache.
Ryan C. Gordon <icculus@icculus.org>
parents: 924
diff changeset
   109
    const char *str_h;  // "h"
2a7cae5f1d68 Added some more basic datatype strings to the initial string cache.
Ryan C. Gordon <icculus@icculus.org>
parents: 924
diff changeset
   110
    const char *str_d;  // "d"
2a7cae5f1d68 Added some more basic datatype strings to the initial string cache.
Ryan C. Gordon <icculus@icculus.org>
parents: 924
diff changeset
   111
    const char *str_s;  // "s"
929
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   112
    const char *str_S;  // "S"
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   113
    const char *str_s1;  // "s1"
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   114
    const char *str_s2;  // "s2"
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   115
    const char *str_s3;  // "s3"
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   116
    const char *str_sc;  // "sc"
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   117
    const char *str_ss;  // "ss"
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   118
    const char *str_sS;  // "sS"
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   119
    const char *str_Fs;  // "Fs"
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   120
    const char *str_Fu;  // "Fu"
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   121
    const char *str_ns;  // "ns"
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   122
    const char *str_nu;  // "nu"
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   123
} Context;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   124
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   125
940
bc2a5efade5e Added a bunch of FIXMEs to accurately portray current technical debt.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   126
// !!! FIXME: cut and paste between every damned source file follows...
bc2a5efade5e Added a bunch of FIXMEs to accurately portray current technical debt.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   127
// !!! FIXME: We need to make some sort of ContextBase that applies to all
bc2a5efade5e Added a bunch of FIXMEs to accurately portray current technical debt.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   128
// !!! FIXME:  files and move this stuff to mojoshader_common.c ...
bc2a5efade5e Added a bunch of FIXMEs to accurately portray current technical debt.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   129
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   130
// Convenience functions for allocators...
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   131
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   132
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
   133
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   134
    ctx->isfail = ctx->out_of_memory = 1;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   135
} // out_of_memory
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   136
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   137
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
   138
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   139
    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
   140
    if (retval == NULL)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   141
        out_of_memory(ctx);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   142
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   143
} // Malloc
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   144
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   145
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
   146
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   147
    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
   148
    if (retval != NULL)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   149
        strcpy(retval, str);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   150
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   151
} // StrDup
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   152
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   153
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
   154
{
939
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   155
    ctx->free(ptr, ctx->malloc_data);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   156
} // Free
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   157
939
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   158
static void *MallocBridge(int bytes, void *data)
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   159
{
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   160
    return Malloc((Context *) data, (size_t) bytes);
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   161
} // MallocBridge
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   162
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   163
static void FreeBridge(void *ptr, void *data)
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   164
{
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   165
    Free((Context *) data, ptr);
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   166
} // FreeBridge
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   167
932
079c62f868eb Filled in some stubs to flesh out the AST API.
Ryan C. Gordon <icculus@icculus.org>
parents: 931
diff changeset
   168
static void failf(Context *ctx, const char *fmt, ...) ISPRINTF(2,3);
079c62f868eb Filled in some stubs to flesh out the AST API.
Ryan C. Gordon <icculus@icculus.org>
parents: 931
diff changeset
   169
static void failf(Context *ctx, const char *fmt, ...)
842
1ea7f51250fb A little work on error handling in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 839
diff changeset
   170
{
932
079c62f868eb Filled in some stubs to flesh out the AST API.
Ryan C. Gordon <icculus@icculus.org>
parents: 931
diff changeset
   171
    ctx->isfail = 1;
939
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   172
    if (ctx->out_of_memory)
932
079c62f868eb Filled in some stubs to flesh out the AST API.
Ryan C. Gordon <icculus@icculus.org>
parents: 931
diff changeset
   173
        return;
079c62f868eb Filled in some stubs to flesh out the AST API.
Ryan C. Gordon <icculus@icculus.org>
parents: 931
diff changeset
   174
079c62f868eb Filled in some stubs to flesh out the AST API.
Ryan C. Gordon <icculus@icculus.org>
parents: 931
diff changeset
   175
    va_list ap;
079c62f868eb Filled in some stubs to flesh out the AST API.
Ryan C. Gordon <icculus@icculus.org>
parents: 931
diff changeset
   176
    va_start(ap, fmt);
939
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   177
    errorlist_add_va(ctx->errors, ctx->sourcefile, ctx->sourceline, fmt, ap);
932
079c62f868eb Filled in some stubs to flesh out the AST API.
Ryan C. Gordon <icculus@icculus.org>
parents: 931
diff changeset
   178
    va_end(ap);
079c62f868eb Filled in some stubs to flesh out the AST API.
Ryan C. Gordon <icculus@icculus.org>
parents: 931
diff changeset
   179
} // failf
079c62f868eb Filled in some stubs to flesh out the AST API.
Ryan C. Gordon <icculus@icculus.org>
parents: 931
diff changeset
   180
079c62f868eb Filled in some stubs to flesh out the AST API.
Ryan C. Gordon <icculus@icculus.org>
parents: 931
diff changeset
   181
static inline void fail(Context *ctx, const char *reason)
079c62f868eb Filled in some stubs to flesh out the AST API.
Ryan C. Gordon <icculus@icculus.org>
parents: 931
diff changeset
   182
{
079c62f868eb Filled in some stubs to flesh out the AST API.
Ryan C. Gordon <icculus@icculus.org>
parents: 931
diff changeset
   183
    failf(ctx, "%s", reason);
842
1ea7f51250fb A little work on error handling in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 839
diff changeset
   184
} // fail
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   185
939
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   186
static void warnf(Context *ctx, const char *fmt, ...) ISPRINTF(2,3);
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   187
static void warnf(Context *ctx, const char *fmt, ...)
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   188
{
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   189
    if (ctx->out_of_memory)
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   190
        return;
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   191
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   192
    va_list ap;
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   193
    va_start(ap, fmt);
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   194
    errorlist_add_va(ctx->warnings, ctx->sourcefile, ctx->sourceline, fmt, ap);
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   195
    va_end(ap);
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   196
} // warnf
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   197
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   198
static inline void warn(Context *ctx, const char *reason)
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   199
{
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   200
    warnf(ctx, "%s", reason);
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   201
} // warn
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   202
932
079c62f868eb Filled in some stubs to flesh out the AST API.
Ryan C. Gordon <icculus@icculus.org>
parents: 931
diff changeset
   203
static inline int isfail(const Context *ctx)
079c62f868eb Filled in some stubs to flesh out the AST API.
Ryan C. Gordon <icculus@icculus.org>
parents: 931
diff changeset
   204
{
079c62f868eb Filled in some stubs to flesh out the AST API.
Ryan C. Gordon <icculus@icculus.org>
parents: 931
diff changeset
   205
    return ctx->isfail;
079c62f868eb Filled in some stubs to flesh out the AST API.
Ryan C. Gordon <icculus@icculus.org>
parents: 931
diff changeset
   206
} // isfail
079c62f868eb Filled in some stubs to flesh out the AST API.
Ryan C. Gordon <icculus@icculus.org>
parents: 931
diff changeset
   207
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   208
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   209
static void symbolmap_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
   210
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   211
static int create_symbolmap(Context *ctx, SymbolMap *map)
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   212
{
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   213
    // !!! FIXME: should compare string pointer, with string in cache.
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   214
    map->scope = NULL;
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   215
    map->hash = hash_create(ctx, hash_hash_string, hash_keymatch_string,
939
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   216
                            symbolmap_nuke, 1, MallocBridge, FreeBridge, ctx);
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   217
    return (map->hash != NULL);
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   218
} // create_symbolmap
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   219
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   220
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   221
static void push_symbol(Context *ctx, SymbolMap *map,
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   222
                        const char *sym, const char *datatype)
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   223
{
929
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   224
    // !!! FIXME: decide if this symbol is defined, and if so, if it's in
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   225
    // !!! FIXME:  the current scope.
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   226
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   227
    SymbolScope *item = (SymbolScope *) Malloc(ctx, sizeof (SymbolScope));
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   228
    if (item == NULL)
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   229
        return;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   230
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   231
    if (sym != NULL)
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   232
    {
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   233
        if (hash_insert(map->hash, sym, datatype) == -1)
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   234
        {
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   235
            Free(ctx, item);
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   236
            return;
929
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   237
        } // if
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   238
    } // if
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   239
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   240
    item->symbol = sym;  // cached strings, don't copy.
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   241
    item->datatype = datatype;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   242
    item->next = map->scope;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   243
    map->scope = item;
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   244
} // push_symbol
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   245
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   246
static inline void push_usertype(Context *ctx, const char *sym, const char *dt)
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   247
{
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   248
    push_symbol(ctx, &ctx->usertypes, sym, dt);
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   249
} // push_usertype
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   250
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   251
static inline void push_variable(Context *ctx, const char *sym, const char *dt)
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   252
{
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   253
    push_symbol(ctx, &ctx->variables, sym, dt);
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   254
} // push_variable
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   255
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   256
static inline void push_scope(Context *ctx)
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   257
{
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   258
    push_usertype(ctx, NULL, NULL);
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   259
    push_variable(ctx, NULL, NULL);
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   260
} // push_scope
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   261
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   262
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   263
static void pop_symbol(Context *ctx, SymbolMap *map)
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   264
{
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   265
    SymbolScope *item = map->scope;
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   266
    if (!item)
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   267
        return;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   268
    if (item->symbol)
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   269
        hash_remove(map->hash, item->symbol);
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   270
    map->scope = item->next;
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   271
    Free(ctx, item);
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   272
} // pop_symbol
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   273
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   274
static void pop_symbol_scope(Context *ctx, SymbolMap *map)
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   275
{
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   276
    while ((map->scope) && (map->scope->symbol))
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   277
        pop_symbol(ctx, map);
850
473108b0366d Fixed pop_scope().
Ryan C. Gordon <icculus@icculus.org>
parents: 849
diff changeset
   278
473108b0366d Fixed pop_scope().
Ryan C. Gordon <icculus@icculus.org>
parents: 849
diff changeset
   279
    assert(map->scope != NULL);
473108b0366d Fixed pop_scope().
Ryan C. Gordon <icculus@icculus.org>
parents: 849
diff changeset
   280
    assert(map->scope->symbol == NULL);
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   281
    pop_symbol(ctx, map);
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   282
} // pop_symbol_scope
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   283
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   284
static inline void pop_scope(Context *ctx)
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   285
{
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   286
    pop_symbol_scope(ctx, &ctx->usertypes);
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   287
    pop_symbol_scope(ctx, &ctx->variables);
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   288
} // push_scope
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   289
929
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   290
static const char *find_symbol(Context *ctx, SymbolMap *map, const char *sym)
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   291
{
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   292
    const void *value = NULL;
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   293
    hash_find(map->hash, sym, &value);
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   294
    return (const char *) value;
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   295
} // find_symbol
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   296
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   297
static inline const char *find_usertype(Context *ctx, const char *sym)
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   298
{
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   299
    return find_symbol(ctx, &ctx->usertypes, sym);
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   300
} // find_usertype
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   301
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   302
static inline const char *find_variable(Context *ctx, const char *sym)
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   303
{
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   304
    return find_symbol(ctx, &ctx->variables, sym);
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   305
} // find_variable
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   306
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   307
static void destroy_symbolmap(Context *ctx, SymbolMap *map)
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   308
{
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   309
    while (map->scope)
937
94e50ba3f956 Workaround for failing parse for now.
Ryan C. Gordon <icculus@icculus.org>
parents: 936
diff changeset
   310
        pop_symbol(ctx, map);
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   311
    hash_destroy(map->hash);
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 921
diff changeset
   312
} // destroy_symbolmap
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   313
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   314
940
bc2a5efade5e Added a bunch of FIXMEs to accurately portray current technical debt.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   315
// !!! FIXME: move this to to mojoshader_ast.c
bc2a5efade5e Added a bunch of FIXMEs to accurately portray current technical debt.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   316
// !!! FIXME: new_* and delete_* should take an allocator, not a context.
bc2a5efade5e Added a bunch of FIXMEs to accurately portray current technical debt.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   317
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   318
// 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
   319
//  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
   320
//  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
   321
//  afterwards.
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   322
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
   323
#define NEW_AST_NODE(retval, cls, typ) \
883
df6265a993bc Fixed C++ compiler error.
Ryan C. Gordon <icculus@icculus.org>
parents: 868
diff changeset
   324
    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
   325
    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
   326
        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
   327
        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
   328
        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
   329
        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
   330
    } while (0)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   331
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
   332
#define DELETE_AST_NODE(cls) do { \
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   333
    if (!cls) return; \
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   334
} while (0)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   335
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   336
static void delete_compilation_unit(Context*, MOJOSHADER_astCompilationUnit*);
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   337
static void delete_statement(Context *ctx, MOJOSHADER_astStatement *stmt);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   338
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   339
static MOJOSHADER_astExpression *new_callfunc_expr(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   340
                                        MOJOSHADER_astExpression *identifier,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   341
                                        MOJOSHADER_astArguments *args)
927
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   342
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   343
    NEW_AST_NODE(retval, MOJOSHADER_astExpressionCallFunction,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   344
                 MOJOSHADER_AST_OP_CALLFUNC);
927
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   345
    retval->identifier = identifier;
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   346
    retval->args = args;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   347
    return (MOJOSHADER_astExpression *) retval;
927
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   348
} // new_callfunc_expr
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   349
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   350
static MOJOSHADER_astExpression *new_constructor_expr(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   351
                                                const char *datatype,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   352
                                                MOJOSHADER_astArguments *args)
837
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   353
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   354
    NEW_AST_NODE(retval, MOJOSHADER_astExpressionConstructor,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   355
                 MOJOSHADER_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
   356
    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
   357
    retval->args = args;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   358
    return (MOJOSHADER_astExpression *) retval;
837
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   359
} // 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
   360
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   361
static MOJOSHADER_astExpression *new_cast_expr(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   362
                                            const char *datatype,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   363
                                            MOJOSHADER_astExpression *operand)
837
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   364
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   365
    NEW_AST_NODE(retval, MOJOSHADER_astExpressionCast, MOJOSHADER_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
   366
    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
   367
    retval->operand = operand;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   368
    return (MOJOSHADER_astExpression *) retval;
837
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   369
} // 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
   370
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   371
static MOJOSHADER_astExpression *new_unary_expr(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   372
                                            const MOJOSHADER_astNodeType op,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   373
                                            MOJOSHADER_astExpression *operand)
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   374
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   375
    NEW_AST_NODE(retval, MOJOSHADER_astExpressionUnary, op);
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   376
    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
   377
    retval->operand = operand;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   378
    return (MOJOSHADER_astExpression *) retval;
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   379
} // new_unary_expr
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   380
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   381
static MOJOSHADER_astExpression *new_binary_expr(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   382
                                            const MOJOSHADER_astNodeType op,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   383
                                            MOJOSHADER_astExpression *left,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   384
                                            MOJOSHADER_astExpression *right)
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   385
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   386
    NEW_AST_NODE(retval, MOJOSHADER_astExpressionBinary, op);
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   387
    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
   388
    retval->left = left;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   389
    retval->right = right;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   390
    return (MOJOSHADER_astExpression *) retval;
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   391
} // new_binary_expr
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   392
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   393
static MOJOSHADER_astExpression *new_ternary_expr(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   394
                                            const MOJOSHADER_astNodeType op,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   395
                                            MOJOSHADER_astExpression *left,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   396
                                            MOJOSHADER_astExpression *center,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   397
                                            MOJOSHADER_astExpression *right)
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   398
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   399
    NEW_AST_NODE(retval, MOJOSHADER_astExpressionTernary, op);
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   400
    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
   401
    retval->left = left;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   402
    retval->center = center;
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   403
    retval->right = right;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   404
    return (MOJOSHADER_astExpression *) retval;
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   405
} // new_ternary_expr
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   406
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   407
static MOJOSHADER_astExpression *new_deref_struct_expr(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   408
                                        MOJOSHADER_astExpression *identifier,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   409
                                        const char *member)
928
c9b0235e9d23 Made struct dereference a separate expression type, not a binary expression.
Ryan C. Gordon <icculus@icculus.org>
parents: 927
diff changeset
   410
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   411
    NEW_AST_NODE(retval, MOJOSHADER_astExpressionDerefStruct,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   412
                 MOJOSHADER_AST_OP_DEREF_STRUCT);
928
c9b0235e9d23 Made struct dereference a separate expression type, not a binary expression.
Ryan C. Gordon <icculus@icculus.org>
parents: 927
diff changeset
   413
    retval->identifier = identifier;
c9b0235e9d23 Made struct dereference a separate expression type, not a binary expression.
Ryan C. Gordon <icculus@icculus.org>
parents: 927
diff changeset
   414
    retval->member = member;  // cached; don't copy string.
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   415
    return (MOJOSHADER_astExpression *) retval;
928
c9b0235e9d23 Made struct dereference a separate expression type, not a binary expression.
Ryan C. Gordon <icculus@icculus.org>
parents: 927
diff changeset
   416
} // new_deref_struct_expr
c9b0235e9d23 Made struct dereference a separate expression type, not a binary expression.
Ryan C. Gordon <icculus@icculus.org>
parents: 927
diff changeset
   417
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   418
static MOJOSHADER_astExpression *new_identifier_expr(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   419
                                                     const char *string)
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   420
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   421
    NEW_AST_NODE(retval, MOJOSHADER_astExpressionIdentifier,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   422
                 MOJOSHADER_AST_OP_IDENTIFIER);
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   423
    retval->identifier = string;  // cached; don't copy string.
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   424
    return (MOJOSHADER_astExpression *) retval;
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   425
} // new_identifier_expr
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   426
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   427
static MOJOSHADER_astExpression *new_literal_int_expr(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   428
                                                       const int value)
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   429
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   430
    NEW_AST_NODE(retval, MOJOSHADER_astExpressionIntLiteral,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   431
                 MOJOSHADER_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
   432
    retval->value = value;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   433
    return (MOJOSHADER_astExpression *) retval;
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   434
} // new_literal_int_expr
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   435
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   436
static MOJOSHADER_astExpression *new_literal_float_expr(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   437
                                                        const double dbl)
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   438
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   439
    NEW_AST_NODE(retval, MOJOSHADER_astExpressionFloatLiteral,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   440
                 MOJOSHADER_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
   441
    retval->value = dbl;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   442
    return (MOJOSHADER_astExpression *) retval;
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   443
} // new_literal_float_expr
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   444
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   445
static MOJOSHADER_astExpression *new_literal_string_expr(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   446
                                                         const char *string)
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   447
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   448
    NEW_AST_NODE(retval, MOJOSHADER_astExpressionStringLiteral,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   449
                 MOJOSHADER_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
   450
    retval->string = string;  // cached; don't copy string.
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   451
    return (MOJOSHADER_astExpression *) retval;
924
c99418745e1b Added boolean literals to parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 923
diff changeset
   452
} // new_literal_string_expr
c99418745e1b Added boolean literals to parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 923
diff changeset
   453
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   454
static MOJOSHADER_astExpression *new_literal_boolean_expr(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   455
                                                          const int value)
924
c99418745e1b Added boolean literals to parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 923
diff changeset
   456
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   457
    NEW_AST_NODE(retval, MOJOSHADER_astExpressionBooleanLiteral,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   458
                 MOJOSHADER_AST_OP_BOOLEAN_LITERAL);
924
c99418745e1b Added boolean literals to parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 923
diff changeset
   459
    retval->value = value;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   460
    return (MOJOSHADER_astExpression *) retval;
924
c99418745e1b Added boolean literals to parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 923
diff changeset
   461
} // new_literal_boolean_expr
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   462
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   463
static void delete_arguments(Context *ctx, MOJOSHADER_astArguments *args);
927
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   464
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   465
static void delete_expr(Context *ctx, MOJOSHADER_astExpression *_expr)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   466
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   467
    MOJOSHADER_astNode *expr = (MOJOSHADER_astNode *) _expr;
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   468
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   469
    DELETE_AST_NODE(expr);
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   470
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   471
    if (expr->ast.type == MOJOSHADER_AST_OP_CAST)
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   472
        delete_expr(ctx, expr->cast.operand);
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   473
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   474
    else if (expr->ast.type == MOJOSHADER_AST_OP_CONSTRUCTOR)
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   475
        delete_arguments(ctx, expr->constructor.args);
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   476
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   477
    else if (expr->ast.type == MOJOSHADER_AST_OP_DEREF_STRUCT)
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   478
        delete_expr(ctx, expr->derefstruct.identifier);
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   479
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   480
    else if (operator_is_unary(expr->ast.type))
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   481
        delete_expr(ctx, expr->unary.operand);
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   482
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
   483
    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
   484
    {
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   485
        delete_expr(ctx, expr->binary.left);
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   486
        delete_expr(ctx, expr->binary.right);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   487
    } // else if
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   488
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
   489
    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
   490
    {
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   491
        delete_expr(ctx, expr->ternary.left);
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   492
        delete_expr(ctx, expr->ternary.center);
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   493
        delete_expr(ctx, expr->ternary.right);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   494
    } // else if
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   495
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   496
    else if (expr->ast.type == MOJOSHADER_AST_OP_CALLFUNC)
837
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   497
    {
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   498
        delete_expr(ctx, expr->callfunc.identifier);
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   499
        delete_arguments(ctx, expr->callfunc.args);
837
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   500
    } // else if
845
d10d31b9b695 Removed incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 844
diff changeset
   501
d10d31b9b695 Removed incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 844
diff changeset
   502
    // rest of operators don't have extra data to free.
d10d31b9b695 Removed incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents: 844
diff changeset
   503
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   504
    Free(ctx, expr);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   505
} // delete_expr
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   506
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   507
static MOJOSHADER_astArguments *new_argument(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   508
                                             MOJOSHADER_astExpression *arg)
927
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   509
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   510
    NEW_AST_NODE(retval, MOJOSHADER_astArguments, MOJOSHADER_AST_ARGUMENTS);
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   511
    retval->argument = arg;
927
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   512
    retval->next = NULL;
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   513
    return retval;
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   514
} // new_argument
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   515
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   516
static void delete_arguments(Context *ctx, MOJOSHADER_astArguments *args)
927
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   517
{
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   518
    DELETE_AST_NODE(args);
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   519
    delete_arguments(ctx, args->next);
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   520
    delete_expr(ctx, args->argument);
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   521
    Free(ctx, args);
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   522
} // delete_arguments
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   523
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   524
static MOJOSHADER_astFunctionParameters *new_function_param(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   525
                        const MOJOSHADER_astInputModifier inputmod,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   526
                        const char *datatype, const char *identifier,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   527
                        const char *semantic,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   528
                        const MOJOSHADER_astInterpolationModifier interpmod,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   529
                        MOJOSHADER_astExpression *initializer)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   530
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   531
    NEW_AST_NODE(retval, MOJOSHADER_astFunctionParameters,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   532
                 MOJOSHADER_AST_FUNCTION_PARAMS);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   533
    retval->input_modifier = inputmod;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   534
    retval->datatype = datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   535
    retval->identifier = identifier;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   536
    retval->semantic = semantic;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   537
    retval->interpolation_modifier = interpmod;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   538
    retval->initializer = initializer;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   539
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   540
    return retval;
926
8ac335735b37 Renamed function "arguments" to function "parameters" in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 925
diff changeset
   541
} // new_function_param
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   542
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   543
static void delete_function_params(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   544
                                   MOJOSHADER_astFunctionParameters *params)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   545
{
926
8ac335735b37 Renamed function "arguments" to function "parameters" in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 925
diff changeset
   546
    DELETE_AST_NODE(params);
8ac335735b37 Renamed function "arguments" to function "parameters" in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 925
diff changeset
   547
    delete_function_params(ctx, params->next);
8ac335735b37 Renamed function "arguments" to function "parameters" in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 925
diff changeset
   548
    delete_expr(ctx, params->initializer);
8ac335735b37 Renamed function "arguments" to function "parameters" in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 925
diff changeset
   549
    Free(ctx, params);
8ac335735b37 Renamed function "arguments" to function "parameters" in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 925
diff changeset
   550
} // delete_function_params
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   551
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   552
static MOJOSHADER_astFunctionSignature *new_function_signature(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   553
                                    const char *datatype,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   554
                                    const char *identifier,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   555
                                    MOJOSHADER_astFunctionParameters *params)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   556
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   557
    NEW_AST_NODE(retval, MOJOSHADER_astFunctionSignature,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   558
                 MOJOSHADER_AST_FUNCTION_SIGNATURE);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   559
    retval->datatype = datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   560
    retval->identifier = identifier;
926
8ac335735b37 Renamed function "arguments" to function "parameters" in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 925
diff changeset
   561
    retval->params = params;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   562
    retval->storage_class = MOJOSHADER_AST_FNSTORECLS_NONE;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   563
    retval->semantic = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   564
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   565
} // new_function_signature
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   566
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   567
static void delete_function_signature(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   568
                                      MOJOSHADER_astFunctionSignature *sig)
836
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
    DELETE_AST_NODE(sig);
926
8ac335735b37 Renamed function "arguments" to function "parameters" in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 925
diff changeset
   571
    delete_function_params(ctx, sig->params);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   572
    Free(ctx, sig);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   573
} // delete_function_signature
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   574
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   575
static MOJOSHADER_astCompilationUnit *new_function(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   576
                                MOJOSHADER_astFunctionSignature *declaration,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   577
                                MOJOSHADER_astStatement *definition)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   578
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   579
    NEW_AST_NODE(retval, MOJOSHADER_astCompilationUnitFunction,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   580
                 MOJOSHADER_AST_COMPUNIT_FUNCTION);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   581
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   582
    retval->declaration = declaration;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   583
    retval->definition = definition;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   584
    return (MOJOSHADER_astCompilationUnit *) retval;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   585
} // new_function
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   586
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   587
static void delete_function(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   588
                            MOJOSHADER_astCompilationUnitFunction *unitfn)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   589
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   590
    DELETE_AST_NODE(unitfn);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   591
    delete_compilation_unit(ctx, unitfn->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   592
    delete_function_signature(ctx, unitfn->declaration);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   593
    delete_statement(ctx, unitfn->definition);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   594
    Free(ctx, unitfn);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   595
} // delete_function
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   596
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   597
static MOJOSHADER_astScalarOrArray *new_scalar_or_array(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   598
                                          const char *ident, const int isvec,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   599
                                          MOJOSHADER_astExpression *dim)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   600
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   601
    NEW_AST_NODE(retval, MOJOSHADER_astScalarOrArray,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   602
                 MOJOSHADER_AST_SCALAR_OR_ARRAY);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   603
    retval->identifier = ident;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   604
    retval->isarray = isvec;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   605
    retval->dimension = dim;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   606
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   607
} // new_scalar_or_array
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   608
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   609
static void delete_scalar_or_array(Context *ctx,MOJOSHADER_astScalarOrArray *s)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   610
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   611
    DELETE_AST_NODE(s);
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   612
    delete_expr(ctx, s->dimension);
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   613
    Free(ctx, s);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   614
} // delete_scalar_or_array
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   615
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   616
static MOJOSHADER_astTypedef *new_typedef(Context *ctx, const int isconst,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   617
                                          const char *datatype,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   618
                                          MOJOSHADER_astScalarOrArray *soa)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   619
{
929
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   620
    // we correct this datatype to the final string during semantic analysis.
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   621
    NEW_AST_NODE(retval, MOJOSHADER_astTypedef, MOJOSHADER_AST_TYPEDEF);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   622
    retval->isconst = isconst;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   623
    retval->datatype = datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   624
    retval->details = soa;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   625
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   626
} // new_typedef
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   627
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   628
static void delete_typedef(Context *ctx, MOJOSHADER_astTypedef *td)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   629
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   630
    DELETE_AST_NODE(td);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   631
    delete_scalar_or_array(ctx, td->details);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   632
    Free(ctx, td);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   633
} // delete_typedef
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   634
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   635
static MOJOSHADER_astPackOffset *new_pack_offset(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   636
                                                 const char *a, const char *b)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   637
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   638
    NEW_AST_NODE(retval, MOJOSHADER_astPackOffset, MOJOSHADER_AST_PACK_OFFSET);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   639
    retval->ident1 = a;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   640
    retval->ident2 = b;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   641
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   642
} // new_pack_offset
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   643
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   644
static void delete_pack_offset(Context *ctx, MOJOSHADER_astPackOffset *o)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   645
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   646
    DELETE_AST_NODE(o);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   647
    Free(ctx, o);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   648
} // delete_pack_offset
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   649
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   650
static MOJOSHADER_astVariableLowLevel *new_variable_lowlevel(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   651
                                               MOJOSHADER_astPackOffset *po,
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   652
                                               const char *reg)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   653
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   654
    NEW_AST_NODE(retval, MOJOSHADER_astVariableLowLevel,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   655
                 MOJOSHADER_AST_VARIABLE_LOWLEVEL);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   656
    retval->packoffset = po;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   657
    retval->register_name = reg;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   658
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   659
} // new_variable_lowlevel
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   660
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   661
static void delete_variable_lowlevel(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   662
                                     MOJOSHADER_astVariableLowLevel *vll)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   663
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   664
    DELETE_AST_NODE(vll);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   665
    delete_pack_offset(ctx, vll->packoffset);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   666
    Free(ctx, vll);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   667
} // delete_variable_lowlevel
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   668
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   669
static MOJOSHADER_astAnnotations *new_annotation(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   670
                                        const char *datatype,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   671
                                        MOJOSHADER_astExpression *initializer)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   672
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   673
    NEW_AST_NODE(retval, MOJOSHADER_astAnnotations, MOJOSHADER_AST_ANNOTATION);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   674
    retval->datatype = datatype;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   675
    retval->initializer = initializer;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   676
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   677
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   678
} // new_annotation
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   679
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   680
static void delete_annotation(Context *ctx, MOJOSHADER_astAnnotations *annos)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   681
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   682
    DELETE_AST_NODE(annos);
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   683
    delete_annotation(ctx, annos->next);
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   684
    delete_expr(ctx, annos->initializer);
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   685
    Free(ctx, annos);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   686
} // delete_annotation
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   687
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   688
static MOJOSHADER_astVariableDeclaration *new_variable_declaration(
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   689
                            Context *ctx, MOJOSHADER_astScalarOrArray *soa,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   690
                            const char *semantic,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   691
                            MOJOSHADER_astAnnotations *annotations,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   692
                            MOJOSHADER_astExpression *init,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   693
                            MOJOSHADER_astVariableLowLevel *vll)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   694
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   695
    NEW_AST_NODE(retval, MOJOSHADER_astVariableDeclaration,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   696
                 MOJOSHADER_AST_VARIABLE_DECLARATION);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   697
    retval->attributes = 0;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   698
    retval->datatype = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   699
    retval->anonymous_datatype = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   700
    retval->details = soa;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   701
    retval->semantic = semantic;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   702
    retval->annotations = annotations;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   703
    retval->initializer = init;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   704
    retval->lowlevel = vll;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   705
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   706
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   707
} // new_variable_declaration
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   708
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   709
static void delete_variable_declaration(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   710
                                        MOJOSHADER_astVariableDeclaration *dcl)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   711
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   712
    DELETE_AST_NODE(dcl);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   713
    delete_variable_declaration(ctx, dcl->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   714
    delete_scalar_or_array(ctx, dcl->details);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   715
    delete_annotation(ctx, dcl->annotations);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   716
    delete_expr(ctx, dcl->initializer);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   717
    delete_variable_lowlevel(ctx, dcl->lowlevel);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   718
    Free(ctx, dcl);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   719
} // delete_variable_declaration
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   720
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   721
static MOJOSHADER_astCompilationUnit *new_global_variable(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   722
                                      MOJOSHADER_astVariableDeclaration *decl)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   723
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   724
    NEW_AST_NODE(retval, MOJOSHADER_astCompilationUnitVariable,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   725
                 MOJOSHADER_AST_COMPUNIT_VARIABLE);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   726
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   727
    retval->declaration = decl;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   728
    return (MOJOSHADER_astCompilationUnit *) retval;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   729
} // new_global_variable
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   730
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   731
static void delete_global_variable(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   732
                                   MOJOSHADER_astCompilationUnitVariable *var)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   733
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   734
    DELETE_AST_NODE(var);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   735
    delete_compilation_unit(ctx, var->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   736
    delete_variable_declaration(ctx, var->declaration);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   737
    Free(ctx, var);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   738
} // delete_global_variable
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   739
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   740
static MOJOSHADER_astCompilationUnit *new_global_typedef(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   741
                                                     MOJOSHADER_astTypedef *td)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   742
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   743
    NEW_AST_NODE(retval, MOJOSHADER_astCompilationUnitTypedef,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   744
                 MOJOSHADER_AST_COMPUNIT_TYPEDEF);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   745
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   746
    retval->type_info = td;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   747
    return (MOJOSHADER_astCompilationUnit *) retval;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   748
} // new_global_typedef
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   749
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   750
static void delete_global_typedef(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   751
                                  MOJOSHADER_astCompilationUnitTypedef *unit)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   752
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   753
    DELETE_AST_NODE(unit);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   754
    delete_compilation_unit(ctx, unit->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   755
    delete_typedef(ctx, unit->type_info);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   756
    Free(ctx, unit);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   757
} // delete_global_typedef
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   758
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   759
static MOJOSHADER_astStructMembers *new_struct_member(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   760
                                            MOJOSHADER_astScalarOrArray *soa,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   761
                                            const char *semantic)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   762
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   763
    NEW_AST_NODE(retval, MOJOSHADER_astStructMembers,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   764
                 MOJOSHADER_AST_STRUCT_MEMBER);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   765
    retval->datatype = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   766
    retval->semantic = semantic;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   767
    retval->details = soa;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   768
    retval->interpolation_mod = MOJOSHADER_AST_INTERPMOD_NONE;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   769
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   770
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   771
} // new_struct_member
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   772
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   773
static void delete_struct_member(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   774
                                 MOJOSHADER_astStructMembers *member)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   775
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   776
    DELETE_AST_NODE(member);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   777
    delete_struct_member(ctx, member->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   778
    delete_scalar_or_array(ctx, member->details);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   779
    Free(ctx, member);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   780
} // delete_struct_member
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   781
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   782
static MOJOSHADER_astStructDeclaration *new_struct_declaration(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   783
                                        const char *name,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   784
                                        MOJOSHADER_astStructMembers *members)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   785
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   786
    NEW_AST_NODE(retval, MOJOSHADER_astStructDeclaration,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   787
                 MOJOSHADER_AST_STRUCT_DECLARATION);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   788
    retval->name = name;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   789
    retval->members = members;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   790
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   791
} // new_struct_declaration
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   792
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   793
static void delete_struct_declaration(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   794
                                      MOJOSHADER_astStructDeclaration *decl)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   795
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   796
    DELETE_AST_NODE(decl);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   797
    delete_struct_member(ctx, decl->members);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   798
    Free(ctx, decl);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   799
} // delete_struct_declaration
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   800
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   801
static MOJOSHADER_astCompilationUnit *new_global_struct(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   802
                                           MOJOSHADER_astStructDeclaration *sd)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   803
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   804
    NEW_AST_NODE(retval, MOJOSHADER_astCompilationUnitStruct,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   805
                 MOJOSHADER_AST_COMPUNIT_STRUCT);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   806
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   807
    retval->struct_info = sd;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   808
    return (MOJOSHADER_astCompilationUnit *) retval;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   809
} // new_global_struct
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   810
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   811
static void delete_global_struct(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   812
                                 MOJOSHADER_astCompilationUnitStruct *unit)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   813
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   814
    DELETE_AST_NODE(unit);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   815
    delete_compilation_unit(ctx, unit->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   816
    delete_struct_declaration(ctx, unit->struct_info);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   817
    Free(ctx, unit);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   818
} // delete_global_struct
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   819
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   820
static void delete_compilation_unit(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   821
                                    MOJOSHADER_astCompilationUnit *unit)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   822
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   823
    if (!unit) return;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   824
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   825
    // 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
   826
    //  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
   827
    //  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
   828
    //  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
   829
    //  to recurse in their own delete methods.
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   830
    // 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
   831
    //  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
   832
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   833
    MOJOSHADER_astCompilationUnit *i = unit->next;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   834
    unit->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   835
    while (i)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   836
    {
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   837
        MOJOSHADER_astCompilationUnit *next = i->next;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   838
        i->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   839
        delete_compilation_unit(ctx, i);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   840
        i = next;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   841
    } // while
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   842
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
   843
    switch (unit->ast.type)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   844
    {
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   845
        #define DELETE_UNIT(typ, cls, fn) \
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   846
            case MOJOSHADER_AST_COMPUNIT_##typ: delete_##fn(ctx, (cls *) unit); break;
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   847
        DELETE_UNIT(FUNCTION, MOJOSHADER_astCompilationUnitFunction, function);
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   848
        DELETE_UNIT(TYPEDEF, MOJOSHADER_astCompilationUnitTypedef, global_typedef);
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   849
        DELETE_UNIT(VARIABLE, MOJOSHADER_astCompilationUnitVariable, global_variable);
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   850
        DELETE_UNIT(STRUCT, MOJOSHADER_astCompilationUnitStruct, global_struct);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   851
        #undef DELETE_UNIT
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   852
        default: assert(0 && "missing cleanup code"); break;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   853
    } // switch
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   854
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   855
    // don't free (unit) here, the class-specific functions do it.
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   856
} // delete_compilation_unit
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   857
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   858
static MOJOSHADER_astStatement *new_typedef_statement(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   859
                                                      MOJOSHADER_astTypedef *td)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   860
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   861
    NEW_AST_NODE(retval, MOJOSHADER_astTypedefStatement,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   862
                 MOJOSHADER_AST_STATEMENT_TYPEDEF);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   863
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   864
    retval->type_info = td;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   865
    return (MOJOSHADER_astStatement *) retval;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   866
} // new_typedef_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   867
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   868
static void delete_typedef_statement(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   869
                                     MOJOSHADER_astTypedefStatement *stmt)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   870
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   871
    DELETE_AST_NODE(stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   872
    delete_statement(ctx, stmt->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   873
    delete_typedef(ctx, stmt->type_info);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   874
    Free(ctx, stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   875
} // delete_typedef_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   876
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   877
static MOJOSHADER_astStatement *new_return_statement(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   878
                                                MOJOSHADER_astExpression *expr)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   879
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   880
    NEW_AST_NODE(retval, MOJOSHADER_astReturnStatement,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   881
                 MOJOSHADER_AST_STATEMENT_RETURN);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   882
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   883
    retval->expr = expr;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   884
    return (MOJOSHADER_astStatement *) retval;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   885
} // new_return_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   886
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   887
static void delete_return_statement(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   888
                                    MOJOSHADER_astReturnStatement *stmt)
836
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
    DELETE_AST_NODE(stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   891
    delete_statement(ctx, stmt->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   892
    delete_expr(ctx, stmt->expr);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   893
    Free(ctx, stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   894
} // delete_return_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   895
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   896
static MOJOSHADER_astStatement *new_block_statement(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   897
                                               MOJOSHADER_astStatement *stmts)
917
85afb474f99d Make statement blocks explicit in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 916
diff changeset
   898
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   899
    NEW_AST_NODE(retval, MOJOSHADER_astBlockStatement,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   900
                 MOJOSHADER_AST_STATEMENT_BLOCK);
917
85afb474f99d Make statement blocks explicit in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 916
diff changeset
   901
    retval->next = NULL;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   902
    retval->statements = stmts;
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   903
    return (MOJOSHADER_astStatement *) retval;
917
85afb474f99d Make statement blocks explicit in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 916
diff changeset
   904
} // new_block_statement
85afb474f99d Make statement blocks explicit in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 916
diff changeset
   905
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   906
static void delete_block_statement(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   907
                                   MOJOSHADER_astBlockStatement *stmt)
917
85afb474f99d Make statement blocks explicit in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 916
diff changeset
   908
{
85afb474f99d Make statement blocks explicit in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 916
diff changeset
   909
    DELETE_AST_NODE(stmt);
85afb474f99d Make statement blocks explicit in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 916
diff changeset
   910
    delete_statement(ctx, stmt->statements);
85afb474f99d Make statement blocks explicit in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 916
diff changeset
   911
    delete_statement(ctx, stmt->next);
85afb474f99d Make statement blocks explicit in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 916
diff changeset
   912
    Free(ctx, stmt);
85afb474f99d Make statement blocks explicit in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 916
diff changeset
   913
} // delete_statement_block
85afb474f99d Make statement blocks explicit in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 916
diff changeset
   914
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   915
static MOJOSHADER_astStatement *new_for_statement(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   916
                                    MOJOSHADER_astVariableDeclaration *decl,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   917
                                    MOJOSHADER_astExpression *initializer,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   918
                                    MOJOSHADER_astExpression *looptest,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   919
                                    MOJOSHADER_astExpression *counter,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   920
                                    MOJOSHADER_astStatement *statement)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   921
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   922
    NEW_AST_NODE(retval, MOJOSHADER_astForStatement,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   923
                 MOJOSHADER_AST_STATEMENT_FOR);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   924
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   925
    retval->unroll = -1;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   926
    retval->var_decl = decl;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   927
    retval->initializer = initializer;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   928
    retval->looptest = looptest;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   929
    retval->counter = counter;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   930
    retval->statement = statement;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   931
    return (MOJOSHADER_astStatement *) retval;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   932
} // new_for_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   933
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   934
static void delete_for_statement(Context *ctx,MOJOSHADER_astForStatement *stmt)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   935
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   936
    DELETE_AST_NODE(stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   937
    delete_statement(ctx, stmt->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   938
    delete_variable_declaration(ctx, stmt->var_decl);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   939
    delete_expr(ctx, stmt->initializer);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   940
    delete_expr(ctx, stmt->looptest);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   941
    delete_expr(ctx, stmt->counter);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   942
    delete_statement(ctx, stmt->statement);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   943
    Free(ctx, stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   944
} // delete_for_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   945
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   946
static MOJOSHADER_astStatement *new_do_statement(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   947
                                                const int unroll,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   948
                                                MOJOSHADER_astStatement *stmt,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   949
                                                MOJOSHADER_astExpression *expr)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   950
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   951
    NEW_AST_NODE(retval,MOJOSHADER_astDoStatement,MOJOSHADER_AST_STATEMENT_DO);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   952
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   953
    retval->unroll = unroll;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   954
    retval->expr = expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   955
    retval->statement = stmt;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   956
    return (MOJOSHADER_astStatement *) retval;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   957
} // new_do_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   958
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   959
static void delete_do_statement(Context *ctx, MOJOSHADER_astDoStatement *stmt)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   960
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   961
    DELETE_AST_NODE(stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   962
    delete_statement(ctx, stmt->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   963
    delete_statement(ctx, stmt->statement);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   964
    delete_expr(ctx, stmt->expr);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   965
    Free(ctx, stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   966
} // delete_do_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   967
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   968
static MOJOSHADER_astStatement *new_while_statement(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   969
                                                const int unroll,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   970
                                                MOJOSHADER_astExpression *expr,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   971
                                                MOJOSHADER_astStatement *stmt)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   972
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   973
    NEW_AST_NODE(retval, MOJOSHADER_astWhileStatement,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   974
                 MOJOSHADER_AST_STATEMENT_WHILE);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   975
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   976
    retval->unroll = unroll;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   977
    retval->expr = expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   978
    retval->statement = stmt;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   979
    return (MOJOSHADER_astStatement *) retval;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   980
} // new_while_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   981
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   982
static void delete_while_statement(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   983
                                   MOJOSHADER_astWhileStatement *stmt)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   984
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   985
    DELETE_AST_NODE(stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   986
    delete_statement(ctx, stmt->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   987
    delete_statement(ctx, stmt->statement);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   988
    delete_expr(ctx, stmt->expr);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   989
    Free(ctx, stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   990
} // delete_while_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   991
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   992
static MOJOSHADER_astStatement *new_if_statement(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   993
                                            const int attr,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   994
                                            MOJOSHADER_astExpression *expr,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   995
                                            MOJOSHADER_astStatement *stmt,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   996
                                            MOJOSHADER_astStatement *elsestmt)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   997
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
   998
    NEW_AST_NODE(retval,MOJOSHADER_astIfStatement,MOJOSHADER_AST_STATEMENT_IF);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
   999
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1000
    retval->attributes = attr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1001
    retval->expr = expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1002
    retval->statement = stmt;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1003
    retval->else_statement = elsestmt;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
  1004
    return (MOJOSHADER_astStatement *) retval;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1005
} // new_if_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1006
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
  1007
static void delete_if_statement(Context *ctx, MOJOSHADER_astIfStatement *stmt)
836
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
    DELETE_AST_NODE(stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1010
    delete_statement(ctx, stmt->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1011
    delete_expr(ctx, stmt->expr);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1012
    delete_statement(ctx, stmt->statement);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1013
    delete_statement(ctx, stmt->else_statement);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1014
    Free(ctx, stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1015
} // delete_if_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1016
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
  1017
static MOJOSHADER_astSwitchCases *new_switch_case(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
  1018
                                                MOJOSHADER_astExpression *expr,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
  1019
                                                MOJOSHADER_astStatement *stmt)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1020
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
  1021
    NEW_AST_NODE(retval, MOJOSHADER_astSwitchCases, MOJOSHADER_AST_SWITCH_CASE);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1022
    retval->expr = expr;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1023
    retval->statement = stmt;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1024
    retval->next = NULL;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1025
    return retval;
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1026
} // new_switch_case
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1027
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
  1028
static void delete_switch_case(Context *ctx, MOJOSHADER_astSwitchCases *sc)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1029
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1030
    DELETE_AST_NODE(sc);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1031
    delete_switch_case(ctx, sc->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1032
    delete_expr(ctx, sc->expr);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1033
    delete_statement(ctx, sc->statement);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1034
    Free(ctx, sc);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1035
} // delete_switch_case
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1036
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
  1037
static MOJOSHADER_astStatement *new_empty_statement(Context *ctx)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1038
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
  1039
    NEW_AST_NODE(retval, MOJOSHADER_astEmptyStatement,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
  1040
                 MOJOSHADER_AST_STATEMENT_EMPTY);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1041
    retval->next = NULL;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
  1042
    return (MOJOSHADER_astStatement *) retval;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1043
} // new_empty_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1044
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
  1045
static void delete_empty_statement(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
  1046
                                   MOJOSHADER_astEmptyStatement *stmt)
836
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(stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1049
    delete_statement(ctx, stmt->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1050
    Free(ctx, stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1051
} // delete_empty_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1052
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
  1053
static MOJOSHADER_astStatement *new_break_statement(Context *ctx)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1054
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
  1055
    NEW_AST_NODE(retval, MOJOSHADER_astBreakStatement,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
  1056
                 MOJOSHADER_AST_STATEMENT_BREAK);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1057
    retval->next = NULL;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
  1058
    return (MOJOSHADER_astStatement *) retval;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1059
} // new_break_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1060
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
  1061
static void delete_break_statement(Context *ctx,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
  1062
                                   MOJOSHADER_astBreakStatement *stmt)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1063
{
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1064
    DELETE_AST_NODE(stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1065
    delete_statement(ctx, stmt->next);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1066
    Free(ctx, stmt);
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1067
} // delete_break_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1068
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
  1069
static MOJOSHADER_astStatement *new_continue_statement(Context *ctx)
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1070
{
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
  1071
    NEW_AST_NODE(retval, MOJOSHADER_astContinueStatement,
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
  1072
                 MOJOSHADER_AST_STATEMENT_CONTINUE);
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1073
    retval->next = NULL;
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset
  1074
    return (MOJOSHADER_astStatement *) retval;
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1075
} // new_continue_statement
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 835
diff changeset
  1076
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 930
diff changeset