Changeset 543 in dev for trunk


Ignore:
Timestamp:
May 4, 2008, 2:00:36 AM (16 years ago)
Author:
dai_9181
Message:

・GetConstInfo関数を廃止し、LexicalAnalyzer::CollectConstsメソッドを追加。

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

Legend:

Unmodified
Added
Removed
  • trunk/ab5.0/abdev/BasicCompiler_Common/Intermediate_Step2.cpp

    r465 r543  
    55#include "../BasicCompiler_Common/common.h"
    66
    7 
    8 void AddConstEnum( const NamespaceScopes &namespaceScopes, char *buffer){
    9     extern int cp;
    10     int i=0,i2;
    11 
    12     if(!(buffer[i]==1&&buffer[i+1]==ESC_ENUM)) return;
    13     i+=2;
    14 
    15     //列挙体の名前を取得
    16     char temporary[VN_SIZE];
    17     for(i2=0;;i++,i2++){
    18         if(IsCommandDelimitation(buffer[i])){
    19             temporary[i2]=0;
    20             break;
    21         }
    22         if(!IsVariableChar(buffer[i])){
    23             compiler.errorMessenger.Output(1,NULL,i);
    24             break;
    25         }
    26         temporary[i2]=buffer[i];
    27     }
    28 
    29     if(buffer[i]=='\0'){
    30         compiler.errorMessenger.Output(22,"Enum",cp);
    31         return;
    32     }
    33 
    34     int NextValue=0;
    35     while(1){
    36         i++;
    37 
    38         if(buffer[i]==1&&buffer[i+1]==ESC_ENDENUM) break;
    39 
    40         for(i2=0;;i2++,i++){
    41             if(IsCommandDelimitation(buffer[i])){
    42                 temporary[i2]=0;
    43                 break;
    44             }
    45             if(buffer[i]=='='){
    46                 temporary[i2]=0;
    47                 break;
    48             }
    49             temporary[i2]=buffer[i];
    50         }
    51         if(temporary[0]=='\0'){
    52             if(buffer[i]=='\0'){
    53                 compiler.errorMessenger.Output(22,"Enum",cp);
    54                 break;
    55             }
    56             continue;
    57         }
    58 
    59         if(buffer[i]!='='){
    60             NextValue++;
    61         }
    62         else{
    63             char temp2[VN_SIZE];
    64             for(i++,i2=0;;i2++,i++){
    65                 if(IsCommandDelimitation(buffer[i])){
    66                     temp2[i2]=0;
    67                     break;
    68                 }
    69                 temp2[i2]=buffer[i];
    70             }
    71 
    72             _int64 i64data;
    73             StaticCalculation(true, temp2,DEF_LONG,&i64data,Type());
    74             NextValue=(int)i64data;
    75         }
    76 
    77         //定数を追加
    78         compiler.GetObjectModule().meta.GetGlobalConsts().Add( namespaceScopes, temporary, NextValue);
    79     }
    80 }
    81 bool GetConstInfo(void){
    82     ////////////////////////////////////////////
    83     // Const命令の情報を取得
    84     ////////////////////////////////////////////
    85 
    86     int i2;
    87     char temporary[1024];
    88 
    89     // 名前空間管理
    90     NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
    91     namespaceScopes.clear();
    92 
    93     extern char *basbuf;
    94     for(int i=0;;i++){
    95         if( basbuf[i] == '\0' ) break;
    96 
    97         if( basbuf[i] == 1 && basbuf[i+1] == ESC_NAMESPACE ){
    98             for(i+=2,i2=0;;i2++,i++){
    99                 if( IsCommandDelimitation( basbuf[i] ) ){
    100                     temporary[i2]=0;
    101                     break;
    102                 }
    103                 temporary[i2]=basbuf[i];
    104             }
    105             namespaceScopes.push_back( temporary );
    106 
    107             continue;
    108         }
    109         else if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENDNAMESPACE ){
    110             if( namespaceScopes.size() <= 0 ){
    111                 compiler.errorMessenger.Output(12, "End Namespace", i );
    112             }
    113             else{
    114                 namespaceScopes.pop_back();
    115             }
    116 
    117             i += 2;
    118             continue;
    119         }
    120 
    121         if( basbuf[i] == 1 ){
    122             if(basbuf[i]==1&&basbuf[i+1]==ESC_CONST){
    123                 i+=2;
    124 
    125                 extern int cp;
    126                 cp=i;   //エラー用
    127 
    128 
    129                 if(basbuf[i]==1&&basbuf[i+1]==ESC_ENUM){
    130                     AddConstEnum( namespaceScopes, basbuf+i);
    131                     continue;
    132                 }
    133 
    134                 for(i2=0;;i++,i2++){
    135                     if(basbuf[i]=='\"'){
    136                         temporary[i2]=basbuf[i];
    137                         for(i++,i2++;;i++,i2++){
    138                             temporary[i2]=basbuf[i];
    139                             if(basbuf[i]=='\"') break;
    140                         }
    141                         continue;
    142                     }
    143                     if(IsCommandDelimitation(basbuf[i])){
    144                         temporary[i2]=0;
    145                         break;
    146                     }
    147                     temporary[i2]=basbuf[i];
    148                 }
    149                 AddConst( namespaceScopes, temporary);
    150                 if(basbuf[i]=='\0') break;
    151             }
    152             else{
    153                 int result = JumpStatement( basbuf, i );
    154                 if( result == -1 ){
    155                     //エラー
    156                     return false;
    157                 }
    158                 else if( result == 1 ){
    159                     //ジャンプした場合
    160                     i--;
    161                 }
    162             }
    163         }
    164     }
    165 
    166     // イテレータを初期化
    167     compiler.GetObjectModule().meta.GetGlobalConsts().Iterator_Init();
    168     compiler.GetObjectModule().meta.GetGlobalConstMacros().Iterator_Init();
    169 
    170     return true;
    171 }
    1727
    1738char ConstructorDestructorSchedule[MAX_PATH];
  • trunk/ab5.0/abdev/BasicCompiler_Common/common.h

    r523 r543  
    290290
    291291//Intermediate_Step2.cpp
    292 bool GetConstInfo(void);
    293292void ChangeCommandToCode(char *buffer);
    294293
  • trunk/ab5.0/abdev/BasicCompiler_Common/include/Const.h

    r524 r543  
    11#pragma once
    2 
    3 void AddConst( const NamespaceScopes &namespaceScopes, char *buffer );
    42
    53//定数
     
    7169public:
    7270
    73     void Add( const NamespaceScopes &namespaceScopes, char *buffer);
    74     void Add( const NamespaceScopes &namespaceScopes, const std::string &name, char *Expression);
     71    void Add( const NamespaceScopes &namespaceScopes, const std::string &name, const char *Expression);
    7572    void Add( const NamespaceScopes &namespaceScopes, const std::string &name, int value);
    7673
  • trunk/ab5.0/abdev/BasicCompiler_Common/include/LexicalAnalyzer.h

    r542 r543  
    3434    static void CollectTypeDefs( const char *source, TypeDefCollection &typeDefs );
    3535
     36    // 定数を収集する
     37    static void AddConstEnum( Consts &consts, const NamespaceScopes &namespaceScopes, const char *buffer );
     38    static void CollectConsts( const char *source, Consts &consts, ConstMacros &constMacros );
     39
    3640    // クラスを収集する
    3741    static void AddMethod(CClass *pobj_c, UserProc *pUserProc, Prototype::Accessibility accessibility, BOOL bStatic, bool isConst, bool isAbstract,
  • trunk/ab5.0/abdev/BasicCompiler_Common/src/Const.cpp

    r523 r543  
    1111}
    1212
    13 void AddConst( const NamespaceScopes &namespaceScopes, char *buffer ){
    14     int i;
    15 
    16     //名前を取得
    17     char name[VN_SIZE];
    18     for(i=0;;i++){
    19         if(buffer[i]=='\0'){
    20             compiler.errorMessenger.Output(10,"Const",cp);
    21             return;
    22         }
    23         if(buffer[i]=='='||buffer[i]=='('){
    24             name[i]=0;
    25             break;
    26         }
    27         name[i]=buffer[i];
    28     }
    29 
    30     //重複チェック
    31     if( compiler.GetObjectModule().meta.GetGlobalConstMacros().IsExist( name )
    32         || compiler.GetObjectModule().meta.GetGlobalConsts().IsExist( name ) )
    33     {
    34         compiler.errorMessenger.Output(15,name,cp);
    35         return;
    36     }
    37 
    38     if(buffer[i] == '('){
    39         //定数マクロ
    40 
    41         compiler.GetObjectModule().meta.GetGlobalConstMacros().Add( namespaceScopes, name, buffer + i );
    42     }
    43     else{
    44         //一般の定数
    45         char *expression = buffer + i + 1;
    46 
    47         compiler.GetObjectModule().meta.GetGlobalConsts().Add( namespaceScopes, name, expression );
    48     }
    49 }
    50 
    51 void Consts::Add( const NamespaceScopes &namespaceScopes, const std::string &name , char *Expression)
     13void Consts::Add( const NamespaceScopes &namespaceScopes, const std::string &name , const char *Expression)
    5214{
    5315    _int64 i64data;
  • trunk/ab5.0/abdev/compiler_x86/MakePeHdr.cpp

    r542 r543  
    190190
    191191    //定数情報を取得
    192     GetConstInfo();
     192    ActiveBasic::Compiler::LexicalAnalyzer::CollectConsts(
     193        compiler.GetObjectModule().GetCurrentSource().GetBuffer(),
     194        compiler.GetObjectModule().meta.GetGlobalConsts(),
     195        compiler.GetObjectModule().meta.GetGlobalConstMacros()
     196    );
    193197
    194198    // サブルーチン(ユーザー定義、DLL関数)の識別子、アドレスを取得
  • trunk/ab5.0/abdev/compiler_x86/compiler_x86.vcproj

    r529 r543  
    12611261                </File>
    12621262                <File
     1263                    RelativePath="..\BasicCompiler_Common\src\LexicalAnalyzer_Const.cpp"
     1264                    >
     1265                </File>
     1266                <File
    12631267                    RelativePath="..\BasicCompiler_Common\src\LexicalAnalyzer_Delegate.cpp"
    12641268                    >
Note: See TracChangeset for help on using the changeset viewer.