Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: engine/FunctionCallExpressionDescription.java


1   
2   /* **********************************
3    File:FunctionCallExpressionDescription.java
4    Author: Alec(panovici@elcom.pub.ro)
5    Created on Sun May  2 15:34:04 EDT 1999
6    Comments: Part of the vIDE Project
7               Copyright 1999 the vIDE Team.
8   ***********************************/
9   
10  
11  package engine;
12  
13  import middle.*;
14  import java.util.*;
15  
16  /**
17   * The description of a funcction call expression. 
18   * It creates the required registers for the actual parameters (whose types are known only at instantiation time).
19   */
20  class FunctionCallExpressionDescription implements ExpressionDescription{
21  
22    /**
23     * Contains the expressionDescriptions for the actual parameters.
24     */
25    Vector actualParamsDescs;
26  
27    /**
28     * The invoked func name.
29     */
30    FQNDescription funcName;
31    
32  
33    FunctionCallExpressionDescription(FQNDescription funcName,
34                                      Vector actualParamsDescs){
35      this.actualParamsDescs = actualParamsDescs;
36      this.funcName = funcName;
37    }
38  
39    /**
40     * Creates the placeholders for the actuel parameters
41     * transfer and the DefaultInstruction for the func invocation.
42     */
43    public Expression instantiate(NameSpace ns)throws ParseException{
44      Vector actualParams = new Vector();
45      Vector paramInstances;
46      
47      for(Enumeration e = actualParamsDescs.elements() ; e.hasMoreElements() ; ){
48        //link the expressions to the caller's NameSpace (ns)
49        try{
50          actualParams.addElement(((ExpressionDescription)
51                                   e.nextElement()).instantiate(ns));
52        }catch(ParseException ex){
53          xConsole.dumpStack(ex);
54          throw new ParseException(super.toString() + " error:" + ex);
55        }
56      }
57      
58      NameSpace funcSpace;
59      try {
60        funcSpace = (NameSpace)ns.resolveName(funcName.instantiate(ns));
61        //just checking that this name refers the correct NameSpace
62        if(funcSpace == null)
63          throw new ParseException(super.toString() +
64                                   " error:symbol \"" +
65                                   funcName + "\" not found");
66        if(! (funcSpace.desc instanceof FunctionDescription))
67          throw new ClassCastException();
68      } catch(ClassCastException ex) {
69        throw new ParseException(super.toString() +
70                                 " error:" + funcName + " is not a function");
71      }
72      
73      FunctionDescription funcDescription = (FunctionDescription) funcSpace.desc;
74      try { 
75        paramInstances = funcDescription.createParams(funcSpace, actualParams);
76      } catch(ParseException ex) {
77        xConsole.dumpStack(ex);
78        throw new ParseException(toString() + " error:" + ex);
79      }
80      xConsole.debug("func description is: " + funcDescription);
81      try {
82        return new FunctionCallExpression(ns, this, funcDescription,
83                                          actualParams, paramInstances,
84                                          funcDescription.
85                                          makeInstructionInstance(funcSpace));
86      } catch(ParseException ex) {
87        xConsole.dumpStack(ex);
88        xConsole.cout(ex.toString());
89        throw new ParseException("error inside called function");
90      }
91    }
92  
93    public String toString(){
94      String res =  funcName + "(" ;
95      for(Enumeration e = actualParamsDescs.elements() ; e.hasMoreElements() ;){
96        res += ((ExpressionDescription)e.nextElement()).toString();
97        if(e.hasMoreElements())res += ", ";
98      }
99      res += ");";
100     return res;
101   }
102 }
103 
104 
105 
106