comparison FixRecursiveTypeFieldResolution @ 106:976a4b87803f

Fix the resolution and the e1000 sample with the new scalar ref feature
author David Pineau <dav.pineau@gmail.com>
date Mon, 25 Mar 2013 01:17:56 +0100
parents
children 3523e795bdf9
comparison
equal deleted inserted replaced
105:fb20f01ea997 106:976a4b87803f
1 # HG changeset patch
2 # Parent f625aa6908ee7a45ab3f97d7137f45003ef02975
3 Fix the recursive field resolution within types.
4
5 diff --git a/rathaxes/compiler/passes/common/rtxResolve.inc.cws b/rathaxes/compiler/passes/common/rtxResolve.inc.cws
6 --- a/rathaxes/compiler/passes/common/rtxResolve.inc.cws
7 +++ b/rathaxes/compiler/passes/common/rtxResolve.inc.cws
8 @@ -739,9 +739,13 @@
9 local source_type;
10
11 // First retrieve the type of the value we just resolved.
12 - if (getArraySize(subidentifiers) != 0)
13 + if (getArraySize(subidentifiers) == 1)
14 {
15 - ref source_type = theChunk.type_map[varName];
16 + // If there's a resval argument for it, then take the source type from there
17 + // Otherwise, use the chunk's type_map.
18 + if (rtxNodeArg_getRType(self, source_type) == false)
19 + { ref source_type = theChunk.type_map[varName]; }
20 + rtxNodeArg_getRType(self, source_type);
21 }
22 else
23 {
24 @@ -1100,6 +1104,7 @@
25 return false;
26 }
27
28 +
29 if (instanceChunk<c_tree.instanceKey>(resVals, c_tree.body, source_tree) != false)
30 {
31 rtxResolve_InsertCode(theBlock, startIdx, phName, phIdx, c_tree.body);
32 @@ -1115,6 +1120,7 @@
33 if (errcount != 0)
34 return false;
35 }
36 +
37 return true;
38 }
39
40 @@ -1309,39 +1315,69 @@
41 placeHolder : node, out_node : node, source_tree : reference)
42 {
43 traceLine("rtxResolve:<LOG> type_map<"+T+"> for variable '"+mappedIds#[0]+"' ("+toString(mappedIds)+")");
44 - local theTemplate;
45 local identifiers;
46 -
47 - if (rtxLink_FindUniqueTemplate(theRtype, source_tree.config, theTemplate) == false)
48 - return false;
49 + local actual_resVals;
50 + local actual_rtype;
51 + setall actual_rtype = theRtype;
52 + setall actual_resVals = resolverValues;
53
54 setall identifiers = mappedIds;
55 removeFirstElement(identifiers);
56 if (getArraySize(identifiers) > 0)
57 {
58 - // Now that we have selected an unique template, load the tree+script
59 - local subtree;
60 - rtxLink_LoadItem(theTemplate, subtree);
61 - localref theMapping = subtree.mapping.body.block[identifiers#front];
62 -
63 - // Call the right mapping function (based on hash + identifier mapped).
64 - traceLine("type_map<"+T+">:<LOG> type_map<" + T + ">: Calling mapping key : "
65 - + theMapping.instanceKey);
66 -
67 - if (instanceMapping<theMapping.instanceKey>(resolverValues, subtree, source_tree) == false)
68 + local self_arg;
69 + local prev_expr;
70 + if (rtxNodeArgs_GetArgByName(resolverValues, "self", self_arg) == false)
71 {
72 - traceLine(RED + "[Error] type_map<"+T+">: instanceMapping<\""+theMapping.instanceKey+"\"> failed");
73 - traceLine(RED + " for mapping at " + placeHolder#parent.location + "." + DEFAULT_COLOR);
74 + traceLine(RED + "[Error] type_map<"+T+">: Could not retrieve self." + DEFAULT_COLOR);
75 return false;
76 }
77 + rtxNodeArg_getValue(self_arg, prev_expr);
78
79 - setall out_node = theMapping.body.expr;
80 + while (getArraySize(identifiers) > 0)
81 + {
82 + local theTemplate;
83 + local subtree;
84 + if (rtxLink_FindUniqueTemplate(actual_rtype, source_tree.config, theTemplate) == false)
85 + return false;
86 + rtxLink_LoadItem(theTemplate, subtree);
87 + localref theMapping = subtree.mapping.body.block[identifiers#front];
88 +
89 + // Call the right mapping function (based on hash + identifier mapped).
90 + traceLine("type_map<"+T+">:<LOG> type_map<" + T + ">: Calling mapping key : "
91 + + theMapping.instanceKey);
92 +
93 + if (instanceMapping<theMapping.instanceKey>(actual_resVals, subtree, source_tree) == false)
94 + {
95 + traceLine(RED + "[Error] type_map<"+T+">: instanceMapping<\""+theMapping.instanceKey+"\"> failed");
96 + traceLine(RED + " for mapping at " + placeHolder#parent.location + "." + DEFAULT_COLOR);
97 + return false;
98 + }
99 +
100 + // Update actual rtype.
101 + local rtypeName = rtxRTypeName<actual_rtype.type>(actual_rtype);
102 + local field_rtype;
103 + if (rtxTypingLookup_TypeField<rtypeName>(actual_rtype, identifiers#front, placeHolder#root, source_tree, field_rtype) == false)
104 + {
105 + traceLine(RED + "[Error] Could not resolve type field '"
106 + + identifiers#front + "' for type " + rtypeName + DEFAULT_COLOR);
107 + return false;
108 + }
109 +
110 + setall prev_expr = theMapping.body.expr;
111 + setall actual_rtype = field_rtype;
112 + clearVariable(actual_resVals);
113 + rtxNodeArgs(actual_resVals);
114 + rtxNodeArgs_AppendArg(actual_resVals, "self", actual_rtype, prev_expr);
115 + removeFirstElement(identifiers);
116 + }
117 }
118 - else
119 +
120 + // Now, resolve as a "self"
121 {
122 local self;
123 local val;
124 - if (rtxNodeArgs_GetArgByName(resolverValues, "self", self) == false)
125 + if (rtxNodeArgs_GetArgByName(actual_resVals, "self", self) == false)
126 {
127 error(RED + "Could not get value..." + DEFAULT_COLOR);
128 }