01: /**************************************************************************/
02: /* N I C E */
03: /* A high-level object-oriented research language */
04: /* (c) Daniel Bonniot 2005 */
05: /* */
06: /* This program is free software; you can redistribute it and/or modify */
07: /* it under the terms of the GNU General Public License as published by */
08: /* the Free Software Foundation; either version 2 of the License, or */
09: /* (at your option) any later version. */
10: /* */
11: /**************************************************************************/package bossa.syntax;
12:
13: /**
14: The smallest unit containing code (typically, the content of a file).
15:
16: Definitions marked as 'private' are only visible inside their Module.
17: */
18:
19: public class Module {
20: public final bossa.modules.Package pkg;
21: VarScope scope;
22: String name;
23:
24: public Module(bossa.modules.Package pkg, String name,
25: nice.tools.visibility.Scope scope) {
26: this .pkg = pkg;
27: this .name = name;
28: this .scope = dispatch.createGlobalVarScope(0, scope);
29: }
30:
31: bossa.modules.Compilation compilation() {
32: return pkg.getCompilation();
33: }
34:
35: public boolean compiled() {
36: return pkg.interfaceFile();
37: }
38:
39: public void addStaticImport(LocatedString value) {
40: String fullName = value.toString();
41:
42: int lastDot = fullName.lastIndexOf('.');
43: if (lastDot == -1)
44: bossa.util.User
45: .error(value, "Missing field or method name");
46:
47: String methodName = fullName.substring(lastDot + 1);
48: fullName = fullName.substring(0, lastDot);
49:
50: mlsub.typing.TypeConstructor tc = Node.getGlobalTypeScope()
51: .globalLookup(fullName, value.location());
52:
53: if (tc == null)
54: bossa.util.User.error(value, "Unknown class: " + fullName);
55:
56: gnu.bytecode.Type type = nice.tools.code.Types.javaType(tc);
57: if (!(type instanceof gnu.bytecode.ClassType))
58: bossa.util.User.error(value, fullName + " is not a class");
59:
60: java.util.List symbols = dispatch.findJavaMethods(
61: (gnu.bytecode.ClassType) type, methodName);
62:
63: if (symbols.size() == 0)
64: bossa.util.User.error(value, methodName
65: + " is not a static field or method of class "
66: + fullName);
67:
68: for (java.util.Iterator i = symbols.iterator(); i.hasNext();) {
69: /*Var*/Symbol s = (/*Var*/Symbol) i.next();
70: scope.addSymbol(s);
71: }
72: }
73: }
|