summaryrefslogtreecommitdiff
path: root/sources/scalac/symtab/Modifiers.java
blob: 1b07e2967f9ce54462b7791d4e2751f8c6910ca8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*     ____ ____  ____ ____  ______                                     *\
**    / __// __ \/ __// __ \/ ____/    SOcos COmpiles Scala             **
**  __\_ \/ /_/ / /__/ /_/ /\_ \       (c) 2002, LAMP/EPFL              **
** /_____/\____/\___/\____/____/                                        **
**                                                                      **
** $Id$
\*                                                                      */

package scalac.symtab;

public interface Modifiers {

    // modifiers
    int DEFERRED      = 0x00000001;   // was `abstract' for members
    int FINAL         = 0x00000002;
    int PRIVATE       = 0x00000004;
    int PROTECTED     = 0x00000008;

    int SEALED        = 0x00000010;
    int OVERRIDE      = 0x00000020;
    int CASE          = 0x00000040;
    int ABSTRACT      = 0x00000080;   // abstract class, or used in conjunction
                                      // with abstract override.
                                      // Note difference to DEFERRED!

    int DEF           = 0x00000100;   // a def parameter
    int REPEATED      = 0x00000200;   // a repeated parameter
    int SYNTHETIC     = 0x00000400;
    int DEPRECATED    = 0x00000800;

    int JAVA          = 0x00001000;   // symbol was defined by a Java class
    int MODUL         = 0x00002000;   // symbol is module or class implementing a module
    int MUTABLE       = 0x00004000;   // symbol is a mutable variable.
    int VIEWBOUND     = 0x00004000;   // type symbol has a <% bound.
    int PARAM         = 0x00008000;   // symbol is a (type) parameter to a method

    int INITIALIZED   = 0x00010000;   // symbol's definition is complete
    int LOCKED        = 0x00020000;   // temporary flag to catch cyclic dependencies
    int ACCESSED      = 0x00040000;   // symbol was accessed at least once
    int SELECTOR      = 0x00080000;   // symbol was used as selector in Select

    int PACKAGE       = 0x00100000;   // symbol is a java package.
    int STABLE        = 0x00800000;   // functions that are assumed to be stable
                                    // (typically, access methods for valdefs)

    int CAPTURED      = 0x01000000;   // variables is accessed from
                                      // nested function. Set by LambdaLift
    int INCONSTRUCTOR = 0x01000000;   // transient flag for Analyzer
    int CASEACCESSOR  = 0x02000000;   // function is a case constructor

    int ACCESSOR      = 0x04000000;   // function is an access function for a
                                      // value or variable
    int BRIDGE        = 0x08000000;    // function is a bridge method.
    int LIFTED        = BRIDGE;        // transient flag for lambdalift
    int ALTERNATIVE   = BRIDGE;        // transient flag for pickle/unpickle
    int SNDTIME       = BRIDGE;        // debug

    int INTERFACE     = 0x10000000;   // symbol is a Java interface
    int TRAIT         = 0x20000000;   // symbol is a Trait

    int COVARIANT     = 0x40000000;   // symbol is a covariant type variable
    int CONTRAVARIANT = 0x80000000;   // symbol is a contravariant type variable

    // masks
    int SOURCEFLAGS   = 0x00000077 | DEF | REPEATED | MODUL | MUTABLE | PACKAGE | PARAM | TRAIT | COVARIANT | CONTRAVARIANT;  // these modifiers can be set in source programs.
    int ACCESSFLAGS   = PRIVATE | PROTECTED;
    int VARIANCES     = COVARIANT | CONTRAVARIANT;
    int CONSTRFLAGS   = CASE | JAVA;
    /** Module flags inherited by their module-class */
    int MODULE2CLASSFLAGS = ACCESSFLAGS | DEPRECATED | SYNTHETIC | JAVA | PACKAGE;

    public static class Helper {

        public static boolean isAbstract(int flags) {
	    // todo: ABSTRACT and DEFERRED should be separated.
            return (flags & DEFERRED) != 0 ||
		(flags & (ABSTRACT | OVERRIDE)) == ABSTRACT;
        }

        public static boolean isFinal(int flags) {
            return (flags & FINAL)     != 0;
        }

        public static boolean isPrivate(int flags) {
            return (flags & PRIVATE)   != 0;
        }

        public static boolean isProtected(int flags) {
            return (flags & PROTECTED) != 0;
        }

        public static boolean isSealed(int flags) {
            return (flags & SEALED) != 0;
        }

        public static boolean isOverride(int flags) {
            return (flags & OVERRIDE)  != 0;
        }

        public static boolean isCase(int flags) {
            return (flags & CASE)      != 0;
        }

        public static boolean isCaseAccessor(int flags) {
            return (flags & CASEACCESSOR) != 0;
        }

        public static boolean isInterface(int flags) {
            return (flags & INTERFACE) != 0;
        }

        public static boolean isDef(int flags) {
            return (flags & DEF)       != 0;
        }

        public static boolean isModClass(int flags) {
            return (flags & MODUL)  != 0;
        }

        public static boolean isJava(int flags) {
            return (flags & JAVA)  != 0;
        }

        public static boolean isNoVal(int flags) {
            return (flags & PACKAGE)  != 0;
        }

        public static String toString(int flags) {
            StringBuffer buffer = new StringBuffer();
            toString(buffer, flags);
            return buffer.toString();
        }

        public static void toString(StringBuffer buffer, int flags) {
            //buffer.append(flags).append(": ");//debug
            int marker = buffer.length();
            if (isPrivate(flags)) buffer.append("private ");
            if (isProtected(flags)) buffer.append("protected ");
            if (isAbstract(flags)) buffer.append("abstract ");
            if (isFinal(flags)) buffer.append("final ");
            if (isSealed(flags)) buffer.append("qualified ");
            if (isInterface(flags)) buffer.append("interface ");
            if (isCase(flags)) buffer.append("case ");
            if (isDef(flags)) buffer.append("def ");
            if (isOverride(flags)) buffer.append("override ");
            int length = buffer.length();
            buffer.setLength(length - (length == marker ? 0 : 1));
        }
    }
}