Changeset 400 in dev for trunk/abdev
- Timestamp:
- Feb 27, 2008, 5:21:00 PM (17 years ago)
- Location:
- trunk/abdev
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler32/BasicCompiler.vcproj
r376 r400 516 516 </FileConfiguration> 517 517 </File> 518 <File 519 RelativePath="..\BasicCompiler_Common\StrOperation.h" 520 > 521 </File> 518 522 <Filter 519 523 Name="Intermediate" -
trunk/abdev/BasicCompiler64/BasicCompiler.vcproj
r377 r400 1073 1073 > 1074 1074 </File> 1075 <File 1076 RelativePath="..\BasicCompiler_Common\StrOperation.h" 1077 > 1078 </File> 1075 1079 <Filter 1076 1080 Name="Intermediate" -
trunk/abdev/BasicCompiler_Common/StrOperation.cpp
r387 r400 505 505 } 506 506 } 507 508 509 bool IsVariableTopChar(char c){ 510 if((c>='A'&&c<='Z')||(c>='a'&&c<='z')||c=='_') 511 { 512 return true; 513 } 514 return false; 515 } 516 bool IsVariableChar( char c, bool isGenericsChars ){ 517 if((c>='A'&&c<='Z')||(c>='a'&&c<='z')||(c>='0'&&c<='9')|| 518 c=='%'||c=='!'||c=='#'||c=='$'|| 519 c=='_'||c=='.') 520 { 521 return true; 522 } 523 524 if( isGenericsChars ) 525 { 526 if( c == '<' || c == '>' ) 527 { 528 return true; 529 } 530 } 531 532 return false; 533 } 534 bool IsBlank(char c){ 535 if(c==' '||c=='\t') return 1; 536 return 0; 537 } 538 int GetOneParameter(const char *Parameter,int pos,char *retAns){ 539 int i,i2,i3,IsStr; 540 for(i=pos,i2=0,IsStr=0;;i++,i2++){ 541 if(Parameter[i]=='\"') IsStr^=1; 542 else if(Parameter[i]=='('&&IsStr==0){ 543 i3=GetStringInPare(retAns+i2,Parameter+i); 544 i+=i3-1; 545 i2+=i3-1; 546 continue; 547 } 548 else if(Parameter[i]=='['&&IsStr==0){ 549 i3=GetStringInBracket(retAns+i2,Parameter+i); 550 i+=i3-1; 551 i2+=i3-1; 552 continue; 553 } 554 else if(Parameter[i]==','&&IsStr==0){ 555 retAns[i2]=0; 556 i++; 557 break; 558 } 559 560 if(IsCommandDelimitation(Parameter[i])&&IsStr==0 561 || Parameter[i] == ')' && IsStr == 0 ){ 562 retAns[i2]=0; 563 break; 564 } 565 566 retAns[i2]=Parameter[i]; 567 } 568 return i; 569 } 570 int JumpOneParameter(char *Parameter,int i){ 571 int i2,IsStr; 572 for(i2=0,IsStr=0;;i++,i2++){ 573 if(Parameter[i]=='\"') IsStr^=1; 574 else if(Parameter[i]=='('&&IsStr==0){ 575 i=JumpStringInPare(Parameter,i+1); 576 continue; 577 } 578 else if(Parameter[i]=='['&&IsStr==0){ 579 i=JumpStringInBracket(Parameter,i+1); 580 continue; 581 } 582 else if(Parameter[i]==','&&IsStr==0){ 583 i++; 584 break; 585 } 586 if(IsCommandDelimitation(Parameter[i])) break; 587 } 588 return i; 589 } 590 int GetStringInQuotation(char *buffer,char *ReadBuffer){ 591 int i; 592 593 if(ReadBuffer[0]=='\"'){ 594 buffer[0]=ReadBuffer[0]; 595 i=1; 596 } 597 else i=0; 598 599 for(;;i++){ 600 buffer[i]=ReadBuffer[i]; 601 if(IsDBCSLeadByte(ReadBuffer[i])){ 602 i++; 603 buffer[i]=ReadBuffer[i]; 604 continue; 605 } 606 if(ReadBuffer[i]=='\"'){ 607 i++; 608 buffer[i]=0; 609 break; 610 } 611 if(ReadBuffer[i]=='\0') return 0; 612 } 613 return i; 614 } 615 int GetStringInPare( char *buffer, const char *ReadBuffer, bool isRemovePare ){ 616 int i,IsStr,PareNum; 617 for(i=0,IsStr=0,PareNum=0;;i++){ 618 buffer[i]=ReadBuffer[i]; 619 if(IsDBCSLeadByte(ReadBuffer[i])){ 620 i++; 621 buffer[i]=ReadBuffer[i]; 622 continue; 623 } 624 if(ReadBuffer[i]=='\"') IsStr^=1; 625 else if(ReadBuffer[i]=='('&&IsStr==0) PareNum++; 626 else if(ReadBuffer[i]==')'&&IsStr==0){ 627 PareNum--; 628 if(PareNum==0){ 629 i++; 630 buffer[i]=0; 631 break; 632 } 633 } 634 else if(ReadBuffer[i]=='\0') return 0; 635 } 636 637 if( isRemovePare ) 638 { 639 RemoveStringPare( buffer ); 640 } 641 642 return i; 643 } 644 int GetStringInBracket(char *buffer,const char *ReadBuffer){ 645 int i,IsStr,PareNum; 646 for(i=0,IsStr=0,PareNum=0;;i++){ 647 buffer[i]=ReadBuffer[i]; 648 if(IsDBCSLeadByte(ReadBuffer[i])){ 649 i++; 650 buffer[i]=ReadBuffer[i]; 651 continue; 652 } 653 if(ReadBuffer[i]=='\"') IsStr^=1; 654 else if(ReadBuffer[i]=='['&&IsStr==0) PareNum++; 655 else if(ReadBuffer[i]==']'&&IsStr==0){ 656 PareNum--; 657 if(PareNum==0){ 658 i++; 659 buffer[i]=0; 660 break; 661 } 662 } 663 else if(ReadBuffer[i]=='\0') return 0; 664 } 665 return i; 666 } 667 int GetStringInGenericBracket(char *buffer,const char *ReadBuffer){ 668 int i,IsStr,PareNum; 669 for(i=0,IsStr=0,PareNum=0;;i++){ 670 buffer[i]=ReadBuffer[i]; 671 if(IsDBCSLeadByte(ReadBuffer[i])){ 672 i++; 673 buffer[i]=ReadBuffer[i]; 674 continue; 675 } 676 if(ReadBuffer[i]=='\"') IsStr^=1; 677 else if(ReadBuffer[i]=='<'&&IsStr==0) PareNum++; 678 else if(ReadBuffer[i]=='>'&&IsStr==0){ 679 PareNum--; 680 if(PareNum==0){ 681 i++; 682 buffer[i]=0; 683 break; 684 } 685 } 686 else if(ReadBuffer[i]=='\0') return 0; 687 } 688 return i; 689 } 690 int JumpStringInPare(const char *buffer,int pos){ 691 int PareNum; 692 for(PareNum=1;;pos++){ 693 if(buffer[pos]=='\"'){ 694 for(pos++;;pos++){ 695 if(buffer[pos]=='\"') break; 696 } 697 continue; 698 } 699 else if(buffer[pos]=='(') PareNum++; 700 else if(buffer[pos]==')'){ 701 PareNum--; 702 if(PareNum==0) return pos; 703 } 704 else if(buffer[pos]=='\0') break; 705 } 706 return 0; 707 } 708 int JumpStringInBracket(const char *buffer,int pos){ 709 int PareNum; 710 for(PareNum=1;;pos++){ 711 if(buffer[pos]=='\"'){ 712 for(pos++;;pos++){ 713 if(buffer[pos]=='\"') break; 714 } 715 continue; 716 } 717 else if(buffer[pos]=='[') PareNum++; 718 else if(buffer[pos]==']'){ 719 PareNum--; 720 if(PareNum==0) return pos; 721 } 722 else if(buffer[pos]=='\0') break; 723 } 724 return 0; 725 } 726 bool IsCommandDelimitation( char c ){ 727 if( c == '\n' || c == ':' || c == '\0' ){ 728 return true; 729 } 730 731 return false; 732 } 733 734 int GetStringInPare_RemovePare(char *buffer,const char *ReadBuffer){ 735 int i,IsStr,PareNum; 736 for(i=0,IsStr=0,PareNum=1;;i++){ 737 buffer[i]=ReadBuffer[i]; 738 if(IsDBCSLeadByte(ReadBuffer[i])){ 739 i++; 740 buffer[i]=ReadBuffer[i]; 741 continue; 742 } 743 if(ReadBuffer[i]=='\"') IsStr^=1; 744 else if(ReadBuffer[i]=='('&&IsStr==0) PareNum++; 745 else if(ReadBuffer[i]==')'&&IsStr==0){ 746 PareNum--; 747 if(PareNum==0){ 748 buffer[i]=0; 749 break; 750 } 751 } 752 else if(ReadBuffer[i]=='\0') return 0; 753 } 754 return i; 755 } 756 757 void SplitParameter( const std::string &src, Jenga::Common::Strings &dests, bool isClear ) 758 { 759 const char *buffer = src.c_str(); 760 int i = 0; 761 762 if( isClear ) 763 { 764 dests.clear(); 765 } 766 767 while( buffer[i] ) 768 { 769 char result[8192]; 770 i = GetOneParameter( buffer, i, result ); 771 dests.push_back( result ); 772 } 773 } 774 775 776 bool SplitMemberName( const char *desc, char *object, char *member, ReferenceKind &refType ){ 777 int lastIndex = -1; 778 for( int i=0; desc[i]; i++ ){ 779 if( desc[i] == '(' ){ 780 i=JumpStringInPare(desc,i+1); 781 continue; 782 } 783 else if( desc[i] == '[' ){ 784 i=JumpStringInBracket(desc,i+1); 785 continue; 786 } 787 else if(desc[i]=='.'||(desc[i]==1&&desc[i+1]==ESC_PSMEM)){ 788 lastIndex = i; 789 } 790 } 791 if( lastIndex == -1 ){ 792 if( object ) 793 { 794 object[0] = 0; 795 } 796 lstrcpy( member, desc ); 797 return false; 798 } 799 800 if(desc[lastIndex]=='.'){ 801 lstrcpy(member,desc+lastIndex+1); 802 refType = RefDot; 803 } 804 else{ 805 lstrcpy(member,desc+lastIndex+2); 806 refType = RefPointer; 807 } 808 809 if( object ){ 810 lstrcpy( object, desc ); 811 object[lastIndex]=0; 812 } 813 814 return true; 815 } 816 bool SplitMemberName( const char *desc, char *object, char *member ){ 817 ReferenceKind dummyRefType; 818 return SplitMemberName( desc, object, member, dummyRefType ); 819 } 820 821 void SplitSyntacticForAs( const char *src, char *varName, char *typeName) 822 { 823 int i = 0; 824 for( ; ; i++ ) 825 { 826 if( src[i] == '\0' || src[i] == 1 && src[i+1] == ESC_AS ) 827 { 828 varName[i] = 0; 829 break; 830 } 831 varName[i] = src[i]; 832 } 833 834 if( src[i] ) 835 { 836 lstrcpy( typeName, src + i + 2 ); 837 } 838 else 839 { 840 typeName[i] = 0; 841 } 842 } 843 844 char *calcNames[255] = { 845 "xor", 846 }; 847 void InitCalcNames() 848 { 849 if( calcNames[CALC_XOR] ) 850 { 851 return; 852 } 853 854 memset( calcNames, 0, 255 * sizeof(char *) ); 855 calcNames[CALC_XOR] = "xor"; 856 calcNames[CALC_OR] = "or"; 857 calcNames[CALC_AND] = "and"; 858 calcNames[CALC_NOT] = "Not"; 859 calcNames[CALC_PE] = "<="; 860 calcNames[CALC_QE] = ">="; 861 calcNames[CALC_NOTEQUAL] = "<>"; 862 calcNames[CALC_EQUAL] = "=(compare)"; 863 calcNames[CALC_P] = "<"; 864 calcNames[CALC_Q] = ">"; 865 calcNames[CALC_SHL] = "<<"; 866 calcNames[CALC_SHR] = ">>"; 867 calcNames[CALC_ADDITION] = "+"; 868 calcNames[CALC_SUBTRACTION] = "-"; 869 calcNames[CALC_STRPLUS] = "&"; 870 calcNames[CALC_MOD] = "mod"; 871 calcNames[CALC_PRODUCT] = "*"; 872 calcNames[CALC_QUOTIENT] = "/"; 873 calcNames[CALC_INTQUOTIENT] = "\\"; 874 calcNames[CALC_AS] = "As"; 875 calcNames[CALC_BYVAL] = "ByVal"; 876 calcNames[CALC_MINUSMARK] = "-(mark)"; 877 calcNames[CALC_POWER] = "^"; 878 calcNames[CALC_SUBSITUATION] = "="; 879 calcNames[CALC_ARRAY_GET] = "[]"; 880 calcNames[CALC_ARRAY_SET] = "[]="; 881 } 882 void GetCalcName(int idCalc,char *name){ 883 InitCalcNames(); 884 885 if( calcNames[idCalc] == NULL ) 886 { 887 SetError(); 888 } 889 lstrcpy( name, calcNames[idCalc] ); 890 } 891 BYTE ToCalcId( const char *name ) 892 { 893 InitCalcNames(); 894 895 for( int i=0; i<255; i++ ) 896 { 897 if( calcNames[i] ) 898 { 899 if( lstrcmp( name, calcNames[i] ) == 0 ) 900 { 901 return i; 902 } 903 } 904 } 905 SetError(); 906 return 0; 907 } 908 909 std::string Operator_NaturalStringToCalcMarkString( const std::string &name ) 910 { 911 if( name[0] == 1 && name[1] == ESC_OPERATOR ) 912 { 913 BYTE calcId = ToCalcId( name.c_str()+2 ); 914 char temporary[255]; 915 temporary[0] = name[0]; 916 temporary[1] = name[1]; 917 temporary[2] = calcId; 918 temporary[3] = 0; 919 return temporary; 920 } 921 return name; 922 } 923 std::string Operator_CalcMarkStringToNaturalString( const std::string &name ) 924 { 925 if( name[0] == 1 && name[1] == ESC_OPERATOR ) 926 { 927 BYTE calcId = name[2]; 928 char temporary[255], calcName[255]; 929 GetCalcName( calcId, calcName ); 930 temporary[0] = name[0]; 931 temporary[1] = name[1]; 932 lstrcpy( temporary+2, calcName ); 933 return temporary; 934 } 935 return name; 936 } 937 938 bool IsGenericTypeSourcePart( const char *buffer ) 939 { 940 if( buffer[0] != '<' ) 941 { 942 Jenga::Throw( "意図しない文字列に対してIsGenericTypeSourcePart関数が呼ばれた" ); 943 return false; 944 } 945 946 int i=1, scopeCount=1; 947 for( ; ; i++ ) 948 { 949 if( buffer[i] == '\0' ) 950 { 951 break; 952 } 953 if( buffer[i] == '<' ) 954 { 955 scopeCount++; 956 } 957 else if( buffer[i] == '>' ) 958 { 959 scopeCount--; 960 961 if( scopeCount == 0 ) 962 { 963 break; 964 } 965 } 966 } 967 968 if( buffer[i] != '>' ) 969 { 970 return false; 971 } 972 973 974 ///////////////////////////////////////////////////////////////// 975 // '>'に続く文字を判定する 976 ///////////////////////////////////////////////////////////////// 977 978 i++; 979 while( IsBlank( buffer[i] ) ) 980 { 981 i++; 982 } 983 984 if( IsVariableChar( buffer[i] ) ) 985 { 986 return false; 987 } 988 989 return true; 990 } -
trunk/abdev/BasicCompiler_Common/common.h
r393 r400 205 205 206 206 #include "../BasicCompiler_Common/PESchedule.h" 207 #include "../BasicCompiler_Common/StrOperation.h" 207 208 #include "../BasicCompiler_Common/VariableOpe.h" 208 209 -
trunk/abdev/BasicCompiler_Common/src/Procedure.cpp
r397 r400 110 110 } 111 111 } 112 113 /* 114 GetStringInPare( temporary, sourceOfParams + i ); 115 RemoveStringPare( temporary ); 116 */ 117 112 118 while(1){ 113 119 if(sourceOfParams[i]==')') break;
Note:
See TracChangeset
for help on using the changeset viewer.