Changeset 68 for branches/Transpascal/Compiler
- Timestamp:
- Oct 18, 2010, 2:14:52 PM (15 years ago)
- Location:
- branches/Transpascal/Compiler
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Transpascal/Compiler/Analyze/UParser.pas
r67 r68 83 83 procedure ParseTypeList(SourceCode: TTypeList; Exported: Boolean = False); 84 84 function ParseType(TypeList: TTypeList; ExpectName: Boolean = True; AssignSymbol: string = '='): TType; 85 function ParseTypeEnumeration(TypeList: TTypeList; Name: string): TType; 86 function ParseTypeRecord(TypeList: TTypeList; Name: string): TType; 85 87 property OnGetSource: TGetSourceEvent read FOnGetSource 86 88 write FOnGetSource; … … 744 746 begin 745 747 with SourceCode do begin 746 while FNextToken <> 'implementation'do begin748 while (FNextToken <> 'implementation') and (FNextTokenType <> ttEndOfFile) do begin 747 749 if FNextToken = 'var' then 748 750 ParseVariableList(Variables) … … 755 757 else if FNextToken = 'function' then 756 758 ParseFunctionList(Functions, True) 757 else ErrorMessage(SUnknownIdentifier, [FNextToken]); 759 else begin 760 ErrorMessage(SUnknownIdentifier, [FNextToken]); 761 ReadCode; 762 end; 758 763 end; 759 764 end; … … 1071 1076 end; 1072 1077 if NextToken = '(' then begin 1073 // Enumeration 1074 Expect('('); 1075 Result := TTypeEnumeration.Create; 1076 TTypeEnumeration(Result).Parent := TypeList; 1077 TTypeEnumeration(Result).Name := Name; 1078 with TTypeEnumeration(Result) do 1079 with TEnumItem(Items[Items.Add(TEnumItem.Create)]) do begin 1080 Name := ReadCode; 1081 if (NextToken = '=') and (FNextTokenType = ttConstantNumber) then begin 1082 Expect('='); 1083 Index := StrToInt(ReadCode); 1084 end; 1085 end; 1086 while (NextToken = ',') and (FNextTokenType <> ttEndOfFile) do 1087 begin 1088 Expect(','); 1089 with TTypeEnumeration(Result) do 1090 with TEnumItem(Items[Items.Add(TEnumItem.Create)]) do begin 1091 Name := ReadCode; 1092 if (NextToken = '=') and (FNextTokenType = ttConstantNumber) then begin 1093 Expect('='); 1094 Index := StrToInt(ReadCode); 1095 end; 1096 end; 1097 end; 1098 Expect(')'); 1078 Result := ParseTypeEnumeration(TypeList, Name); 1099 1079 end else 1100 1080 if NextToken = 'record' then begin 1101 Expect('record'); 1102 Result := TTypeRecord.Create; 1103 TTypeRecord(Result).Parent := TypeList; 1104 TType(Result).Name := Name; 1105 while (NextToken <> 'end') and (FNextTokenType <> ttEndOfFile) do 1106 begin 1107 TTypeRecord(Result).Items.Add(ParseType(TypeList, True, ':')); 1108 Expect(';'); 1109 end; 1110 Expect('end'); 1081 Result := ParseTypeRecord(TypeList, Name); 1111 1082 end else 1112 1083 if NextToken = 'class' then begin … … 1178 1149 end; 1179 1150 1151 function TPascalParser.ParseTypeEnumeration(TypeList: TTypeList; Name: string): TType; 1152 begin 1153 Expect('('); 1154 Result := TTypeEnumeration.Create; 1155 TTypeEnumeration(Result).Parent := TypeList; 1156 TTypeEnumeration(Result).Name := Name; 1157 with TTypeEnumeration(Result) do 1158 with TEnumItem(Items[Items.Add(TEnumItem.Create)]) do begin 1159 Name := ReadCode; 1160 if (NextToken = '=') and (FNextTokenType = ttConstantNumber) then begin 1161 Expect('='); 1162 Index := StrToInt(ReadCode); 1163 end; 1164 end; 1165 while (NextToken = ',') and (FNextTokenType <> ttEndOfFile) do 1166 begin 1167 Expect(','); 1168 with TTypeEnumeration(Result) do 1169 with TEnumItem(Items[Items.Add(TEnumItem.Create)]) do begin 1170 Name := ReadCode; 1171 if (NextToken = '=') and (FNextTokenType = ttConstantNumber) then begin 1172 Expect('='); 1173 Index := StrToInt(ReadCode); 1174 end; 1175 end; 1176 end; 1177 Expect(')'); 1178 end; 1179 1180 function TPascalParser.ParseTypeRecord(TypeList: TTypeList; Name: string 1181 ): TType; 1182 var 1183 Visibility: TTypeVisibility; 1184 begin 1185 Visibility := tvPublic; 1186 Expect('record'); 1187 Result := TTypeRecord.Create; 1188 TTypeRecord(Result).Parent := TypeList; 1189 TType(Result).Name := Name; 1190 while (NextToken <> 'end') and (FNextTokenType <> ttEndOfFile) do 1191 begin 1192 if NextToken = 'public' then begin 1193 Expect('public'); 1194 Visibility := tvPublic; 1195 end else 1196 if NextToken = 'private' then begin 1197 Expect('private'); 1198 Visibility := tvPrivate; 1199 end else 1200 if NextToken = 'published' then begin 1201 Expect('published'); 1202 Visibility := tvPublished; 1203 end else 1204 if NextToken = 'protected' then begin 1205 Expect('protected'); 1206 Visibility := tvProtected; 1207 end else 1208 if NextToken = 'var' then 1209 ParseVariableList(TTypeRecord(Result).CommonBlock.Variables) 1210 else if FNextToken = 'const' then 1211 ParseConstantList(TTypeRecord(Result).CommonBlock.Constants, True) 1212 else if FNextToken = 'type' then 1213 ParseTypeList(TTypeRecord(Result).CommonBlock.Types, True) 1214 else if FNextToken = 'procedure' then 1215 ParseFunctionList(TTypeRecord(Result).CommonBlock.Functions, True) 1216 else if FNextToken = 'function' then 1217 ParseFunctionList(TTypeRecord(Result).CommonBlock.Functions, True) 1218 else begin 1219 TTypeRecord(Result).CommonBlock.Types.Add(ParseType(TypeList, True, ':')); 1220 TType(TTypeRecord(Result).CommonBlock.Types.Last).Visibility := Visibility; 1221 end; 1222 Expect(';'); 1223 end; 1224 Expect('end'); 1225 end; 1226 1180 1227 constructor TPascalParser.Create; 1181 1228 begin -
branches/Transpascal/Compiler/Produce/UProducerC.pas
r67 r68 299 299 Emit('{'); 300 300 Inc(Indetation); 301 for I := 0 to TTypeRecord(AType). Items.Count - 1 do begin302 GenerateType(TType(TTypeRecord(AType). Items[I]));301 for I := 0 to TTypeRecord(AType).CommonBlock.Types.Count - 1 do begin 302 GenerateType(TType(TTypeRecord(AType).CommonBlock.Types[I])); 303 303 Emit(';'); 304 304 end; -
branches/Transpascal/Compiler/Produce/UProducerPascal.pas
r60 r68 109 109 Emit(AType.Name + ' ' + AssignSymbol + ' record'); 110 110 Inc(Indetation); 111 for I := 0 to TTypeRecord(AType). Items.Count - 1 do begin112 GenerateType(TType(TTypeRecord(AType). Items[I]));111 for I := 0 to TTypeRecord(AType).CommonBlock.Types.Count - 1 do begin 112 GenerateType(TType(TTypeRecord(AType).CommonBlock.Types[I])); 113 113 Emit(';'); 114 114 end; -
branches/Transpascal/Compiler/Produce/UProducerTreeView.pas
r60 r68 298 298 I: Integer; 299 299 begin 300 if TypeRecord. Items.Count > 0 then begin301 for I := 0 to TypeRecord. Items.Count - 1 do302 with TType(TypeRecord. Items[I]) do300 if TypeRecord.CommonBlock.Types.Count > 0 then begin 301 for I := 0 to TypeRecord.CommonBlock.Types.Count - 1 do 302 with TType(TypeRecord.CommonBlock.Types[I]) do 303 303 if not System then 304 AddNodeType(Node, TType(TypeRecord. Items[I]));304 AddNodeType(Node, TType(TypeRecord.CommonBlock.Types[I])); 305 305 end; 306 306 end; -
branches/Transpascal/Compiler/USourceCode.pas
r65 r68 15 15 16 16 TNodeType = (ntNone, ntVariable, ntFunction, ntConstant, ntOperator); 17 18 TTypeVisibility = (tvPublic, tvPublished, tvPrivate, tvProtected); 17 19 18 20 TValue = Variant; //array of Byte; … … 156 158 Size: Integer; 157 159 UsedType: TType; 160 Visibility: TTypeVisibility; 158 161 end; 159 162 … … 162 165 163 166 TTypeRecord = class(TType) 164 Items: TObjectList; // TObjectList<TType>167 CommonBlock: TCommonBlock; 165 168 constructor Create; 166 169 destructor Destroy; override; … … 714 717 begin 715 718 inherited; 716 Items := TObjectList.Create;719 CommonBlock := TCommonBlock.Create; 717 720 end; 718 721 719 722 destructor TTypeRecord.Destroy; 720 723 begin 721 Items.Free;724 CommonBlock.Free; 722 725 inherited Destroy; 723 726 end;
Note:
See TracChangeset
for help on using the changeset viewer.