2012-03-30 11 views
2

私は、Statementと呼ばれる抽象型とexecute()という抽象関数を持つStatementsというパッケージを用意しています。別のパッケージでは、タイプステートメントであるCompoundStatement型を持ち、execute()関数を実装しています。Adaでアクセスタイプの抽象関数を実装する

私はcreateStatement()という関数を持っています。 Unbounded_String型のトークンを評価し、それに含まれるキーワードを判断するのが目的です。このキーワードに基づいて、このキーワードに基づいてアクセスタイプを生成します。

これまでのところとても良いです。

しかし、私は正しい実行メソッドを呼び出す方法を理解できません。まだ機能していないので、今は1つのキーワードしかコード化されていません。

申し訳ありませんが、私の説明が畳み込まれて聞こえます。

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 

答えて

4

executeに三番目のパラメータは、(の子)であることが予想されるStatement、あなたが与えたことはです(子の)Statementへのポインタ。おそらく必要です

tokensexecuted := execute(skip, TK, stmt.all); 

スタイルの問題として、ディスパッチパラメータを最初にするのが最も一般的です。あなたは(2005年のAdaで)言うことができます

tokensexecuted := stmt.execute(skip, TK); 
+0

[* 2.3プレフィックス表記*](http://www.adaic.org/resources/add_content/standards/05rat/html/Rat-2- 3.html)。 – trashgod

+0

恐ろしい!それはうまくいった。ありがとう、ワイアット氏。 –

+0

@deuteros - その場合は、この回答の横にあるチェックマークの輪郭をクリックすることで、皆さんにそのことを知らせてください(そして、ライト氏に報酬を与えることをお勧めします)。それはこの答えを「受け入れる」でしょう。 –

関連する問題