00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _RM_UTILITIES_HLSLPARSER_H_
00014 #define _RM_UTILITIES_HLSLPARSER_H_
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 class RMUTIL_API IRmUtilHLSLParser
00026 {
00027 public :
00028
00029
00030
00031 enum TokenID
00032 {
00033
00034 TOKEN_END,
00035
00036
00037 TOKEN_NUM_INTEGER,
00038 TOKEN_NUM_FLOAT,
00039
00040
00041 TOKEN_IDENTIFIER,
00042
00043
00044 TOKEN_STRING,
00045
00046
00047 TOKEN_OP_SEMICOLON,
00048 TOKEN_OP_COMMA,
00049 TOKEN_OP_BACKSLASH,
00050 TOKEN_OP_SMALLER,
00051 TOKEN_OP_GREATER,
00052 TOKEN_OP_QUESTION,
00053
00054 TOKEN_OP_MUL,
00055 TOKEN_OP_DIV,
00056 TOKEN_OP_EQUAL,
00057 TOKEN_OP_PLUS,
00058 TOKEN_OP_MINUS,
00059 TOKEN_OP_MULEQUAL,
00060 TOKEN_OP_PLUSEQUAL,
00061 TOKEN_OP_MINUSEQUAL,
00062 TOKEN_OP_DIVEQUAL,
00063
00064 TOKEN_OP_BRACKET_OPEN,
00065 TOKEN_OP_BRACKET_CLOSE,
00066 TOKEN_OP_SQBRACKET_OPEN,
00067 TOKEN_OP_SQBRACKET_CLOSE,
00068 TOKEN_OP_CURLYBRACKET_OPEN,
00069 TOKEN_OP_CURLYBRACKET_CLOSE,
00070
00071 TOKEN_OP_QUATATION,
00072 TOKEN_OP_COLON,
00073
00074 TOKEN_OP_AND,
00075 TOKEN_OP_ANDAND,
00076
00077 TOKEN_OP_SHIFTLEFT,
00078 TOKEN_OP_SHIFTLEFTEQUAL,
00079 TOKEN_OP_SHIFTRIGHT,
00080 TOKEN_OP_SHIFTRIGHTEQUAL,
00081
00082 TOKEN_OP_PERIOD,
00083
00084
00085 TOKEN_KW_IF,
00086 TOKEN_KW_ELSEIF,
00087 TOKEN_KW_ELSE,
00088 TOKEN_KW_FOR,
00089 TOKEN_KW_WHILE,
00090 TOKEN_KW_VOID,
00091 TOKEN_KW_VS,
00092 TOKEN_KW_PS,
00093 TOKEN_KW_RETURN,
00094 TOKEN_KW_STRUCT,
00095
00096
00097 TOKEN_DT_BOOL,
00098 TOKEN_DT_BOOL1,
00099 TOKEN_DT_BOOL2,
00100 TOKEN_DT_BOOL3,
00101 TOKEN_DT_BOOL4,
00102 TOKEN_DT_BOOL1x1,
00103 TOKEN_DT_BOOL1x2,
00104 TOKEN_DT_BOOL1x3,
00105 TOKEN_DT_BOOL1x4,
00106 TOKEN_DT_BOOL2x1,
00107 TOKEN_DT_BOOL2x2,
00108 TOKEN_DT_BOOL2x3,
00109 TOKEN_DT_BOOL2x4,
00110 TOKEN_DT_BOOL3x1,
00111 TOKEN_DT_BOOL3x2,
00112 TOKEN_DT_BOOL3x3,
00113 TOKEN_DT_BOOL3x4,
00114 TOKEN_DT_BOOL4x1,
00115 TOKEN_DT_BOOL4x2,
00116 TOKEN_DT_BOOL4x3,
00117 TOKEN_DT_BOOL4x4,
00118 TOKEN_DT_INT,
00119 TOKEN_DT_INT1,
00120 TOKEN_DT_INT2,
00121 TOKEN_DT_INT3,
00122 TOKEN_DT_INT4,
00123 TOKEN_DT_INT1x1,
00124 TOKEN_DT_INT1x2,
00125 TOKEN_DT_INT1x3,
00126 TOKEN_DT_INT1x4,
00127 TOKEN_DT_INT2x1,
00128 TOKEN_DT_INT2x2,
00129 TOKEN_DT_INT2x3,
00130 TOKEN_DT_INT2x4,
00131 TOKEN_DT_INT3x1,
00132 TOKEN_DT_INT3x2,
00133 TOKEN_DT_INT3x3,
00134 TOKEN_DT_INT3x4,
00135 TOKEN_DT_INT4x1,
00136 TOKEN_DT_INT4x2,
00137 TOKEN_DT_INT4x3,
00138 TOKEN_DT_INT4x4,
00139 TOKEN_DT_FLOAT,
00140 TOKEN_DT_FLOAT1,
00141 TOKEN_DT_FLOAT2,
00142 TOKEN_DT_FLOAT3,
00143 TOKEN_DT_FLOAT4,
00144 TOKEN_DT_FLOAT1x1,
00145 TOKEN_DT_FLOAT1x2,
00146 TOKEN_DT_FLOAT1x3,
00147 TOKEN_DT_FLOAT1x4,
00148 TOKEN_DT_FLOAT2x1,
00149 TOKEN_DT_FLOAT2x2,
00150 TOKEN_DT_FLOAT2x3,
00151 TOKEN_DT_FLOAT2x4,
00152 TOKEN_DT_FLOAT3x1,
00153 TOKEN_DT_FLOAT3x2,
00154 TOKEN_DT_FLOAT3x3,
00155 TOKEN_DT_FLOAT3x4,
00156 TOKEN_DT_FLOAT4x1,
00157 TOKEN_DT_FLOAT4x2,
00158 TOKEN_DT_FLOAT4x3,
00159 TOKEN_DT_FLOAT4x4,
00160 TOKEN_DT_HALF,
00161 TOKEN_DT_HALF1,
00162 TOKEN_DT_HALF2,
00163 TOKEN_DT_HALF3,
00164 TOKEN_DT_HALF4,
00165 TOKEN_DT_HALF1x1,
00166 TOKEN_DT_HALF1x2,
00167 TOKEN_DT_HALF1x3,
00168 TOKEN_DT_HALF1x4,
00169 TOKEN_DT_HALF2x1,
00170 TOKEN_DT_HALF2x2,
00171 TOKEN_DT_HALF2x3,
00172 TOKEN_DT_HALF2x4,
00173 TOKEN_DT_HALF3x1,
00174 TOKEN_DT_HALF3x2,
00175 TOKEN_DT_HALF3x3,
00176 TOKEN_DT_HALF3x4,
00177 TOKEN_DT_HALF4x1,
00178 TOKEN_DT_HALF4x2,
00179 TOKEN_DT_HALF4x3,
00180 TOKEN_DT_HALF4x4,
00181 };
00182
00183
00184
00185
00186 interface IFunction;
00187 interface IStructType;
00188
00189
00190
00191
00192 interface RMUTIL_API IDataType
00193 {
00194
00195 virtual const RmStringT& GetTypeName() const = 0;
00196
00197
00198 virtual TokenID GetTypeID() const = 0;
00199 };
00200
00201
00202
00203
00204 interface RMUTIL_API IVariable
00205 {
00206
00207
00208 virtual int GetLocation() const = 0;
00209
00210
00211 virtual const IDataType* GetDataType() const = 0;
00212
00213
00214 virtual const RmStringT& GetName() const = 0;
00215
00216
00217 virtual IFunction* GetParentFunction() = 0;
00218 virtual const IFunction* GetParentFunction() const = 0;
00219
00220 virtual IStructType* GetParentStruct() = 0;
00221 virtual const IStructType* GetParentStruct() const = 0;
00222
00223
00224 virtual const RmStringT& GetSemantec() const = 0;
00225 };
00226
00227
00228
00229
00230 interface RMUTIL_API IStructType : public IDataType
00231 {
00232
00233 virtual int GetNumMembers() const = 0;
00234
00235
00236 virtual IVariable* GetMember( int index ) = 0;
00237 virtual const IVariable* GetMember( int index ) const = 0;
00238
00239 virtual IVariable* FindMember( const RM_TCHAR *szName ) = 0;
00240 virtual const IVariable* FindMember( const RM_TCHAR *szName ) const = 0;
00241
00242
00243 virtual int GetLocation() const = 0;
00244 };
00245
00246
00247
00248
00249 interface RMUTIL_API IFunction
00250 {
00251
00252
00253 virtual int GetLocation() const = 0;
00254 virtual int GetEndLocation() const = 0;
00255
00256
00257 virtual const RmStringT& GetName() const = 0;
00258
00259
00260 virtual const IDataType* GetReturnType() const = 0;
00261
00262
00263 virtual const RmStringT& GetSemantec() const = 0;
00264
00265
00266 virtual int GetNumParameters() const = 0;
00267 virtual IVariable* GetParameter( int index ) = 0;
00268 virtual const IVariable* GetParameter( int index ) const = 0;
00269
00270 virtual IVariable* FindParameter( const RM_TCHAR *szName ) = 0;
00271 virtual const IVariable* FindParameter( const RM_TCHAR *szName ) const = 0;
00272
00273
00274 virtual int GetNumVariables() const = 0;
00275 virtual IVariable* GetVariable( int index ) = 0;
00276 virtual const IVariable* GetVariable( int index ) const = 0;
00277
00278 virtual IVariable* FindVariable( const RM_TCHAR *szName ) = 0;
00279 virtual const IVariable* FindVariable( const RM_TCHAR *szName ) const = 0;
00280 };
00281
00282
00283
00284
00285 interface RMUTIL_API IToken
00286 {
00287 virtual TokenID GetTokenType() const = 0;
00288
00289 virtual const RmStringT& GetString() const = 0;
00290
00291 virtual int GetInteger() const = 0;
00292 virtual double GetFloat() const = 0;
00293
00294 virtual int GetLocation() const = 0;
00295 virtual int GetTokenPos() const = 0;
00296
00297 virtual bool IsOperator() const = 0;
00298 virtual bool IsKeyword() const = 0;
00299 virtual bool IsIdentifier() const = 0;
00300 virtual bool IsString() const = 0;
00301 virtual bool IsEndToken() const = 0;
00302
00303 virtual bool IsNumber() const = 0;
00304 virtual bool IsInteger() const = 0;
00305 virtual bool IsFloat() const = 0;
00306
00307 virtual bool IsDataType() const = 0;
00308 };
00309
00310 public :
00311
00312
00313
00314 static IRmUtilHLSLParser* CreateHLSLParser();
00315 static void DestroyHLSLParser( IRmUtilHLSLParser* &pParser );
00316
00317
00318
00319
00320 virtual void Parse( const RM_TCHAR *pCode ) = 0;
00321
00322
00323
00324
00325 virtual int GetNumDataTypes() const = 0;
00326 virtual IDataType* GetDataType( int index ) = 0;
00327 virtual const IDataType* GetDataType( int index ) const = 0;
00328
00329 virtual IDataType* FindDataType( const RM_TCHAR *szName ) = 0;
00330 virtual const IDataType* FindDataType( const RM_TCHAR *szName ) const = 0;
00331
00332
00333
00334
00335 virtual int GetNumVariables() const = 0;
00336 virtual IVariable* GetVariable( int index ) = 0;
00337 virtual const IVariable* GetVariable( int index ) const = 0;
00338
00339 virtual IVariable* FindVariable( const RM_TCHAR *szName ) = 0;
00340 virtual const IVariable* FindVariable( const RM_TCHAR *szName ) const = 0;
00341
00342
00343
00344
00345
00346
00347
00348 virtual IVariable* FindVariable( int textLocation, const RM_TCHAR *szName ) = 0;
00349 virtual const IVariable* FindVariable( int textLocation, const RM_TCHAR *szName ) const = 0;
00350
00351
00352
00353
00354 virtual int GetNumFunctions() const = 0;
00355 virtual IFunction* GetFunction( int index ) = 0;
00356 virtual const IFunction* GetFunction( int index ) const = 0;
00357
00358 virtual IFunction* FindFunction( const RM_TCHAR *szName ) = 0;
00359 virtual const IFunction* FindFunction( const RM_TCHAR *szName ) const = 0;
00360
00361
00362 virtual IFunction* IsInsideFunction( int offset ) = 0;
00363 virtual const IFunction* IsInsideFunction( int offset ) const = 0;
00364
00365
00366
00367
00368 virtual void OutputParserResult() = 0;
00369 };
00370
00371
00372 #endif