• <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  評(píng)論-2670  文章-0  trackbacks-0
                為了讓宿主程序可以更加清楚一份Kernel FP代碼的內(nèi)容,我今天為Kernel FP添加了反射的API。

                Kernel FP的腳本引擎分為VL_KfpSymbol和VL_KfpMachine。其中VL_KfpSymbol負(fù)責(zé)編譯代碼和構(gòu)造VL_KfpMachine。VL_KfpMachine的運(yùn)行可以脫離VL_KfpSymbol,VL_KfpSymbol再次添加代碼并編譯的時(shí)候,構(gòu)造的VL_KfpMachine并不受到影響。先前VL_KfpMachine已經(jīng)有了小部分反射,主要用于枚舉各種對(duì)象的運(yùn)行時(shí)ID。這次VL_KfpSymbol的反射則是用于查看已經(jīng)添加的代碼的結(jié)構(gòu)。

                反射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         };

                以下為使用方法。這是一個(gè)函數(shù),從VL_KfpSymbol對(duì)象開始反射并打印出所反射到的內(nèi)容:
             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]繼續(xù)");
            59         GetConsole()->WaitForEnter();
            60     }
            61 }

                對(duì)于宿主程序來說,反射主要用于檢查連接函數(shù)的類型,并根據(jù)不同的類型使用不同的求值方法進(jìn)行求值。
            posted on 2008-12-20 06:10 陳梓瀚(vczh) 閱讀(1422) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 腳本技術(shù)
            四虎国产精品成人免费久久| 亚洲欧美国产日韩综合久久| 色狠狠久久综合网| 一本久久久久久久| 青青热久久综合网伊人| 久久久精品国产sm调教网站| 亚洲va久久久噜噜噜久久| 久久综合久久综合亚洲| 一极黄色视频久久网站| 亚洲欧美日韩精品久久亚洲区| 久久久久女教师免费一区| 久久精品综合一区二区三区| 少妇被又大又粗又爽毛片久久黑人| 国产精品伦理久久久久久| 久久99精品久久久久久9蜜桃| 久久精品国产精品亜洲毛片| 久久福利片| 久久人人爽人人爽人人片AV东京热| 久久精品国产亚洲av麻豆蜜芽| 色偷偷久久一区二区三区| AV狠狠色丁香婷婷综合久久| 国产一区二区精品久久岳| 久久久国产精品| 性做久久久久久久| 国产激情久久久久影院老熟女| 久久久久女教师免费一区| 亚洲AV日韩精品久久久久久| 嫩草影院久久国产精品| 日韩欧美亚洲国产精品字幕久久久 | 91精品久久久久久无码| 久久久久99精品成人片| 国产婷婷成人久久Av免费高清| 99热精品久久只有精品| 精品久久久久久久国产潘金莲 | 久久精品一区二区影院| 久久久久久久久久久| 色综合久久久久网| 久久久无码精品亚洲日韩蜜臀浪潮 | 伊人精品久久久久7777| 久久这里只精品国产99热| 国产精品成人久久久|