【发布时间】:2012-03-30 15:51:47
【问题描述】:
我有一个名为 Statements 的包,其中包含一个名为 Statement 的抽象类型和一个名为 execute() 的抽象函数。在另一个包中,我有一个 CompoundStatement 类型,它是一个 Statement 类型,它实现了 execute() 函数。
我有一个名为 createStatement() 的函数。它的目的是评估 Unbounded_String 类型的标记并确定它包含什么关键字。然后根据这个关键字生成一个基于这个关键字的访问类型。
到目前为止一切顺利。
但我不知道该怎么做是调用正确的执行方法。我现在只有一个关键字编码,因为它还没有工作。
对不起,如果我的描述听起来令人费解。
package Statements is
type Statement is abstract tagged private;
type Statement_Access is access all Statement'Class;
function execute(skip: in Boolean; T: in TokenHandler; S: in Statement) return Integer is abstract;
private
type Statement is abstract tagged
record
tokens: Vector;
end record;
end Statements;
procedure createStatement(T : in TokenHandler; stmt: out Statement_Access) is
currenttoken : Unbounded_String;
C : CompoundStatement;
begin
currenttoken := To_Unbounded_String(TokenHandlers.getCurrentToken(T));
if currenttoken = "begin" then
createCompoundStatement(T, C);
stmt := new CompoundStatement;
stmt.all := Statement'Class(C);
end if;
end createStatement;
procedure createCompoundStatement(T : in TokenHandler; C: out CompoundStatement) is
begin
C.tokens := T.tokens;
end createCompoundStatement;
function execute(skip: in Boolean; T: in TokenHandler; C: in CompoundStatement) return Integer is
TK: TokenHandler := T;
stmt: Statement_Access;
tokensexecuted: Integer;
currenttoken : Unbounded_String;
begin
TokenHandlers.match("begin", TK);
currenttoken := To_Unbounded_String(TokenHandlers.getCurrentToken(TK));
while(currenttoken /= "end") loop
Put(To_String(currenttoken));
createStatement(T, stmt);
tokensexecuted := execute(skip, TK, stmt); //ERROR OCCURS HERE
TokenHandlers.moveAhead(tokensexecuted, TK);
currenttoken := To_Unbounded_String(TokenHandlers.getCurrentToken(TK));
end loop;
TokenHandlers.match("end", TK);
return TokenHandlers.resetTokens(TK);
end execute;
编译时出现此错误:
statements-statementhandlers.adb:35:28: no candidate interpretations match the actuals:
statements-statementhandlers.adb:35:46: expected type "CompoundStatement" defined at statements-statementhandlers.ads:14
statements-statementhandlers.adb:35:46: found type "Statement_Access" defined at statements.ads:6
statements-statementhandlers.adb:35:46: ==> in call to "execute" at statements-statementhandlers.ads:10
statements-statementhandlers.adb:35:46: ==> in call to "execute" at statements.ads:8
【问题讨论】:
标签: pointers abstract-class abstract ada