[543] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
| 3 | using namespace ActiveBasic::Compiler;
|
---|
| 4 |
|
---|
| 5 | void LexicalAnalyzer::AddConstEnum( Consts &consts, const NamespaceScopes &namespaceScopes, const char *buffer )
|
---|
| 6 | {
|
---|
| 7 | extern int cp;
|
---|
| 8 | int i=0,i2;
|
---|
| 9 |
|
---|
| 10 | if(!(buffer[i]==1&&buffer[i+1]==ESC_ENUM)) return;
|
---|
| 11 | i+=2;
|
---|
| 12 |
|
---|
| 13 | //列挙体の名前を取得
|
---|
| 14 | char temporary[VN_SIZE];
|
---|
| 15 | for(i2=0;;i++,i2++){
|
---|
| 16 | if(IsCommandDelimitation(buffer[i])){
|
---|
| 17 | temporary[i2]=0;
|
---|
| 18 | break;
|
---|
| 19 | }
|
---|
| 20 | if(!IsVariableChar(buffer[i])){
|
---|
| 21 | compiler.errorMessenger.Output(1,NULL,i);
|
---|
| 22 | break;
|
---|
| 23 | }
|
---|
| 24 | temporary[i2]=buffer[i];
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | if(buffer[i]=='\0'){
|
---|
| 28 | compiler.errorMessenger.Output(22,"Enum",cp);
|
---|
| 29 | return;
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | int NextValue=0;
|
---|
| 33 | while(1){
|
---|
| 34 | i++;
|
---|
| 35 |
|
---|
| 36 | if(buffer[i]==1&&buffer[i+1]==ESC_ENDENUM) break;
|
---|
| 37 |
|
---|
| 38 | for(i2=0;;i2++,i++){
|
---|
| 39 | if(IsCommandDelimitation(buffer[i])){
|
---|
| 40 | temporary[i2]=0;
|
---|
| 41 | break;
|
---|
| 42 | }
|
---|
| 43 | if(buffer[i]=='='){
|
---|
| 44 | temporary[i2]=0;
|
---|
| 45 | break;
|
---|
| 46 | }
|
---|
| 47 | temporary[i2]=buffer[i];
|
---|
| 48 | }
|
---|
| 49 | if(temporary[0]=='\0'){
|
---|
| 50 | if(buffer[i]=='\0'){
|
---|
| 51 | compiler.errorMessenger.Output(22,"Enum",cp);
|
---|
| 52 | break;
|
---|
| 53 | }
|
---|
| 54 | continue;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | if(buffer[i]!='='){
|
---|
| 58 | NextValue++;
|
---|
| 59 | }
|
---|
| 60 | else{
|
---|
| 61 | char temp2[VN_SIZE];
|
---|
| 62 | for(i++,i2=0;;i2++,i++){
|
---|
| 63 | if(IsCommandDelimitation(buffer[i])){
|
---|
| 64 | temp2[i2]=0;
|
---|
| 65 | break;
|
---|
| 66 | }
|
---|
| 67 | temp2[i2]=buffer[i];
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | _int64 i64data;
|
---|
| 71 | StaticCalculation(true, temp2,DEF_LONG,&i64data,Type());
|
---|
| 72 | NextValue=(int)i64data;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | //定数を追加
|
---|
| 76 | consts.Add( namespaceScopes, temporary, NextValue);
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | void LexicalAnalyzer::CollectConsts( const char *source, Consts &consts, ConstMacros &constMacros )
|
---|
| 81 | {
|
---|
| 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 | for(int i=0;;i++){
|
---|
| 94 | if( source[i] == '\0' ) break;
|
---|
| 95 |
|
---|
| 96 | if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){
|
---|
| 97 | for(i+=2,i2=0;;i2++,i++){
|
---|
| 98 | if( IsCommandDelimitation( source[i] ) ){
|
---|
| 99 | temporary[i2]=0;
|
---|
| 100 | break;
|
---|
| 101 | }
|
---|
| 102 | temporary[i2]=source[i];
|
---|
| 103 | }
|
---|
| 104 | namespaceScopes.push_back( temporary );
|
---|
| 105 |
|
---|
| 106 | continue;
|
---|
| 107 | }
|
---|
| 108 | else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){
|
---|
| 109 | if( namespaceScopes.size() <= 0 ){
|
---|
| 110 | compiler.errorMessenger.Output(12, "End Namespace", i );
|
---|
| 111 | }
|
---|
| 112 | else{
|
---|
| 113 | namespaceScopes.pop_back();
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | i += 2;
|
---|
| 117 | continue;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | if( source[i] == 1 ){
|
---|
| 121 | if(source[i]==1&&source[i+1]==ESC_CONST){
|
---|
| 122 | i+=2;
|
---|
| 123 |
|
---|
| 124 | extern int cp;
|
---|
| 125 | cp=i; //エラー用
|
---|
| 126 |
|
---|
| 127 |
|
---|
| 128 | if(source[i]==1&&source[i+1]==ESC_ENUM){
|
---|
| 129 | AddConstEnum( consts, namespaceScopes, source+i);
|
---|
| 130 | continue;
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | for(i2=0;;i++,i2++){
|
---|
| 134 | if(source[i]=='\"'){
|
---|
| 135 | temporary[i2]=source[i];
|
---|
| 136 | for(i++,i2++;;i++,i2++){
|
---|
| 137 | temporary[i2]=source[i];
|
---|
| 138 | if(source[i]=='\"') break;
|
---|
| 139 | }
|
---|
| 140 | continue;
|
---|
| 141 | }
|
---|
| 142 | if(IsCommandDelimitation(source[i])){
|
---|
| 143 | temporary[i2]=0;
|
---|
| 144 | break;
|
---|
| 145 | }
|
---|
| 146 | temporary[i2]=source[i];
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | //名前を取得
|
---|
| 150 | char name[VN_SIZE];
|
---|
| 151 | for(i2=0;;i2++){
|
---|
| 152 | if(temporary[i2]=='\0'){
|
---|
| 153 | compiler.errorMessenger.Output(10,"Const",cp);
|
---|
| 154 | return;
|
---|
| 155 | }
|
---|
| 156 | if(temporary[i2]=='='||temporary[i2]=='('){
|
---|
| 157 | name[i2]=0;
|
---|
| 158 | break;
|
---|
| 159 | }
|
---|
| 160 | name[i2]=temporary[i2];
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | //重複チェック
|
---|
| 164 | if( compiler.GetObjectModule().meta.GetGlobalConstMacros().IsExist( name )
|
---|
| 165 | || compiler.GetObjectModule().meta.GetGlobalConsts().IsExist( name ) )
|
---|
| 166 | {
|
---|
| 167 | compiler.errorMessenger.Output(15,name,cp);
|
---|
| 168 | return;
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | if( temporary[i2] == '=' )
|
---|
| 172 | {
|
---|
| 173 | // 定数
|
---|
| 174 | const char *expression = temporary + i2 + 1;
|
---|
| 175 | consts.Add( namespaceScopes, name, expression );
|
---|
| 176 | }
|
---|
| 177 | else
|
---|
| 178 | {
|
---|
| 179 | // 定数マクロ
|
---|
| 180 | const char *params = temporary + i2;
|
---|
| 181 | constMacros.Add( namespaceScopes, name, params );
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | if(source[i]=='\0') break;
|
---|
| 185 | }
|
---|
| 186 | else{
|
---|
| 187 | int result = JumpStatement( source, i );
|
---|
| 188 | if( result == -1 ){
|
---|
| 189 | //エラー
|
---|
| 190 | return;
|
---|
| 191 | }
|
---|
| 192 | else if( result == 1 ){
|
---|
| 193 | //ジャンプした場合
|
---|
| 194 | i--;
|
---|
| 195 | }
|
---|
| 196 | }
|
---|
| 197 | }
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | // イテレータを初期化
|
---|
| 201 | compiler.GetObjectModule().meta.GetGlobalConsts().Iterator_Init();
|
---|
| 202 | compiler.GetObjectModule().meta.GetGlobalConstMacros().Iterator_Init();
|
---|
| 203 | }
|
---|