comparison graal/com.oracle.truffle.ruby.runtime/src/com/oracle/truffle/ruby/runtime/lookup/LookupFork.java @ 13514:0fbee3eb71f0

Ruby: import project.
author Chris Seaton <chris.seaton@oracle.com>
date Mon, 06 Jan 2014 17:12:09 +0000
parents
children
comparison
equal deleted inserted replaced
13513:64a23ce736a0 13514:0fbee3eb71f0
1 /*
2 * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. This
3 * code is released under a tri EPL/GPL/LGPL license. You can use it,
4 * redistribute it and/or modify it under the terms of the:
5 *
6 * Eclipse Public License version 1.0
7 * GNU General Public License version 2
8 * GNU Lesser General Public License version 2.1
9 */
10 package com.oracle.truffle.ruby.runtime.lookup;
11
12 import java.util.*;
13
14 import com.oracle.truffle.api.*;
15 import com.oracle.truffle.api.utilities.*;
16 import com.oracle.truffle.ruby.runtime.methods.*;
17
18 /**
19 * A fork in the lookup graph. Look at first and then look at second.
20 */
21 public class LookupFork implements LookupNode {
22
23 private LookupNode first;
24 private LookupNode second;
25
26 public LookupFork(LookupNode first, LookupNode second) {
27 this.first = first;
28 this.second = second;
29 }
30
31 public boolean setClassVariableIfAlreadySet(String variableName, Object value) {
32 if (first.setClassVariableIfAlreadySet(variableName, value)) {
33 return true;
34 }
35
36 return second.setClassVariableIfAlreadySet(variableName, value);
37 }
38
39 @Override
40 public Object lookupConstant(String constantName) {
41 final Object firstResult = first.lookupConstant(constantName);
42
43 if (firstResult != null) {
44 return firstResult;
45 }
46
47 return second.lookupConstant(constantName);
48 }
49
50 @Override
51 public Object lookupClassVariable(String classVariable) {
52 final Object firstResult = first.lookupClassVariable(classVariable);
53
54 if (firstResult != null) {
55 return firstResult;
56 }
57
58 return second.lookupClassVariable(classVariable);
59 }
60
61 @Override
62 public RubyMethod lookupMethod(String methodName) {
63 final RubyMethod firstResult = first.lookupMethod(methodName);
64
65 if (firstResult != null) {
66 return firstResult;
67 }
68
69 return second.lookupMethod(methodName);
70 }
71
72 @Override
73 public Assumption getUnmodifiedAssumption() {
74 return new UnionAssumption(first.getUnmodifiedAssumption(), second.getUnmodifiedAssumption());
75 }
76
77 public LookupNode getFirst() {
78 return first;
79 }
80
81 public LookupNode getSecond() {
82 return second;
83 }
84
85 public Set<String> getClassVariables() {
86 final Set<String> classVariables = new HashSet<>();
87 classVariables.addAll(first.getClassVariables());
88 classVariables.addAll(second.getClassVariables());
89 return classVariables;
90 }
91
92 public void getMethods(Map<String, RubyMethod> methods) {
93 second.getMethods(methods);
94 first.getMethods(methods);
95 }
96
97 }