Changeset 525 in dev for trunk


Ignore:
Timestamp:
May 1, 2008, 11:46:43 PM (16 years ago)
Author:
dai_9181
Message:

デリゲート収集コードの実装をLexicalAnalyzerクラスに移動した。

Location:
trunk/ab5.0/abdev
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/ab5.0/abdev/BasicCompiler_Common/include/Delegate.h

    r524 r525  
    11#pragma once
    2 
    3 class Delegates;
    42
    53class Delegate
     
    75    , public Jenga::Common::ObjectInHashmap<Delegate>
    86{
    9     friend Delegates;
    10 
    117    // importされている名前空間
    128    NamespaceScopesCollection importedNamespaces;
     
    4339    }
    4440
     41    const std::string &GetParamStr() const
     42    {
     43        return paramStr;
     44    }
     45    const std::string &GetReturnTypeName() const
     46    {
     47        return returnTypeName;
     48    }
     49
    4550    void RefleshParameterAndReturnType();
    4651
     
    6166    bool IsSimilar( const Delegate &dgt ) const;
    6267};
    63 
    64 class Delegates : public Jenga::Common::Hashmap<Delegate>
    65 {
    66 public:
    67     void Collect( const BasicSource &source );
    68     void GenerateSourceCode( std::string &destSource );
    69     void RefleshParameterAndReturnType();
    70 };
     68typedef Jenga::Common::Hashmap<Delegate> Delegates;
  • trunk/ab5.0/abdev/BasicCompiler_Common/include/LexicalAnalyzer.h

    r511 r525  
    3030    static UserProc* ParseUserProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, char *buffer,int nowLine,bool isVirtual,CClass *pobj_c, bool isStatic, char *interfaceName = NULL );
    3131    static void CollectProcedures( const BasicSource &source, UserProcs &userProcs, DllProcs &dllProcs );
     32
     33    // デリゲートを収集する
     34    static void CollectDelegates( const BasicSource &source, Delegates &delegates );
     35    static std::string GenerateDelegatesSourceCode( const Delegates &delegates );
     36    static void RefleshDelegatesParameterAndReturnType( Delegates &delegates );
    3237};
    3338
  • trunk/ab5.0/abdev/BasicCompiler_Common/src/Delegate.cpp

    r523 r525  
    4242    return false;
    4343}
    44 
    45 void Delegates::Collect( const BasicSource &source )
    46 {
    47     int i2;
    48     char temporary[VN_SIZE];
    49 
    50     // 名前空間管理
    51     NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
    52     namespaceScopes.clear();
    53 
    54     // Importsされた名前空間の管理
    55     NamespaceScopesCollection &importedNamespaces = compiler.GetNamespaceSupporter().GetImportedNamespaces();
    56     importedNamespaces.clear();
    57 
    58     for( int i=0; i<source.GetLength(); i++ )
    59     {
    60         if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){
    61             for(i+=2,i2=0;;i2++,i++){
    62                 if( IsCommandDelimitation( source[i] ) ){
    63                     temporary[i2]=0;
    64                     break;
    65                 }
    66                 temporary[i2]=source[i];
    67             }
    68             namespaceScopes.push_back( temporary );
    69 
    70             continue;
    71         }
    72         else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){
    73             if( namespaceScopes.size() <= 0 ){
    74                 compiler.errorMessenger.Output(12, "End Namespace", i );
    75             }
    76             else{
    77                 namespaceScopes.pop_back();
    78             }
    79 
    80             i += 2;
    81             continue;
    82         }
    83         else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){
    84             for(i+=2,i2=0;;i2++,i++){
    85                 if( IsCommandDelimitation( source[i] ) ){
    86                     temporary[i2]=0;
    87                     break;
    88                 }
    89                 temporary[i2]=source[i];
    90             }
    91             if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )
    92             {
    93                 compiler.errorMessenger.Output(64,temporary,i );
    94             }
    95 
    96             continue;
    97         }
    98         else if( source[i] == 1 && source[i+1] == ESC_CLEARNAMESPACEIMPORTED ){
    99             importedNamespaces.clear();
    100             continue;
    101         }
    102 
    103         else if( source[i] == 1 && source[i+1] == ESC_DELEGATE )
    104         {
    105             int nowLine = i;
    106 
    107             i += 2;
    108             if( !( source[i] == 1 && ( source[i+1] == ESC_SUB || source[i+1] == ESC_FUNCTION ) ) )
    109             {
    110                 compiler.errorMessenger.Output(1,NULL,i);
    111                 continue;
    112             }
    113 
    114             Procedure::Kind procKind = Procedure::Sub;
    115             if( source[i+1] == ESC_FUNCTION )
    116             {
    117                 procKind = Procedure::Function;
    118             }
    119             i += 2;
    120 
    121             // 名前
    122             char name[VN_SIZE];
    123             GetIdentifierToken( name, source.GetBuffer(), i );
    124 
    125             if( source[i] != '(' )
    126             {
    127                 compiler.errorMessenger.Output(1,NULL,nowLine);
    128                 continue;
    129             }
    130 
    131             // パラメータ文字列
    132             char paramStr[8192];
    133             i += GetStringInPare( paramStr, source.GetBuffer() + i, true );
    134 
    135             // 戻り値の型の文字列
    136             char returnTypeName[VN_SIZE] = "";
    137             if( source[i] == 1 && source[i+1] == ESC_AS )
    138             {
    139                 i += 2;
    140                 GetCommandToken( returnTypeName, source.GetBuffer(), i );
    141 
    142                 if( procKind != Procedure::Function )
    143                 {
    144                     compiler.errorMessenger.Output(38,name,nowLine);
    145                 }
    146             }
    147             else
    148             {
    149                 if( procKind == Procedure::Function )
    150                 {
    151                     compiler.errorMessenger.Output(-104,name,nowLine);
    152                     lstrcpy( returnTypeName, "Double" );
    153                 }
    154             }
    155 
    156             this->Put( new Delegate( namespaceScopes, importedNamespaces, name, procKind, paramStr, returnTypeName, nowLine ) );
    157         }
    158     }
    159 }
    160 
    161 void Delegates::GenerateSourceCode( std::string &destSource )
    162 {
    163     destSource = "";
    164 
    165     SourceTemplate sourceTemplate( ActiveBasic::Common::Environment::GetAbdevSystemDirPath() + "\\templates\\delegate_class.tab" );
    166 
    167     this->Iterator_Reset();
    168     while( this->Iterator_HasNext() )
    169     {
    170         const Delegate &dg = *this->Iterator_GetNext();
    171 
    172         if( !dg.isTargetObjectModule )
    173         {
    174             // 静的リンクライブラリの場合は飛ばす(既にインスタンスが定義済みであるため)
    175             continue;
    176         }
    177 
    178         std::map<std::string,std::string> values;
    179 
    180         if( dg.GetNamespaceScopes().size() )
    181         {
    182             std::string namespaceScopesCommandStr = "";
    183             std::string endNamespaceScopesCommandStr = "";
    184             BOOST_FOREACH( const std::string &namespaceStr, dg.GetNamespaceScopes() )
    185             {
    186                 if( namespaceScopesCommandStr.size() )
    187                 {
    188                     namespaceScopesCommandStr += ":";
    189                     endNamespaceScopesCommandStr += ":";
    190                 }
    191                 namespaceScopesCommandStr += "Namespace " + namespaceStr;
    192                 endNamespaceScopesCommandStr += "End Namespace";
    193             }
    194 
    195             values.insert( std::map<std::string,std::string>::value_type(
    196                 "#namespace_begin#",
    197                 namespaceScopesCommandStr
    198             ) );
    199             values.insert( std::map<std::string,std::string>::value_type(
    200                 "#namespace_end#",
    201                 endNamespaceScopesCommandStr
    202             ) );
    203         }
    204         else
    205         {
    206             values.insert( std::map<std::string,std::string>::value_type( "#namespace_begin#", "" ) );
    207             values.insert( std::map<std::string,std::string>::value_type( "#namespace_end#", "" ) );
    208         }
    209 
    210         values.insert( std::map<std::string,std::string>::value_type( "#name#", dg.GetName() ) );
    211 
    212         if( dg.IsFunction() )
    213         {
    214             values.insert( std::map<std::string,std::string>::value_type(
    215                 "#call_method_begin#",
    216                 (std::string)"Function Call(" + dg.paramStr + ") As " + dg.returnTypeName
    217             ) );
    218 
    219             values.insert( std::map<std::string,std::string>::value_type(
    220                 "#call_method_end#",
    221                 "End Function"
    222             ) );
    223 
    224             values.insert( std::map<std::string,std::string>::value_type( "#result#", "Call=" ) );
    225         }
    226         else
    227         {
    228             values.insert( std::map<std::string,std::string>::value_type(
    229                 "#call_method_begin#",
    230                 (std::string)"Sub Call(" + dg.paramStr + ")"
    231             ) );
    232 
    233             values.insert( std::map<std::string,std::string>::value_type(
    234                 "#call_method_end#",
    235                 "End Sub"
    236             ) );
    237 
    238             values.insert( std::map<std::string,std::string>::value_type( "#result#", "" ) );
    239         }
    240 
    241         values.insert( std::map<std::string,std::string>::value_type( "#params#", dg.paramStr ) );
    242 
    243         destSource += sourceTemplate.GetResult( values );
    244     }
    245 /*
    246     std::ofstream ofs( ( Jenga::Common::Environment::GetAppDir() + "\\generated_delegate_code.log" ).c_str() );
    247     ofs << destSource;
    248     ofs.close();
    249     */
    250 }
    251 
    252 void Delegates::RefleshParameterAndReturnType()
    253 {
    254     this->Iterator_Reset();
    255     while( this->Iterator_HasNext() )
    256     {
    257         Delegate &dg = *this->Iterator_GetNext();
    258         dg.RefleshParameterAndReturnType();
    259     }
    260 }
  • trunk/ab5.0/abdev/BasicCompiler_Common/src/ObjectModule.cpp

    r524 r525  
    7575#include <Variable.h>
    7676#include <Procedure.h>
    77 #include <LexicalAnalyzer.h>
    7877#include <Program.h>
    7978#include <TypeDef.h>
     
    8483#include <Exception.h>
    8584#include <Meta.h>
     85
    8686#include <CodeGenerator.h>
    8787#include <Messenger.h>
     
    9191#include <Debugger.h>
    9292#include <Program.h>
     93#include <LexicalAnalyzer.h>
     94
    9395
    9496
  • trunk/ab5.0/abdev/compiler_x86/MakePeHdr.cpp

    r523 r525  
    156156    // デリゲートに関する情報を収集
    157157    {
    158         compiler.GetObjectModule().meta.GetDelegates().Collect(
    159             compiler.GetObjectModule().GetCurrentSource()
     158        ActiveBasic::Compiler::LexicalAnalyzer::CollectDelegates(
     159            compiler.GetObjectModule().GetCurrentSource(),
     160            compiler.GetObjectModule().meta.GetDelegates()
    160161        );
    161162        compiler.GetObjectModule().meta.GetDelegates().Iterator_Init();
    162163
    163164        // デリゲートからクラスコードを生成
    164         std::string tempSource;
    165         compiler.GetObjectModule().meta.GetDelegates().GenerateSourceCode( tempSource );
     165        std::string tempSource = ActiveBasic::Compiler::LexicalAnalyzer::GenerateDelegatesSourceCode(
     166            compiler.GetObjectModule().meta.GetDelegates()
     167        );
    166168        AddSourceCode( tempSource.c_str() );
    167169    }
     
    183185    型情報に依存するパラメータ情報を取得できないため、ここでの再取得が必要
    184186    */
    185     compiler.GetObjectModule().meta.GetDelegates().RefleshParameterAndReturnType();
     187    ActiveBasic::Compiler::LexicalAnalyzer::RefleshDelegatesParameterAndReturnType(
     188        compiler.GetObjectModule().meta.GetDelegates()
     189    );
    186190
    187191    //定数情報を取得
  • trunk/ab5.0/abdev/compiler_x86/compiler_x86.vcproj

    r514 r525  
    12611261                </File>
    12621262                <File
     1263                    RelativePath="..\BasicCompiler_Common\src\LexicalAnalyzer_Delegate.cpp"
     1264                    >
     1265                </File>
     1266                <File
    12631267                    RelativePath="..\BasicCompiler_Common\src\Linker.cpp"
    12641268                    >
     
    12721276                    >
    12731277                    <File
    1274                         RelativePath="..\BasicCompiler_Common\src\Class.cpp"
    1275                         >
    1276                     </File>
    1277                     <File
    12781278                        RelativePath="..\BasicCompiler_Common\src\Const.cpp"
    12791279                        >
     
    13081308                    </File>
    13091309                    <File
    1310                         RelativePath="..\BasicCompiler_Common\src\Method.cpp"
    1311                         >
    1312                     </File>
    1313                     <File
    13141310                        RelativePath="..\BasicCompiler_Common\src\NativeCode.cpp"
    13151311                        >
     
    13451341                    <File
    13461342                        RelativePath="..\BasicCompiler_Common\src\Source.cpp"
    1347                         >
    1348                     </File>
    1349                     <File
    1350                         RelativePath="..\BasicCompiler_Common\src\Type.cpp"
    13511343                        >
    13521344                    </File>
     
    14771469                    >
    14781470                    <File
    1479                         RelativePath="..\BasicCompiler_Common\include\Class.h"
    1480                         >
    1481                     </File>
    1482                     <File
    14831471                        RelativePath="..\BasicCompiler_Common\include\Const.h"
    14841472                        >
     
    15091497                    </File>
    15101498                    <File
    1511                         RelativePath="..\BasicCompiler_Common\include\Member.h"
    1512                         >
    1513                     </File>
    1514                     <File
    15151499                        RelativePath="..\BasicCompiler_Common\include\Meta.h"
    15161500                        >
    15171501                    </File>
    15181502                    <File
    1519                         RelativePath="..\BasicCompiler_Common\include\Method.h"
    1520                         >
    1521                     </File>
    1522                     <File
    15231503                        RelativePath="..\BasicCompiler_Common\include\NativeCode.h"
    15241504                        >
     
    15381518                    <File
    15391519                        RelativePath="..\BasicCompiler_Common\include\Source.h"
    1540                         >
    1541                     </File>
    1542                     <File
    1543                         RelativePath="..\BasicCompiler_Common\include\Type.h"
    15441520                        >
    15451521                    </File>
  • trunk/ab5.0/abdev/compiler_x86/stdafx.h

    r524 r525  
    5555#include <Variable.h>
    5656#include <Procedure.h>
    57 #include <LexicalAnalyzer.h>
    5857#include <Program.h>
    5958#include <TypeDef.h>
     
    6463#include <Exception.h>
    6564#include <Meta.h>
     65
    6666#include <CodeGenerator.h>
    6767#include <Messenger.h>
     
    7171#include <Debugger.h>
    7272#include <Program.h>
     73#include <LexicalAnalyzer.h>
Note: See TracChangeset for help on using the changeset viewer.