home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 275 / DPCS0111DVD.ISO / Toolkit / Audio-Visual / VirtualDub / Source / VirtualDub-1.9.10-src.7z / src / Asuka / h / filecreator.h next >
Encoding:
C/C++ Source or Header  |  2009-09-14  |  3.4 KB  |  146 lines

  1. //    VDCompiler - Custom shader video filter for VirtualDub
  2. //    Copyright (C) 2007 Avery Lee
  3. //
  4. //    This program is free software; you can redistribute it and/or modify
  5. //    it under the terms of the GNU General Public License as published by
  6. //    the Free Software Foundation; either version 2 of the License, or
  7. //    (at your option) any later version.
  8. //
  9. //    This program is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. //    GNU General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU General Public License
  15. //    along with this program; if not, write to the Free Software
  16. //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. #ifndef MAKEFILE_H
  19. #define MAKEFILE_H
  20.  
  21. #ifdef _MSC_VER
  22.     #pragma once
  23. #endif
  24.  
  25. #include <vd2/system/refcount.h>
  26. #include <map>
  27.  
  28. class IVDCompilerLogOutput {
  29. public:
  30.     virtual void WriteLogOutput(const char *s) = 0;
  31. };
  32.  
  33. void VDCompilerWriteLogOutputF(IVDCompilerLogOutput& out, const char *format ...);
  34.  
  35. namespace nsVDCompilerTokens {
  36.     enum VDCompilerToken {
  37.         kTokenInt        = 0x100,
  38.         kTokenFloat,
  39.         kTokenString,
  40.         kTokenIdent,
  41.         kTokenKeywordBase    = 0x0200
  42.     };
  43. }
  44.  
  45. struct VDCompilerErrorInfo {
  46.     int mLine;
  47.     int mColumn;
  48.     int mLength;
  49. };
  50.  
  51. class VDCompilerLexer {
  52. public:
  53.     void Init(const char *src, size_t len, const char *context, IVDCompilerLogOutput *pOutput);
  54.     bool GetErrorInfo(VDCompilerErrorInfo& errorInfo);
  55.  
  56.     IVDCompilerLogOutput *GetLogOutput() const { return mpOutput; }
  57.     bool IsErrorFlagSet() const { return mbError; }
  58.  
  59.     void AddToken(int token, const char *s);
  60.  
  61.     int Token();
  62.     void Push();
  63.  
  64.     bool SetError(const char *s);
  65.     bool SetErrorF(const char *format, ...);
  66.  
  67. public:
  68.     const char *mpToken;
  69.     const char *mpTokenLineStart;
  70.     int mTokenLength;
  71.     union {
  72.         int        mIntVal;
  73.         float    mFloatVal;
  74.     };
  75.     vdfastvector<char> mString;
  76.  
  77. protected:
  78.     void SkipComment();
  79.  
  80.     const char *mpSrc;
  81.     const char *mpSrcEnd;
  82.     const char *mpSrcLineStart;
  83.     const char *mpContext;
  84.     int mLineNo;
  85.  
  86.     bool mbError;
  87.     VDCompilerErrorInfo mErrorInfo;
  88.  
  89.     IVDCompilerLogOutput *mpOutput;
  90.  
  91.     struct Keyword {
  92.         int token;
  93.         int len;
  94.         const char *text;
  95.     };
  96.  
  97.     typedef std::multimap<uint32, Keyword> Keywords;
  98.     Keywords mKeywords;
  99. };
  100.  
  101. class IVDFileCreator : public IVDRefCount {
  102. public:
  103.     virtual void Create(const wchar_t *filename) = 0;
  104. };
  105.  
  106. class VDFileCreator;
  107. struct VDFileCreatorValue;
  108.  
  109. class VDFileCreatorParser {
  110. public:
  111.     VDFileCreatorParser();
  112.     ~VDFileCreatorParser();
  113.  
  114.     bool Parse(const char *src, size_t len, const char *context, IVDCompilerLogOutput *pOutput, IVDFileCreator **ppCreator);
  115.  
  116.     bool GetErrorInfo(VDCompilerErrorInfo& errorInfo);
  117.  
  118. protected:
  119.     bool TryParseGlobalStatement();
  120.     bool ParseChunk();
  121.     bool ParseIndexedChunk();
  122.     bool ParseExpression(VDFileCreatorValue& value);
  123.     bool EmitExpressionI1();
  124.     bool EmitExpressionI2();
  125.     bool EmitExpressionI4();
  126.     bool EmitExpressionI8();
  127.     bool EmitExpressionU1();
  128.     bool EmitExpressionU2();
  129.     bool EmitExpressionU4();
  130.     bool EmitExpressionU8();
  131.     bool EmitExpressionR4();
  132.     bool EmitExpressionR8();
  133.     bool EmitExpressionFCC();
  134.  
  135.     void Collect();
  136.  
  137.     VDCompilerLexer    mLexer;
  138.  
  139.     vdrefptr<VDFileCreator> mpCreator;
  140.  
  141.     typedef vdfastvector<const char *> TempStrings;
  142.     TempStrings mTempStrings;
  143. };
  144.  
  145. #endif
  146.