view FixScalarRefPlaceholders @ 109:3523e795bdf9

Done with the ref/scalar mq
author Louis Opter <louis@lse.epita.fr>
date Mon, 01 Apr 2013 00:56:28 -0700
parents 976a4b87803f
children
line wrap: on
line source

# HG changeset patch
# User David Pineau <dav.pineau@gmail.com>
# Parent 6f20fad6add410a6a8ba42ec60ffdf81cdbaa4e8
Fix Scalar/Ref placeholders annotations by adding a 'copy' that does not alter the current state

diff --git a/rathaxes/compiler/passes/back/rtxPlaceHolders.inc.cws b/rathaxes/compiler/passes/back/rtxPlaceHolders.inc.cws
--- a/rathaxes/compiler/passes/back/rtxPlaceHolders.inc.cws
+++ b/rathaxes/compiler/passes/back/rtxPlaceHolders.inc.cws
@@ -194,12 +194,13 @@
                 // in unstrict mode
                 if (existVariable(ctype_ref.unknown) && $getArraySize(ctype_ref.unknown) > 0$)
                 {       
-                        ctype_ref.identifier = ctype_ref.unknown#back;
-                        removeVariable(ctype_ref.unknown);
+                    ctype_ref.identifier = ctype_ref.unknown#back;
+                    removeVariable(ctype_ref.unknown);
                 }
                 // name of a type
                 if (existVariable(ctype_ref.identifier) && rtxPH_havePlaceHolder(ctype_ref.identifier))
                 { rtxPH_mapPlaceHolder(ctype_ref.identifier, compile, node_idx, "target_decl"); }
+
                 // composed
                 if (existVariable(ctype_ref.list))
                 {
@@ -266,7 +267,7 @@
 // So do not bother with subtypes and check them all and then recurse.
 function        rtxPH_compile<"__expr__">(local_node : node, compile : node, node_idx : value)
 {
-        if (!existVariable(this.phtype)) insert this.phtype = "scalar";/////
+        if (!existVariable(this.phtype)) insert this.phtype = "copy";//// set to default
         // left for bin operator
         if (existVariable(local_node.left))
         { 
@@ -275,7 +276,7 @@
                 // all post expr case [] or (), are pointer
                 if (local_node.expr_type == "__postexpr__") { insert this.phtype = "pointer";}////
                 rtxPH_compile<local_node.left.type>(local_node.left, compile, node_idx); 
-                insert this.phtype = "scalar";////
+                insert this.phtype = "copy";//// set to default
         }
         // right for bin operator
         if (existVariable(local_node.right))
@@ -283,7 +284,7 @@
                 // the unary *
                 if (local_node.operator == "*" && local_node.expr_type == "__unary__") {insert this.phtype = "pointer";}////
                 rtxPH_compile<local_node.right.type>(local_node.right, compile, node_idx); 
-                insert this.phtype = "scalar";////
+                insert this.phtype = "copy";//// set to default
         }
         // if,while
         if (existVariable(local_node.condition))
diff --git a/rathaxes/compiler/passes/common/rtxResolve.inc.cws b/rathaxes/compiler/passes/common/rtxResolve.inc.cws
--- a/rathaxes/compiler/passes/common/rtxResolve.inc.cws
+++ b/rathaxes/compiler/passes/common/rtxResolve.inc.cws
@@ -177,6 +177,10 @@
     if (out_type == "ref")
         out_type = "pointer";
 
+    // Then, check if we need any changes or not for the out_type
+    if (out_type == "copy") // Copy means that we keep the current state, whether pointer or scalar.
+        return true;
+
     // make sure in and out types are either scalar or ref
     if ((in_type != "scalar" && in_type != "pointer")
         || (out_type != "scalar" && out_type != "pointer"))
@@ -593,7 +597,7 @@
     // We want to set the mangled typedef name into the ctype's identifier:
     // (equivalent of: theDecl.ctype.identifier = COMPUTED_NAME;)
     local_node#parent.ref_placeholder.identifier = rtxResolve_MangleTypeName(theRtype, theRtype.qualifier != "scalar");
-    
+
     return true;
 }
 
@@ -756,7 +760,6 @@
                 { error(RED + "[Error] Cannot transcribe an expression from " + in_type + " to " + out_type + DEFAULT_COLOR); }
                 setall local_node#parent.ref_placeholder = mapping;
             }
-
         }
         else if (isBuiltinVariable(varName)) // Mapping for a  builtin type
         {