summaryrefslogtreecommitdiff
path: root/sources/scalac/ast/parser/ParserPhase.java
blob: 204fb2b925127546e039be1d9a0fdcb1603458cc (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
/*     ____ ____  ____ ____  ______                                     *\
**    / __// __ \/ __// __ \/ ____/    SOcos COmpiles Scala             **
**  __\_ \/ /_/ / /__/ /_/ /\_ \       (c) 2002, LAMP/EPFL              **
** /_____/\____/\___/\____/____/                                        **
**
** $Id$
\*                                                                      */

package scalac.ast.parser;

import java.io.*;
import scalac.*;

public class ParserPhase extends PhaseDescriptor {

    public String name() {
        return "parse";
    }

    public String description () {
        return "parse source files";
    }

    public String taskDescription() {
        return "parsed";
    }

    public Phase createPhase(Global global) {
	return new ParserWorker(global, this);
    }
}

public class ParserWorker extends Phase {

    /** constructor
     */
    public ParserWorker(Global global, PhaseDescriptor descr) {
        super(global, descr);
    }

    /** apply this phase to all compilation units
     */
    public void apply() {
        super.apply();
        int count = 0;
        for (int i = 0; i < global.units.length; i++) {
            if (global.units[i].body != null) count++;
        }
        Unit[] units = new Unit[count];
        for (int i = 0, j = 0; i < global.units.length; i++) {
            if (global.units[i].body != null) units[j++] = global.units[i];
        }
        global.units = units;
    }

    /** apply this phase to the given compilation unit
     */
    public void apply(Unit unit) {
        global.start();
        unit.body = new Parser(unit).parse();
        global.stop("parsed " + unit.source);
    }
}