view FixScalarRefCasts @ 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 2a7d28a3e2d86d36ddfc77ad8ce73c22eadcc718
Add .ref and .scalar to rathaxes types

diff --git a/rathaxes/compiler/node/rtxNodeBack.inc.cws b/rathaxes/compiler/node/rtxNodeBack.inc.cws
--- a/rathaxes/compiler/node/rtxNodeBack.inc.cws
+++ b/rathaxes/compiler/node/rtxNodeBack.inc.cws
@@ -19,7 +19,7 @@
 declare function rtxNodePlaceHolder(local_node : node);
 declare function rtxNodeCall(local_node : node, theVars : node, theChunk : node, out_ref_params : reference);
 declare function rtxNodeSequenceCall(local_node : node, name : node, args : node);
-declare function rtxNodeCast(local_node : node, varName : value, typeId : node);
+declare function rtxNodeCast(local_node : node, varName : value, typeId : node, sQualifier : value);
 // Tool functions for the resolution/generation
 declare function rtxNodeResVal_GetField(resolver_values : node, idList : node, out_ref : reference);
 declare function rtxNodeResVal(local_node : node);
@@ -233,7 +233,7 @@
         return true;
 }
 
-function rtxNodeCast(local_node : node, varName : value, typeId : node)
+function rtxNodeCast(local_node : node, varName : value, typeId : node, sQualifier : value)
 {
     rtxNode(local_node);
     local_node.type = "__rtx_tpl_cast__";
@@ -244,6 +244,8 @@
     local dummy;
     if (rtxNodeRType(local_node.rtype, typeId, dummy) == false)
         return false;
+    if (rtxNodeRType_SetQualifier(local_node.rtype, sQualifier) == false)
+        return false;
 
     return true;
 }
diff --git a/rathaxes/compiler/passes/back/rtxMeta.inc.cws b/rathaxes/compiler/passes/back/rtxMeta.inc.cws
--- a/rathaxes/compiler/passes/back/rtxMeta.inc.cws
+++ b/rathaxes/compiler/passes/back/rtxMeta.inc.cws
@@ -292,15 +292,20 @@
 
                 // Here, we allow casting a local C variable into a rathaxes type. This casts lasts for the current chunk's scope.
                 tpl_cast(theCast : node) ::=
+/**/                    => local sQualifier = "scalar";
                         "cast"
+                        #continue(sError, "A cast can only be applied to a local variable (\"local.\" is expected).")
                         => local typeId;
-                        #continue(sError, "A cast can only be applied to a local variable (\"local.\" is expected).")
                         "local" '.' rootidentifier:varName
                         #continue(sError, "Expected 'as' token for a rathaxes cast.")
                         "as"
                         #continue(sError, "Expected Type name for casting type.")
                         rtx_scoped_identifier(typeId, false)
-                        #check(rtxNodeCast(theCast, varName, typeId))
+                        [
+                            "."
+                            tpl_type_qualifier:sQualifier
+                        ]?
+                        #check(rtxNodeCast(theCast, varName, typeId, sQualifier))
                 ;
 
                 tpl_type_qualifier ::=