001: // ===========================================================================
002: // This file has been generated by
003: // Typical, version 1.13.1,
004: // (C) 2004-2007 Robert Grimm and New York University,
005: // on Tuesday, October 16, 2007 at 10:43:19 AM.
006: // Edit at your own risk.
007: // ===========================================================================
008:
009: package xtc.lang;
010:
011: import xtc.util.Pair;
012: import xtc.util.Runtime;
013: import xtc.util.Function;
014:
015: import xtc.tree.Node;
016: import xtc.tree.GNode;
017:
018: import xtc.typical.Analyzer;
019: import xtc.typical.Tuple;
020: import xtc.typical.Name;
021: import xtc.typical.Scope;
022: import xtc.typical.ScopeKind;
023:
024: /** Type checker for TypedLambda. */
025: public class TypedLambdaAnalyzer extends Analyzer {
026: public TypedLambdaAnalyzer(Runtime runt) {
027: super (runt);
028: analyzer = analyze;
029: }
030:
031: public void getScopeNodes() {
032: processScopeNodes.add("Abstraction");
033: }
034:
035: final Function.F1<Tuple.T3<Name, String, String>, Node> getNameSpace = new Function.F1<Tuple.T3<Name, String, String>, Node>() {
036: public Tuple.T3<Name, String, String> apply(final Node n) {
037: return new Match<Tuple.T3<Name, String, String>>() {
038: public Tuple.T3<Name, String, String> apply() {
039: final Node arg$0 = GNode.cast(n);
040:
041: if (TypedLambdaSupport.match$1(arg$0)) {
042: final String id = Analyzer.cast(arg$0
043: .getString(0));
044:
045: matching_nodes.add(arg$0);
046: if ((null != arg$0 && processScopeNodes
047: .contains(arg$0.getName()))) {
048: processScope(arg$0, getScope);
049: }
050: checkEnterScope(arg$0);
051:
052: final Object retValue$4 = Analyzer
053: .cast(new Tuple.T3<Name, String, String>(
054: new Name.SimpleName(id),
055: "default", "type"));
056:
057: checkExitScope(arg$0);
058: matching_nodes
059: .remove(matching_nodes.size() - 1);
060: return Analyzer.cast(retValue$4);
061: }
062: return null;
063: }
064: }.apply();
065: }
066: };
067:
068: final Function.F1<Scope, Node> getScope = new Function.F1<Scope, Node>() {
069: public Scope apply(final Node n) {
070: if (TypedLambdaSupport.match$6(n)) {
071: final Node id = Analyzer.cast(n.getGeneric(0));
072: final Node body = Analyzer.cast(n.getGeneric(2));
073:
074: return Analyzer.cast(new Scope(new ScopeKind.Anonymous(
075: "lambda"), new Pair<Node>(id)
076: .append(new Pair<Node>(body))));
077: }
078: return null;
079: }
080: };
081:
082: final Function.F1<TypedLambdaTypes.raw_type<?>, Node> analyze = new Function.F1<TypedLambdaTypes.raw_type<?>, Node>() {
083: public TypedLambdaTypes.raw_type<?> apply(final Node arg$8) {
084: return new Match<TypedLambdaTypes.raw_type<?>>() {
085: public TypedLambdaTypes.raw_type<?> apply() {
086: final Node arg$9 = GNode.cast(arg$8);
087:
088: if (TypedLambdaSupport.match$10(arg$9)) {
089: final Node lambda = Analyzer.cast(arg$9
090: .getGeneric(0));
091: final Node expr = Analyzer.cast(arg$9
092: .getGeneric(1));
093:
094: matching_nodes.add(arg$9);
095: if ((null != arg$9 && processScopeNodes
096: .contains(arg$9.getName()))) {
097: processScope(arg$9, getScope);
098: }
099: checkEnterScope(arg$9);
100:
101: final Object retValue$27 = Analyzer
102: .cast(new Let<TypedLambdaTypes.raw_type<?>>() {
103: final TypedLambdaTypes.raw_type<?> tl;
104: final TypedLambdaTypes.raw_type<?> tr;
105:
106: {
107: tl = Analyzer.cast(analyze
108: .apply(lambda));
109: tr = Analyzer.cast(analyze
110: .apply(expr));
111: }
112:
113: public TypedLambdaTypes.raw_type<?> apply() {
114: return Analyzer
115: .cast(new Require<TypedLambdaTypes.raw_type<?>>() {
116: public TypedLambdaTypes.raw_type<?> apply() {
117: final Boolean var$24 = new Match<Boolean>() {
118: public Boolean apply() {
119: final TypedLambdaTypes.raw_type<?> arg$21 = Analyzer
120: .cast(tl);
121:
122: if ((null != arg$21))
123: switch (arg$21
124: .tag()) {
125: case FunctionT:
126: if (TypedLambdaSupport
127: .match$15(arg$21)) {
128: return Analyzer
129: .cast(Boolean.TRUE);
130: }
131: break;
132: default:
133: break;
134: }
135: ;
136: if (true) {
137: return Analyzer
138: .cast(Boolean.FALSE);
139: }
140: return null;
141: }
142: }
143: .apply()
144: .equals(
145: true);
146:
147: if ((null != var$24 && !var$24)) {
148: showMessage(
149: "error",
150: "application of non-function",
151: null);
152: }
153: if ((null == var$24)) {
154: return null;
155: }
156: if (var$24) {
157: return new Match<TypedLambdaTypes.raw_type<?>>() {
158: public TypedLambdaTypes.raw_type<?> apply() {
159: final Tuple.T2<TypedLambdaTypes.raw_type<?>, TypedLambdaTypes.raw_type<?>> arg$18 = Analyzer
160: .cast(new Tuple.T2<TypedLambdaTypes.raw_type<?>, TypedLambdaTypes.raw_type<?>>(
161: tl,
162: tr));
163:
164: if (TypedLambdaSupport
165: .match$12(arg$18)) {
166: final TypedLambdaTypes.raw_type<?> param = Analyzer
167: .cast(arg$18
168: .get1()
169: .getTuple()
170: .get1());
171: final TypedLambdaTypes.raw_type<?> res = Analyzer
172: .cast(arg$18
173: .get1()
174: .getTuple()
175: .get2());
176:
177: if ((null != arg$18
178: .get2() && arg$18
179: .get2()
180: .equals(
181: param))) {
182: return Analyzer
183: .cast(res);
184: }
185: }
186: if (true) {
187: return Analyzer
188: .cast(error(
189: "argument/parameter type mismatch",
190: null));
191: }
192: return null;
193: }
194: }.apply();
195: }
196: return null;
197: }
198: }.apply());
199: }
200: }.apply());
201:
202: checkExitScope(arg$9);
203: matching_nodes
204: .remove(matching_nodes.size() - 1);
205: if ((null != arg$9)) {
206: arg$9.setProperty("__type", retValue$27);
207: }
208: return Analyzer.cast(retValue$27);
209: }
210: if (TypedLambdaSupport.match$6(arg$9)) {
211: final Node id = Analyzer.cast(arg$9
212: .getGeneric(0));
213: final Node type = Analyzer.cast(arg$9
214: .getGeneric(1));
215: final Node body = Analyzer.cast(arg$9
216: .getGeneric(2));
217:
218: matching_nodes.add(arg$9);
219: if ((null != arg$9 && processScopeNodes
220: .contains(arg$9.getName()))) {
221: processScope(arg$9, getScope);
222: }
223: checkEnterScope(arg$9);
224:
225: final Object retValue$31 = Analyzer
226: .cast(new Let<TypedLambdaTypes.raw_type<?>>() {
227: final TypedLambdaTypes.raw_type<?> param;
228: final TypedLambdaTypes.raw_type<?> res;
229:
230: {
231: param = Analyzer.cast(get_type
232: .apply(type));
233: define3.apply(id, param,
234: getNameSpace);
235: res = Analyzer.cast(analyze
236: .apply(body));
237: }
238:
239: public TypedLambdaTypes.raw_type<?> apply() {
240: return Analyzer
241: .cast(new TypedLambdaTypes.FunctionT(
242: param, res));
243: }
244: }.apply());
245:
246: checkExitScope(arg$9);
247: matching_nodes
248: .remove(matching_nodes.size() - 1);
249: if ((null != arg$9)) {
250: arg$9.setProperty("__type", retValue$31);
251: }
252: return Analyzer.cast(retValue$31);
253: }
254: if (TypedLambdaSupport.match$32(arg$9)) {
255: final Node id = Analyzer.cast(arg$9);
256:
257: matching_nodes.add(arg$9);
258: if ((null != arg$9 && processScopeNodes
259: .contains(arg$9.getName()))) {
260: processScope(arg$9, getScope);
261: }
262: checkEnterScope(arg$9);
263:
264: final Object retValue$35 = Analyzer
265: .cast(Analyzer.cast(lookup2.apply(id,
266: getNameSpace)));
267:
268: checkExitScope(arg$9);
269: matching_nodes
270: .remove(matching_nodes.size() - 1);
271: if ((null != arg$9)) {
272: arg$9.setProperty("__type", retValue$35);
273: }
274: return Analyzer.cast(retValue$35);
275: }
276: if (TypedLambdaSupport.match$36(arg$9)) {
277: matching_nodes.add(arg$9);
278: if ((null != arg$9 && processScopeNodes
279: .contains(arg$9.getName()))) {
280: processScope(arg$9, getScope);
281: }
282: checkEnterScope(arg$9);
283:
284: final Object retValue$39 = Analyzer
285: .cast(new TypedLambdaTypes.IntegerT());
286:
287: checkExitScope(arg$9);
288: matching_nodes
289: .remove(matching_nodes.size() - 1);
290: if ((null != arg$9)) {
291: arg$9.setProperty("__type", retValue$39);
292: }
293: return Analyzer.cast(retValue$39);
294: }
295: if (TypedLambdaSupport.match$40(arg$9)) {
296: matching_nodes.add(arg$9);
297: if ((null != arg$9 && processScopeNodes
298: .contains(arg$9.getName()))) {
299: processScope(arg$9, getScope);
300: }
301: checkEnterScope(arg$9);
302:
303: final Object retValue$43 = Analyzer
304: .cast(new TypedLambdaTypes.StringT());
305:
306: checkExitScope(arg$9);
307: matching_nodes
308: .remove(matching_nodes.size() - 1);
309: if ((null != arg$9)) {
310: arg$9.setProperty("__type", retValue$43);
311: }
312: return Analyzer.cast(retValue$43);
313: }
314: return null;
315: }
316: }.apply();
317: }
318: };
319:
320: final Function.F1<TypedLambdaTypes.raw_type<?>, Node> get_type = new Function.F1<TypedLambdaTypes.raw_type<?>, Node>() {
321: public TypedLambdaTypes.raw_type<?> apply(final Node arg$45) {
322: return new Match<TypedLambdaTypes.raw_type<?>>() {
323: public TypedLambdaTypes.raw_type<?> apply() {
324: final Node arg$46 = GNode.cast(arg$45);
325:
326: if (TypedLambdaSupport.match$47(arg$46)) {
327: final Node parameter = Analyzer.cast(arg$46
328: .getGeneric(0));
329: final Node result = Analyzer.cast(arg$46
330: .getGeneric(1));
331:
332: matching_nodes.add(arg$46);
333: if ((null != arg$46 && processScopeNodes
334: .contains(arg$46.getName()))) {
335: processScope(arg$46, getScope);
336: }
337: checkEnterScope(arg$46);
338:
339: final Object retValue$50 = Analyzer
340: .cast(new TypedLambdaTypes.FunctionT(
341: get_type.apply(parameter),
342: get_type.apply(result)));
343:
344: checkExitScope(arg$46);
345: matching_nodes
346: .remove(matching_nodes.size() - 1);
347: return Analyzer.cast(retValue$50);
348: }
349: if (TypedLambdaSupport.match$51(arg$46)) {
350: matching_nodes.add(arg$46);
351: if ((null != arg$46 && processScopeNodes
352: .contains(arg$46.getName()))) {
353: processScope(arg$46, getScope);
354: }
355: checkEnterScope(arg$46);
356:
357: final Object retValue$54 = Analyzer
358: .cast(new TypedLambdaTypes.IntegerT());
359:
360: checkExitScope(arg$46);
361: matching_nodes
362: .remove(matching_nodes.size() - 1);
363: return Analyzer.cast(retValue$54);
364: }
365: if (TypedLambdaSupport.match$55(arg$46)) {
366: matching_nodes.add(arg$46);
367: if ((null != arg$46 && processScopeNodes
368: .contains(arg$46.getName()))) {
369: processScope(arg$46, getScope);
370: }
371: checkEnterScope(arg$46);
372:
373: final Object retValue$58 = Analyzer
374: .cast(new TypedLambdaTypes.StringT());
375:
376: checkExitScope(arg$46);
377: matching_nodes
378: .remove(matching_nodes.size() - 1);
379: return Analyzer.cast(retValue$58);
380: }
381: return null;
382: }
383: }.apply();
384: }
385: };
386: }
|