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