1 package edu.uci.eecs.specExtraction;
3 import java.util.ArrayList;
7 * This represents a function declaration header. For example,
8 * "void myFunction(int arg1, bool arg2)" is a function declaration header.
14 public class FunctionHeader {
15 private ArrayList<VariableDeclaration> templateList;
17 // The return type of the function
18 public final String returnType;
20 public final QualifiedName funcName;
21 // The argument list (with formal parameter names)
22 public final ArrayList<VariableDeclaration> args;
24 // The actually function definition line in plain text.
25 // E.g. "void myFunction(int arg1, bool arg2) {"
26 private String headerLine;
28 public FunctionHeader(String returnType, QualifiedName qualifiedName,
29 ArrayList<VariableDeclaration> args) {
30 this.templateList = null;
31 this.returnType = returnType;
32 this.funcName = qualifiedName;
38 * @return Whether the return type is void
40 public boolean isReturnVoid() {
41 return returnType.equals("void");
44 public void setTemplateList(ArrayList<VariableDeclaration> templateList) {
45 this.templateList = templateList;
48 public ArrayList<VariableDeclaration> getTemplateList() {
49 return this.templateList;
52 public String getTemplateFullStr() {
53 String templateStr = "";
54 if (templateList == null)
56 VariableDeclaration decl;
57 decl = templateList.get(0);
58 templateStr = "<" + decl.type + " " + decl.name;
59 for (int i = 1; i < templateList.size(); i++) {
60 decl = templateList.get(i);
61 templateStr = templateStr + ", " + decl.type + " " + decl.name;
63 templateStr = templateStr + ">";
67 public String getTemplateArgStr() {
68 String templateStr = null;
69 if (templateList.size() == 0)
71 templateStr = "<" + templateList.get(0).name;
72 for (int i = 1; i < templateList.size(); i++) {
73 templateStr = templateStr + ", " + templateList.get(i);
75 templateStr = templateStr + ">";
79 public String getFuncStr() {
80 String res = returnType + " " + funcName.fullName + "(";
81 if (args.size() >= 1) {
82 res = res + args.get(0);
84 for (int i = 1; i < args.size(); i++) {
85 res = res + ", " + args.get(i);
91 public String toString() {
92 String res = returnType + " " + funcName.fullName + "(";
93 if (args.size() >= 1) {
94 res = res + args.get(0);
96 for (int i = 1; i < args.size(); i++) {
97 res = res + ", " + args.get(i);
103 public String getRenamedFuncName() {
104 return funcName.qualifiedName + SpecNaming.WrapperPrefix + "_"
108 public FunctionHeader getRenamedHeader(String prefix) {
109 String newFullName = getRenamedFuncName();
110 FunctionHeader newHeader = new FunctionHeader(returnType,
111 new QualifiedName(newFullName), args);
115 public FunctionHeader getRenamedHeader() {
116 return getRenamedHeader(SpecNaming.WrapperPrefix);
121 * @return The string that represents the renamed function header line. For
122 * example, we would return
123 * <code>"bool Wrapper_myFunc(int x, int y)"</code> for the fucntion
124 * <code>"bool myFunc(int x, int y) {"</code>
126 public String getRenamedFuncLine() {
127 String bareName = this.funcName.bareName;
128 String newName = this.getRenamedFuncName();
129 return this.headerLine.replaceFirst(bareName, newName);
134 * @return The string that represents the renamed function call. For
135 * example, we would return <code>"bool RET = myFunc(x, y)"</code>
136 * for the fucntion <code>"bool myFunc(int x, int y)"</code>
138 public String getRenamedCall() {
139 return getRenamedCall(SpecNaming.WrapperPrefix);
144 * @return The original plain text line of the function header
146 public String getHeaderLine() {
151 // No support for template right now
152 public String getDeclaration() {
153 String res = returnType + " " + funcName.fullName + "(";
154 if (args.size() >= 1) {
155 res = res + args.get(0).type + " " + args.get(0).name;
157 for (int i = 1; i < args.size(); i++) {
158 res = res + ", " + args.get(i).type + " " + args.get(i).name;
164 public String getRenamedCall(String prefix) {
166 if (!isReturnVoid()) {
167 res = res + "bool " + SpecNaming.RET + " = ";
169 res = res + prefix + "_" + funcName.fullName + "(";
170 if (args.size() >= 1) {
171 res = res + args.get(0).name;
173 for (int i = 1; i < args.size(); i++) {
174 res = res + ", " + args.get(i).name;
180 public void setHeaderLine(String headerLine) {
181 this.headerLine = headerLine;