• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆-341  評論-2670  文章-0  trackbacks-0
                為了讓宿主程序可以更加清楚一份Kernel FP代碼的內容,我今天為Kernel FP添加了反射的API。

                Kernel FP的腳本引擎分為VL_KfpSymbol和VL_KfpMachine。其中VL_KfpSymbol負責編譯代碼和構造VL_KfpMachine。VL_KfpMachine的運行可以脫離VL_KfpSymbol,VL_KfpSymbol再次添加代碼并編譯的時候,構造的VL_KfpMachine并不受到影響。先前VL_KfpMachine已經有了小部分反射,主要用于枚舉各種對象的運行時ID。這次VL_KfpSymbol的反射則是用于查看已經添加的代碼的結構。

                反射API如下:
              1 /*********************************************************************************************************
              2 反射
              3 *********************************************************************************************************/
              4 
              5         class VL_KfpAsmDecl : public VL_Base
              6         {
              7         public:
              8             virtual VUnicodeString                GetName()=0;
              9             virtual VUnicodeString                GetOwnerUnitName()=0;
             10         };
             11 
             12         class VL_KfpAsmTypeDecl : public VL_KfpAsmDecl
             13         {
             14             friend class VL_KfpAsmUnit;
             15         protected:
             16             VL_KfpIdTypeDeclaration::Ptr    FInternalObject;
             17 
             18             VL_KfpAsmTypeDecl(VL_KfpIdTypeDeclaration::Ptr Object);
             19         public:
             20             VL_KfpAsmTypeDecl();
             21             ~VL_KfpAsmTypeDecl();
             22 
             23             VUnicodeString                        GetName();
             24             VUnicodeString                        GetOwnerUnitName();
             25             VInt                                GetTypeParameterCount();
             26             VUnicodeString                        GetTypeParameter(VInt Index);
             27             VL_KfpIdType::Ptr                    GetReferencedType();
             28         };
             29 
             30         class VL_KfpAsmCtorDecl : public VL_KfpAsmDecl
             31         {
             32             friend class VL_KfpAsmUnit;
             33         protected:
             34             VL_KfpIdCtorDeclaration::Ptr        FInternalObject;
             35 
             36             VL_KfpAsmCtorDecl(VL_KfpIdCtorDeclaration::Ptr Object);
             37         public:
             38             VL_KfpAsmCtorDecl();
             39             ~VL_KfpAsmCtorDecl();
             40 
             41             VUnicodeString                        GetName();
             42             VUnicodeString                        GetOwnerUnitName();
             43             VUnicodeString                        GetOwnerTypeName();
             44             VL_KfpIdType::Ptr                    GetType();
             45         };
             46 
             47         class VL_KfpAsmExpectedDecl : public VL_KfpAsmDecl
             48         {
             49             friend class VL_KfpAsmUnit;
             50         protected:
             51             VL_KfpIdExpectedDeclaration::Ptr    FInternalObject;
             52 
             53             VL_KfpAsmExpectedDecl(VL_KfpIdExpectedDeclaration::Ptr Object);
             54         public:
             55             VL_KfpAsmExpectedDecl();
             56             ~VL_KfpAsmExpectedDecl();
             57 
             58             VUnicodeString                        GetName();
             59             VUnicodeString                        GetOwnerUnitName();
             60             VInt                                GetTypeParameterCount();
             61             VUnicodeString                        GetTypeParameter(VInt Index);
             62             VL_KfpIdType::Ptr                    GetType();
             63         };
             64 
             65         class VL_KfpAsmFunctionDecl : public VL_KfpAsmDecl
             66         {
             67             friend class VL_KfpAsmUnit;
             68         protected:
             69             VL_KfpIdFunctionDeclaration::Ptr    FInternalObject;
             70 
             71             VL_KfpAsmFunctionDecl(VL_KfpIdFunctionDeclaration::Ptr Object);
             72         public:
             73             VL_KfpAsmFunctionDecl();
             74             ~VL_KfpAsmFunctionDecl();
             75 
             76             VUnicodeString                        GetName();
             77             VUnicodeString                        GetOwnerUnitName();
             78             VInt                                GetTypeParameterCount();
             79             VUnicodeString                        GetTypeParameter(VInt Index);
             80             VL_KfpIdType::Ptr                    GetType();
             81             VBool                                IsExternalFunction();
             82             VUnicodeString                        GetAlias();
             83         };
             84 
             85         class VL_KfpAsmUnit : public VL_Base
             86         {
             87             friend class VL_KfpAsmProgram;
             88         protected:
             89             VL_KfpIdTable::Ptr                    FTable;
             90 
             91             VL_KfpAsmUnit(VL_KfpIdTable::Ptr Table);
             92         public:
             93             VL_KfpAsmUnit();
             94             ~VL_KfpAsmUnit();
             95 
             96             VUnicodeString                        GetName();
             97             VInt                                GetImportCount();
             98             VUnicodeString                        GetImport(VInt Index);
             99             VInt                                GetTypeDeclarationCount();
            100             VL_KfpAsmTypeDecl                    GetTypeDeclaration(VInt Index);
            101             VInt                                GetCtorDeclarationCount();
            102             VL_KfpAsmCtorDecl                    GetCtorDeclaration(VInt Index);
            103             VInt                                GetExpectedDeclarationCount();
            104             VL_KfpAsmExpectedDecl                GetExpectedDeclaration(VInt Index);
            105             VInt                                GetFunctionDeclarationCount();
            106             VL_KfpAsmFunctionDecl                GetFunctionDeclaration(VInt Index);
            107         };
            108 
            109         class VL_KfpAsmProgram : public VL_Base
            110         {
            111             friend class VL_KfpSymbol;
            112         protected:
            113             typedef VL_AutoPtr<VL_KfpAsmProgram>                    Ptr;
            114             VL_KfpCodeUnitAnalyser*                FAnalyser;
            115 
            116             VL_KfpAsmProgram(VL_KfpCodeUnitAnalyser* Analyser);
            117         public:
            118             VL_KfpAsmProgram();
            119             ~VL_KfpAsmProgram();
            120 
            121             VInt                                GetUnitCount();
            122             VL_KfpAsmUnit                        GetUnit(VInt Index);
            123         };
            124 
            125 /*********************************************************************************************************
            126 腳本引擎
            127 *********************************************************************************************************/
            128 
            129         class VL_KfpSymbol : public VL_Base
            130         {
            131         protected:
            132             VL_KfpCodeProvider                    FProvider;
            133             VL_KfpCodeUnitAnalyser                FAnalyser;
            134             VL_KfpCodeUnit::List                FCodeUnits;
            135             VBool                                FErrorState;
            136             VL_KfpAsmProgram::Ptr                FProgram;
            137         public:
            138             VL_KfpSymbol();
            139             ~VL_KfpSymbol();
            140 
            141             VL_KfpCodeUnit::Ptr                    AddUnit(VUnicodeString Code , VL_KfpError::List& Errors);
            142             void                                AddUnit(KfpUnit& Unit);
            143             VBool                                PreCompile(VL_KfpError::List& Errors);
            144             VBool                                IsErrorState();
            145             VBool                                HasCodeUnit();
            146             VL_KfpMachine::Ptr                    CreateMachine();
            147             VUnicodeString                        GetReport();
            148             VUnicodeString                        GetDebugInformation();
            149             VL_KfpAsmProgram*                    GetProgramForReflection();
            150         };

                以下為使用方法。這是一個函數,從VL_KfpSymbol對象開始反射并打印出所反射到的內容:
             1 void ReflectSymbol(VL_KfpSymbol* Symbol)
             2 {
             3     for(VInt i=0;i<Symbol->GetProgramForReflection()->GetUnitCount();i++)
             4     {
             5         VL_KfpAsmUnit Unit=Symbol->GetProgramForReflection()->GetUnit(i);
             6         GetConsole()->Write(L"Unit : "+Unit.GetName()+L"\r\n");
             7         for(VInt j=0;j<Unit.GetImportCount();j++)
             8         {
             9             GetConsole()->Write(L"  Import : "+Unit.GetImport(j)+L"\r\n");
            10         }
            11         for(VInt j=0;j<Unit.GetTypeDeclarationCount();j++)
            12         {
            13             VL_KfpAsmTypeDecl TypeDecl=Unit.GetTypeDeclaration(j);
            14             GetConsole()->Write(L"    Type Declaration : "+TypeDecl.GetOwnerUnitName()+L"."+TypeDecl.GetName()+L"\r\n");
            15             GetConsole()->Write(L"      Parameters : ");
            16             for(VInt k=0;k<TypeDecl.GetTypeParameterCount();k++)
            17             {
            18                 GetConsole()->Write(TypeDecl.GetTypeParameter(k)+L" ");
            19             }
            20             GetConsole()->Write(L"\r\n");
            21             GetConsole()->Write(L"      Type :"+TypeDecl.GetReferencedType()->GenerateCode(L"")+L"\r\n");
            22         }
            23         for(VInt j=0;j<Unit.GetCtorDeclarationCount();j++)
            24         {
            25             VL_KfpAsmCtorDecl CtorDecl=Unit.GetCtorDeclaration(j);
            26             GetConsole()->Write(L"    Ctor Declaration : "+CtorDecl.GetOwnerUnitName()+L"."+CtorDecl.GetName()+L"\r\n");
            27             GetConsole()->Write(L"      Source : "+CtorDecl.GetOwnerTypeName()+L"\r\n");
            28             GetConsole()->Write(L"      Type :"+CtorDecl.GetType()->GenerateCode(L"")+L"\r\n");
            29         }
            30         for(VInt j=0;j<Unit.GetExpectedDeclarationCount();j++)
            31         {
            32             VL_KfpAsmExpectedDecl ExpectedDecl=Unit.GetExpectedDeclaration(j);
            33             GetConsole()->Write(L"    Expected Declaration : "+ExpectedDecl.GetOwnerUnitName()+L"."+ExpectedDecl.GetName()+L"\r\n");
            34             GetConsole()->Write(L"      Parameters : ");
            35             for(VInt k=0;k<ExpectedDecl.GetTypeParameterCount();k++)
            36             {
            37                 GetConsole()->Write(ExpectedDecl.GetTypeParameter(k)+L" ");
            38             }
            39             GetConsole()->Write(L"\r\n");
            40             GetConsole()->Write(L"      Type :"+ExpectedDecl.GetType()->GenerateCode(L"")+L"\r\n");
            41         }
            42         for(VInt j=0;j<Unit.GetFunctionDeclarationCount();j++)
            43         {
            44             VL_KfpAsmFunctionDecl FunctionDecl=Unit.GetFunctionDeclaration(j);
            45             GetConsole()->Write(L"    Function Declaration : "+FunctionDecl.GetOwnerUnitName()+L"."+FunctionDecl.GetName()+L"\r\n");
            46             GetConsole()->Write(L"      Parameters : ");
            47             for(VInt k=0;k<FunctionDecl.GetTypeParameterCount();k++)
            48             {
            49                 GetConsole()->Write(FunctionDecl.GetTypeParameter(k)+L" ");
            50             }
            51             GetConsole()->Write(L"\r\n");
            52             GetConsole()->Write(L"      Type :"+FunctionDecl.GetType()->GenerateCode(L"")+L"\r\n");
            53             if(FunctionDecl.IsExternalFunction())
            54             {
            55             GetConsole()->Write(L"      Alias :"+FunctionDecl.GetAlias()+L"\r\n");
            56             }
            57         }
            58         GetConsole()->Write(L"按[ENTER]繼續");
            59         GetConsole()->WaitForEnter();
            60     }
            61 }

                對于宿主程序來說,反射主要用于檢查連接函數的類型,并根據不同的類型使用不同的求值方法進行求值。
            posted on 2008-12-20 06:10 陳梓瀚(vczh) 閱讀(1416) 評論(0)  編輯 收藏 引用 所屬分類: 腳本技術
            国产亚州精品女人久久久久久 | 99久久精品国产一区二区| 99久久777色| 国产日韩欧美久久| 伊人久久大香线蕉精品不卡| 97香蕉久久夜色精品国产| 国产A三级久久精品| 久久―日本道色综合久久| 亚洲乱码日产精品a级毛片久久| 久久精品国产黑森林| 天天躁日日躁狠狠久久| 狠狠色伊人久久精品综合网| 伊人久久大香线蕉综合Av| 久久99精品国产麻豆婷婷| 久久精品国产亚洲精品2020| 久久夜色撩人精品国产| 久久精品中文字幕久久| 人人狠狠综合久久88成人| 老司机午夜网站国内精品久久久久久久久| 亚洲中文字幕无码久久精品1| 93精91精品国产综合久久香蕉| 久久夜色精品国产噜噜噜亚洲AV| 欧美久久天天综合香蕉伊| 青青青国产精品国产精品久久久久| 久久国产欧美日韩精品| 亚洲国产综合久久天堂| 久久高潮一级毛片免费| 99久久综合国产精品二区| 久久精品国产69国产精品亚洲| 亚洲精品蜜桃久久久久久| 亚洲精品99久久久久中文字幕 | 99久久精品国产一区二区| 伊人久久成人成综合网222| 久久久精品人妻无码专区不卡| 91久久精品电影| 国产精品久久久久久久午夜片 | 久久成人小视频| 亚洲伊人久久综合影院| 亚洲国产精品成人久久蜜臀| 久久亚洲中文字幕精品一区四| 亚洲精品视频久久久|