edits
[cdsspec-compiler.git] / src / edu / uci / eecs / specExtraction / SpecUtils.java
index a9ed016f00b7598eb3ea301dbf46648b5c89e74a..869b9ff81aff63566fbe77445851f7b360182977 100644 (file)
@@ -123,8 +123,7 @@ public class SpecUtils {
         *         annotations or the beginning line of the next primitive
         * @throws WrongAnnotationException
         */
-       public static Primitive extractPrimitive(File file, int beginLineNum,
-                       ArrayList<String> annotations, IntObj curIdx)
+       public static Primitive extractPrimitive(File file, int beginLineNum, ArrayList<String> annotations, IntObj curIdx)
                        throws WrongAnnotationException {
                if (curIdx.getVal() == annotations.size()) // The current index points
                                                                                                        // to the end
@@ -147,9 +146,8 @@ public class SpecUtils {
                }
                // Assert that we must have found one primitive
                if (primitive == null) {
-                       WrongAnnotationException
-                                       .err(file, curLineNum,
-                                                       "Something is wrong! We must have found one primitve here!\n");
+                       WrongAnnotationException.err(file, curLineNum,
+                                       "Something is wrong! We must have found one primitve here!\n");
                }
 
                // Process the current "primitive"
@@ -163,9 +161,8 @@ public class SpecUtils {
                                primitive.addLine(trimmedCode);
                        }
                } else {
-                       WrongAnnotationException
-                                       .err(file, curLineNum,
-                                                       "The state annotation should have correct primitive syntax (sub-annotations)");
+                       WrongAnnotationException.err(file, curLineNum,
+                                       "The state annotation should have correct primitive syntax (sub-annotations)");
                }
 
                // Deal with other normal line. E.g. y = 1;
@@ -187,8 +184,7 @@ public class SpecUtils {
 
                if (primitive.contents.size() == 0) { // The content of the primitive is
                                                                                                // empty
-                       WrongAnnotationException.warning(file, curLineNum, "Primitive "
-                                       + primitive.name + " is empty.");
+                       WrongAnnotationException.warning(file, curLineNum, "Primitive " + primitive.name + " is empty.");
                }
                return primitive;
        }
@@ -228,4 +224,20 @@ public class SpecUtils {
                        return null;
                }
        }
+
+       public static boolean isUserDefinedStruct(String type) {
+               // FIXME: We only consider the type is either a one-level pointer or a
+               // struct
+               String bareType = trimSpace(type.replace('*', ' '));
+               return !bareType.equals("int") && !bareType.matches("unsigned\\s+int") && !bareType.equals("unsigned")
+                               && !bareType.equals("bool") && !bareType.equals("double") && !bareType.equals("float")
+                               && !bareType.equals("void");
+       }
+
+       public static String getPlainType(String type) {
+               // FIXME: We only consider the type is either a one-level pointer or a
+               // struct
+               String bareType = trimSpace(type.replace('*', ' '));
+               return bareType;
+       }
 }