edits
[cdsspec-compiler.git] / src / edu / uci / eecs / specExtraction / VariableDeclaration.java
1 package edu.uci.eecs.specExtraction;
2
3 import java.io.File;
4 import java.util.regex.Matcher;
5 import java.util.regex.Pattern;
6
7 import edu.uci.eecs.utilParser.ParseException;
8 import edu.uci.eecs.utilParser.UtilParser;
9
10 /**
11  * <p>
12  * This class represents a variable declaration in C/C++, in which there exist a
13  * type and a name.
14  * </p>
15  * 
16  * @author Peizhao Ou
17  * 
18  */
19 public class VariableDeclaration {
20         public final String type;
21         public final String name;
22
23         public VariableDeclaration(String type, String name) {
24                 this.type = SpecUtils.trimSpace(type);
25                 this.name = SpecUtils.trimSpace(name);
26         }
27
28         public VariableDeclaration(File file, int lineNum, String line)
29                         throws WrongAnnotationException {
30                 VariableDeclaration decl = null;
31                 try {
32                         decl = UtilParser.parseDeclaration(line);
33                 } catch (ParseException e) {
34                         WrongAnnotationException.err(file, lineNum, "The declaration: \""
35                                 + line + "\" has wrong syntax.");
36                 } finally {
37                         type = decl == null ? null : decl.type;
38                         name = decl == null ? null : decl.name;
39                 }
40         }
41
42         public String toString() {
43                 return type + ": " + name;
44         }
45 }