Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

RmUtilHLSLParser.h

00001 //=================================================================================================//
00002 // filename: RmUtilHLSLParser.h                                                                    //
00003 //                                                                                                 //
00004 //           ATI Research, Inc.                                                                    //
00005 //           3D Application Research Group                                                         //
00006 //                                                                                                 //
00007 // Description: declaration file for Parser                                                        //
00008 //                                                                                                 //
00009 //=================================================================================================//
00010 //   (C) 2004 ATI Research, Inc.  All rights reserved.                                             //
00011 //=================================================================================================//
00012 
00013 #ifndef _RM_UTILITIES_HLSLPARSER_H_
00014 #define _RM_UTILITIES_HLSLPARSER_H_
00015 
00016 //...........................................................................
00017 //...........................................................................
00018 //...........................................................................
00019 //
00020 // HLSL Parser
00021 //
00022 //...........................................................................
00023 //...........................................................................
00024 //...........................................................................
00025 class RMUTIL_API IRmUtilHLSLParser 
00026 {
00027 public :
00028     //=================================================================================================
00029     // TokenIDs
00030     //=================================================================================================
00031     enum TokenID
00032     {
00033         // End Token
00034         TOKEN_END,
00035 
00036         // Number TokenIDs
00037         TOKEN_NUM_INTEGER,
00038         TOKEN_NUM_FLOAT,
00039 
00040         // Identifier
00041         TOKEN_IDENTIFIER,
00042 
00043         // String
00044         TOKEN_STRING,
00045 
00046         // Operator TokenIDs
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         // Keyword TokenIDs
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         // Data Type
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     }; // End of TokenID
00182 
00183     //=======================================================================
00184     // Forward Declaration
00185     //=======================================================================
00186     interface IFunction;
00187     interface IStructType;
00188 
00189     //=======================================================================
00190     // Base Data Type
00191     //=======================================================================
00192     interface RMUTIL_API IDataType
00193     {
00194         // Name of Type
00195         virtual const RmStringT& GetTypeName() const = 0;
00196 
00197         // Type of Data by Token ID
00198         virtual TokenID GetTypeID() const = 0;
00199     }; // End of IDataType
00200 
00201     //=======================================================================
00202     // Variable
00203     //=======================================================================
00204     interface RMUTIL_API IVariable
00205     {
00206         // Location in code where this variable is declared
00207         // ( # of characters from beginning of text )
00208         virtual int GetLocation() const = 0;
00209 
00210         // DataType ( float, int etc )
00211         virtual const IDataType* GetDataType() const = 0;
00212 
00213         // Name of Variable
00214         virtual const RmStringT& GetName() const = 0;
00215 
00216         // Parent Struct/Function
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         // Semantec
00224         virtual const RmStringT& GetSemantec() const = 0;
00225     }; // End of IVariable
00226 
00227     //=======================================================================
00228     // Struct Type
00229     //=======================================================================
00230     interface RMUTIL_API IStructType : public IDataType
00231     {
00232         // Number of children
00233         virtual int GetNumMembers() const = 0;
00234 
00235         // Access Child Member
00236         virtual IVariable*       GetMember( /*[in]*/ int index ) = 0;
00237         virtual const IVariable* GetMember( /*[in]*/ int index ) const = 0;
00238 
00239         virtual IVariable*       FindMember( /*[in]*/ const RM_TCHAR *szName ) = 0;
00240         virtual const IVariable* FindMember( /*[in]*/ const RM_TCHAR *szName ) const = 0;
00241 
00242         // Location where it is defined ( # of characters from beginning of text )
00243         virtual int GetLocation() const = 0;
00244     }; // End of IStructType
00245 
00246     //=======================================================================
00247     // Function
00248     //=======================================================================
00249     interface RMUTIL_API IFunction
00250     {
00251         // Location in code where this function is declared
00252         // ( # of characters from beginning of text )
00253         virtual int GetLocation() const = 0;
00254         virtual int GetEndLocation() const = 0;
00255 
00256         // Name of Variable
00257         virtual const RmStringT& GetName() const = 0;
00258 
00259         // DataType ( float, int etc )
00260         virtual const IDataType* GetReturnType() const = 0;
00261 
00262         // Semantec
00263         virtual const RmStringT& GetSemantec() const = 0;
00264 
00265         // Parameters
00266         virtual int GetNumParameters() const = 0;
00267         virtual IVariable*       GetParameter( /*[in]*/ int index ) = 0;
00268         virtual const IVariable* GetParameter( /*[in]*/ int index ) const = 0;
00269 
00270         virtual IVariable*       FindParameter( /*[in]*/ const RM_TCHAR *szName ) = 0;
00271         virtual const IVariable* FindParameter( /*[in]*/ const RM_TCHAR *szName ) const = 0;
00272 
00273         // Local Variables
00274         virtual int GetNumVariables() const = 0;
00275         virtual IVariable*       GetVariable( /*[in]*/ int index ) = 0;
00276         virtual const IVariable* GetVariable( /*[in]*/ int index ) const = 0;
00277 
00278         virtual IVariable*       FindVariable( /*[in]*/ const RM_TCHAR *szName ) = 0;
00279         virtual const IVariable* FindVariable( /*[in]*/ const RM_TCHAR *szName ) const = 0;
00280     }; // End of IFunction
00281 
00282     //=======================================================================
00283     // Token
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; // Offset in text
00295         virtual int  GetTokenPos() const = 0; // Index to Token Array
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; // Float or Integer
00304         virtual bool IsInteger() const = 0;
00305         virtual bool IsFloat() const = 0;
00306 
00307         virtual bool IsDataType() const = 0;
00308     }; // End of IToken
00309 
00310 public :
00311     //------------------------------------------------------------------------
00312     // static Create/Destroy
00313     //------------------------------------------------------------------------
00314     static IRmUtilHLSLParser* CreateHLSLParser();
00315     static void DestroyHLSLParser( /*[in,out]*/ IRmUtilHLSLParser* &pParser );
00316 
00317     //------------------------------------------------------------------------
00318     // Parsing
00319     //------------------------------------------------------------------------
00320     virtual void Parse( /*[in]*/ const RM_TCHAR *pCode ) = 0;
00321 
00322     //------------------------------------------------------------------------
00323     // DataTypes
00324     //------------------------------------------------------------------------
00325     virtual int              GetNumDataTypes() const = 0;
00326     virtual IDataType*       GetDataType( /*[in]*/ int index ) = 0;
00327     virtual const IDataType* GetDataType( /*[in]*/ int index ) const = 0;
00328 
00329     virtual IDataType*       FindDataType( /*[in]*/ const RM_TCHAR *szName ) = 0;
00330     virtual const IDataType* FindDataType( /*[in]*/ const RM_TCHAR *szName ) const = 0;
00331 
00332     //------------------------------------------------------------------------
00333     // Variables ( global variables only )
00334     //------------------------------------------------------------------------
00335     virtual int              GetNumVariables() const = 0;
00336     virtual IVariable*       GetVariable( /*[in]*/ int index ) = 0;
00337     virtual const IVariable* GetVariable( /*[in]*/ int index ) const = 0;
00338 
00339     virtual IVariable*        FindVariable( /*[in]*/ const RM_TCHAR *szName ) = 0;
00340     virtual const IVariable*  FindVariable( /*[in]*/ const RM_TCHAR *szName ) const = 0;
00341 
00342     //------------------------------------------------------------------------
00343     // Fidn Variable at given loaction of text
00344     //
00345     // - First it checks if given location is inside function, if so 
00346     //   look for local variable, if not found look for global variable
00347     //------------------------------------------------------------------------
00348     virtual IVariable*        FindVariable( /*[in]*/ int textLocation, /*[in]*/ const RM_TCHAR *szName ) = 0;
00349     virtual const IVariable*  FindVariable( /*[in]*/ int textLocation, /*[in]*/ const RM_TCHAR *szName ) const = 0;
00350 
00351     //------------------------------------------------------------------------
00352     // Functions
00353     //------------------------------------------------------------------------
00354     virtual int              GetNumFunctions() const = 0;
00355     virtual IFunction*       GetFunction( /*[in]*/ int index ) = 0;
00356     virtual const IFunction* GetFunction( /*[in]*/ int index ) const = 0;
00357 
00358     virtual IFunction*        FindFunction( /*[in]*/ const RM_TCHAR *szName ) = 0;
00359     virtual const IFunction*  FindFunction( /*[in]*/ const RM_TCHAR *szName ) const = 0;
00360 
00361     // If give position in code is inside function, it returns the Function interface
00362     virtual IFunction*       IsInsideFunction( /*[in]*/ int offset ) = 0;
00363     virtual const IFunction* IsInsideFunction( /*[in]*/ int offset ) const = 0;
00364 
00365     //------------------------------------------------------------------------
00366     // For debugging
00367     //------------------------------------------------------------------------
00368     virtual void OutputParserResult() = 0;
00369 }; // End of IRmUtilLHLSLParser
00370 
00371 
00372 #endif

Generated on Fri Feb 25 16:08:41 2005 for RenderMonkey SDK by doxygen 1.3.6