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

RmUtilGLSLParser.h

00001 //=================================================================================================//
00002 // filename: RmUtilGLSLParser.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_GLSLPARSER_H_
00014 #define _RM_UTILITIES_GLSLPARSER_H_
00015 
00016 //...........................................................................
00017 //...........................................................................
00018 //...........................................................................
00019 //
00020 // GLSL Parser
00021 //
00022 //...........................................................................
00023 //...........................................................................
00024 //...........................................................................
00025 class RMUTIL_API IRmUtilGLSLParser 
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_VS,
00091         TOKEN_KW_PS,
00092         TOKEN_KW_RETURN,
00093         TOKEN_KW_STRUCT,
00094 
00095         // Data Type
00096         TOKEN_DT_VOID,
00097         TOKEN_DT_BOOL,
00098         TOKEN_DT_BOOL2,
00099         TOKEN_DT_BOOL3,
00100         TOKEN_DT_BOOL4,
00101         TOKEN_DT_INT,
00102         TOKEN_DT_INT2,
00103         TOKEN_DT_INT3,
00104         TOKEN_DT_INT4,
00105         TOKEN_DT_FLOAT,
00106         TOKEN_DT_FLOAT2,
00107         TOKEN_DT_FLOAT3,
00108         TOKEN_DT_FLOAT4,
00109         TOKEN_DT_MAT2x2,
00110         TOKEN_DT_MAT3x3,
00111         TOKEN_DT_MAT4x4,
00112     }; // End of TokenID
00113 
00114     //=======================================================================
00115     // Forward Declaration
00116     //=======================================================================
00117     interface IFunction;
00118     interface IStructType;
00119 
00120     //=======================================================================
00121     // Base Data Type
00122     //=======================================================================
00123     interface RMUTIL_API IDataType
00124     {
00125         // Name of Type
00126         virtual const RmStringT& GetTypeName() const = 0;
00127 
00128         // Type of Data by Token ID
00129         virtual TokenID GetTypeID() const = 0;
00130     }; // End of IDataType
00131 
00132     //=======================================================================
00133     // Variable
00134     //=======================================================================
00135     interface RMUTIL_API IVariable
00136     {
00137         // Location in code where this variable is declared
00138         // ( # of characters from beginning of text )
00139         virtual int GetLocation() const = 0;
00140 
00141         // DataType ( float, int etc )
00142         virtual const IDataType* GetDataType() const = 0;
00143 
00144         // Name of Variable
00145         virtual const RmStringT& GetName() const = 0;
00146 
00147         // Parent Struct/Function
00148         virtual IFunction*       GetParentFunction() = 0;
00149         virtual const IFunction* GetParentFunction() const = 0;
00150 
00151         virtual IStructType*       GetParentStruct() = 0;
00152         virtual const IStructType* GetParentStruct() const = 0;
00153 
00154         // Semantec
00155         virtual const RmStringT& GetSemantec() const = 0;
00156     }; // End of IVariable
00157 
00158     //=======================================================================
00159     // Struct Type
00160     //=======================================================================
00161     interface RMUTIL_API IStructType : public IDataType
00162     {
00163         // Number of children
00164         virtual int GetNumMembers() const = 0;
00165 
00166         // Access Child Member
00167         virtual IVariable*       GetMember( /*[in]*/ int index ) = 0;
00168         virtual const IVariable* GetMember( /*[in]*/ int index ) const = 0;
00169 
00170         virtual IVariable*       FindMember( /*[in]*/ const RM_TCHAR *szName ) = 0;
00171         virtual const IVariable* FindMember( /*[in]*/ const RM_TCHAR *szName ) const = 0;
00172 
00173         // Location where it is defined ( # of characters from beginning of text )
00174         virtual int GetLocation() const = 0;
00175     }; // End of IStructType
00176 
00177     //=======================================================================
00178     // Function
00179     //=======================================================================
00180     interface RMUTIL_API IFunction
00181     {
00182         // Location in code where this function is declared
00183         // ( # of characters from beginning of text )
00184         virtual int GetLocation() const = 0;
00185         virtual int GetEndLocation() const = 0;
00186 
00187         // Name of Variable
00188         virtual const RmStringT& GetName() const = 0;
00189 
00190         // DataType ( float, int etc )
00191         virtual const IDataType* GetReturnType() const = 0;
00192 
00193         // Semantec
00194         virtual const RmStringT& GetSemantec() const = 0;
00195 
00196         // Parameters
00197         virtual int GetNumParameters() const = 0;
00198         virtual IVariable*       GetParameter( /*[in]*/ int index ) = 0;
00199         virtual const IVariable* GetParameter( /*[in]*/ int index ) const = 0;
00200 
00201         virtual IVariable*       FindParameter( /*[in]*/ const RM_TCHAR *szName ) = 0;
00202         virtual const IVariable* FindParameter( /*[in]*/ const RM_TCHAR *szName ) const = 0;
00203 
00204         // Local Variables
00205         virtual int GetNumVariables() const = 0;
00206         virtual IVariable*       GetVariable( /*[in]*/ int index ) = 0;
00207         virtual const IVariable* GetVariable( /*[in]*/ int index ) const = 0;
00208 
00209         virtual IVariable*       FindVariable( /*[in]*/ const RM_TCHAR *szName ) = 0;
00210         virtual const IVariable* FindVariable( /*[in]*/ const RM_TCHAR *szName ) const = 0;
00211     }; // End of IFunction
00212 
00213     //=======================================================================
00214     // Token
00215     //=======================================================================
00216     interface RMUTIL_API IToken
00217     {
00218         virtual TokenID GetTokenType() const = 0;
00219 
00220         virtual const RmStringT& GetString() const = 0;
00221 
00222         virtual int    GetInteger() const = 0;
00223         virtual double GetFloat() const = 0;
00224 
00225         virtual int  GetLocation() const = 0; // Offset in text
00226         virtual int  GetTokenPos() const = 0; // Index to Token Array
00227 
00228         virtual bool IsOperator() const = 0;
00229         virtual bool IsKeyword() const = 0;
00230         virtual bool IsIdentifier() const = 0;
00231         virtual bool IsString() const = 0;
00232         virtual bool IsEndToken() const = 0;
00233 
00234         virtual bool IsNumber() const = 0; // Float or Integer
00235         virtual bool IsInteger() const = 0;
00236         virtual bool IsFloat() const = 0;
00237 
00238         virtual bool IsDataType() const = 0;
00239     }; // End of IToken
00240 
00241 public :
00242     //------------------------------------------------------------------------
00243     // static Create/Destroy
00244     //------------------------------------------------------------------------
00245     static IRmUtilGLSLParser* CreateGLSLParser();
00246     static void DestroyGLSLParser( /*[in,out]*/ IRmUtilGLSLParser* &pParser );
00247 
00248     //------------------------------------------------------------------------
00249     // Parsing
00250     //------------------------------------------------------------------------
00251     virtual void Parse( /*[in]*/ const RM_TCHAR *pCode ) = 0;
00252 
00253     //------------------------------------------------------------------------
00254     // DataTypes
00255     //------------------------------------------------------------------------
00256     virtual int              GetNumDataTypes() const = 0;
00257     virtual IDataType*       GetDataType( /*[in]*/ int index ) = 0;
00258     virtual const IDataType* GetDataType( /*[in]*/ int index ) const = 0;
00259 
00260     virtual IDataType*       FindDataType( /*[in]*/ const RM_TCHAR *szName ) = 0;
00261     virtual const IDataType* FindDataType( /*[in]*/ const RM_TCHAR *szName ) const = 0;
00262 
00263     //------------------------------------------------------------------------
00264     // Variables ( global variables only )
00265     //------------------------------------------------------------------------
00266     virtual int              GetNumVariables() const = 0;
00267     virtual IVariable*       GetVariable( /*[in]*/ int index ) = 0;
00268     virtual const IVariable* GetVariable( /*[in]*/ int index ) const = 0;
00269 
00270     virtual IVariable*        FindVariable( /*[in]*/ const RM_TCHAR *szName ) = 0;
00271     virtual const IVariable*  FindVariable( /*[in]*/ const RM_TCHAR *szName ) const = 0;
00272 
00273     //------------------------------------------------------------------------
00274     // Fidn Variable at given loaction of text
00275     //
00276     // - First it checks if given location is inside function, if so 
00277     //   look for local variable, if not found look for global variable
00278     //------------------------------------------------------------------------
00279     virtual IVariable*        FindVariable( /*[in]*/ int textLocation, /*[in]*/ const RM_TCHAR *szName ) = 0;
00280     virtual const IVariable*  FindVariable( /*[in]*/ int textLocation, /*[in]*/ const RM_TCHAR *szName ) const = 0;
00281 
00282     //------------------------------------------------------------------------
00283     // Functions
00284     //------------------------------------------------------------------------
00285     virtual int              GetNumFunctions() const = 0;
00286     virtual IFunction*       GetFunction( /*[in]*/ int index ) = 0;
00287     virtual const IFunction* GetFunction( /*[in]*/ int index ) const = 0;
00288 
00289     virtual IFunction*        FindFunction( /*[in]*/ const RM_TCHAR *szName ) = 0;
00290     virtual const IFunction*  FindFunction( /*[in]*/ const RM_TCHAR *szName ) const = 0;
00291 
00292     // If give position in code is inside function, it returns the Function interface
00293     virtual IFunction*       IsInsideFunction( /*[in]*/ int offset ) = 0;
00294     virtual const IFunction* IsInsideFunction( /*[in]*/ int offset ) const = 0;
00295 
00296     //------------------------------------------------------------------------
00297     // For debugging
00298     //------------------------------------------------------------------------
00299     virtual void OutputParserResult() = 0;
00300 }; // End of IRmUtilLGLSLParser
00301 
00302 
00303 #endif

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