Add back pre-ICS support for "int root(int);".

BUG=5521638

Change-Id: Ic1f3c071562c687a98125c2151e306313c5405b8
diff --git a/slang_rs_context.cpp b/slang_rs_context.cpp
index e1a2857..980038c 100644
--- a/slang_rs_context.cpp
+++ b/slang_rs_context.cpp
@@ -116,7 +116,7 @@
     return false;
   }
 
-  if (RSExportForEach::isRSForEachFunc(FD)) {
+  if (RSExportForEach::isRSForEachFunc(mTargetAPI, FD)) {
     RSExportForEach *EFE = RSExportForEach::Create(this, FD);
     if (EFE == NULL)
       return false;
@@ -125,7 +125,8 @@
     return true;
   } else if (RSExportForEach::isSpecialRSFunc(FD)) {
     // Do not reflect specialized RS functions like init or graphics root.
-    if (!RSExportForEach::validateSpecialFuncDecl(getDiagnostics(), FD)) {
+    if (!RSExportForEach::validateSpecialFuncDecl(mTargetAPI,
+                                                  getDiagnostics(), FD)) {
       return false;
     }
     return true;
diff --git a/slang_rs_export_foreach.cpp b/slang_rs_export_foreach.cpp
index faa5f17..924bc06 100644
--- a/slang_rs_export_foreach.cpp
+++ b/slang_rs_export_foreach.cpp
@@ -292,7 +292,8 @@
   return FE;
 }
 
-bool RSExportForEach::isRSForEachFunc(const clang::FunctionDecl *FD) {
+bool RSExportForEach::isRSForEachFunc(int targetAPI,
+    const clang::FunctionDecl *FD) {
   // We currently support only compute root() being exported via forEach
   if (!isRootRSFunc(FD)) {
     return false;
@@ -302,10 +303,23 @@
     // Graphics compute function
     return false;
   }
+
+  // Handle legacy graphics root functions.
+  if ((targetAPI < SLANG_ICS_TARGET_API) && (FD->getNumParams() == 1)) {
+    const clang::ParmVarDecl *PVD = FD->getParamDecl(0);
+    clang::QualType QT = PVD->getType().getCanonicalType();
+    const clang::QualType &IntType = FD->getASTContext().IntTy;
+    if ((FD->getResultType().getCanonicalType() == IntType) &&
+        (QT == IntType)) {
+      return false;
+    }
+  }
+
   return true;
 }
 
-bool RSExportForEach::validateSpecialFuncDecl(clang::Diagnostic *Diags,
+bool RSExportForEach::validateSpecialFuncDecl(int targetAPI,
+                                              clang::Diagnostic *Diags,
                                               const clang::FunctionDecl *FD) {
   slangAssert(Diags && FD);
   bool valid = true;
@@ -323,6 +337,9 @@
                                    "an int for graphics usage"));
         valid = false;
       }
+    } else if ((targetAPI < SLANG_ICS_TARGET_API) && (numParams == 1)) {
+      // Legacy graphics root function
+      // This has already been validated in isRSForEachFunc().
     } else {
       slangAssert(false &&
           "Should not call validateSpecialFuncDecl() on compute root()");
diff --git a/slang_rs_export_foreach.h b/slang_rs_export_foreach.h
index 13fd3a7..cf9ed3f 100644
--- a/slang_rs_export_foreach.h
+++ b/slang_rs_export_foreach.h
@@ -148,13 +148,14 @@
     return Name.equals(FuncDtor);
   }
 
-  static bool isRSForEachFunc(const clang::FunctionDecl *FD);
+  static bool isRSForEachFunc(int targetAPI, const clang::FunctionDecl *FD);
 
   inline static bool isSpecialRSFunc(const clang::FunctionDecl *FD) {
     return isRootRSFunc(FD) || isInitRSFunc(FD) || isDtorRSFunc(FD);
   }
 
-  static bool validateSpecialFuncDecl(clang::Diagnostic *Diags,
+  static bool validateSpecialFuncDecl(int targetAPI,
+                                      clang::Diagnostic *Diags,
                                       const clang::FunctionDecl *FD);
 };  // RSExportForEach
 
diff --git a/tests/F_root_graphics_13/root_graphics_13.rs b/tests/F_root_graphics_13/root_graphics_13.rs
new file mode 100644
index 0000000..c6c1fbd
--- /dev/null
+++ b/tests/F_root_graphics_13/root_graphics_13.rs
@@ -0,0 +1,7 @@
+// -target-api 13
+#pragma version(1)
+#pragma rs java_package_name(foo)
+
+int root(unsigned int launchID) {
+    return 10;
+}
diff --git a/tests/F_root_graphics_13/stderr.txt.expect b/tests/F_root_graphics_13/stderr.txt.expect
new file mode 100644
index 0000000..5670930
--- /dev/null
+++ b/tests/F_root_graphics_13/stderr.txt.expect
@@ -0,0 +1,3 @@
+root_graphics_13.rs:5:5: error: compute root() is required to return a void type
+root_graphics_13.rs:5:5: error: Compute root() must have at least one parameter for in or out
+root_graphics_13.rs:5:5: error: Compute root() targeting SDK levels 11-13 may not skip parameters
diff --git a/tests/F_root_graphics_13/stdout.txt.expect b/tests/F_root_graphics_13/stdout.txt.expect
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/F_root_graphics_13/stdout.txt.expect
diff --git a/tests/P_root_graphics_13/root_graphics_13.rs b/tests/P_root_graphics_13/root_graphics_13.rs
new file mode 100644
index 0000000..882bea1
--- /dev/null
+++ b/tests/P_root_graphics_13/root_graphics_13.rs
@@ -0,0 +1,9 @@
+// -target-api 13
+#pragma version(1)
+#pragma rs java_package_name(foo)
+
+typedef int myInt;
+
+myInt root(myInt launchID) {
+    return 10;
+}
diff --git a/tests/P_root_graphics_13/stderr.txt.expect b/tests/P_root_graphics_13/stderr.txt.expect
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/P_root_graphics_13/stderr.txt.expect
diff --git a/tests/P_root_graphics_13/stdout.txt.expect b/tests/P_root_graphics_13/stdout.txt.expect
new file mode 100644
index 0000000..f61211e
--- /dev/null
+++ b/tests/P_root_graphics_13/stdout.txt.expect
@@ -0,0 +1 @@
+Generating ScriptC_root_graphics_13.java ...