class
compiler::InitInput
sys::Obj
compiler::CompilerSupport
compiler::CompilerStep
compiler::InitInput
1 //
2 // Copyright (c) 2006, Brian Frank and Andy Frank
3 // Licensed under the Academic Free License version 3.0
4 //
5 // History:
6 // 5 Jun 06 Brian Frank Creation
7 //
8
9 **
10 ** InitInput is responsible:
11 ** - verifies the CompilerInput instance
12 ** - checks the depends dir
13 ** - constructs the appropiate Namespace
14 ** - initializes Comiler.pod with a PodDef
15 ** - tokenizes the source code from file or string input
16 **
17 class InitInput : CompilerStep
18 {
19
20 //////////////////////////////////////////////////////////////////////////
21 // Construction
22 //////////////////////////////////////////////////////////////////////////
23
24 **
25 ** Constructor takes the associated Compiler
26 **
27 new make(Compiler compiler)
28 : super(compiler)
29 {
30 loc = compiler.input.inputLoc
31 }
32
33 //////////////////////////////////////////////////////////////////////////
34 // Methods
35 //////////////////////////////////////////////////////////////////////////
36
37 **
38 ** Run the step
39 **
40 override Void run()
41 {
42 // validate input
43 input := compiler.input
44 try
45 {
46 input.validate
47 }
48 catch (CompilerErr err)
49 {
50 throw errReport(err)
51 }
52
53 // figure out where our depends are coming from
54 checkDependsDir(input)
55
56 // create the appropiate namespace
57 if (input.dependsDir == null)
58 compiler.ns = ReflectNamespace.make
59 else
60 compiler.ns = FPodNamespace.make(input.dependsDir)
61
62 // init pod
63 podName := input.podName
64 compiler.pod = PodDef.make(ns, Location.make(podName), podName)
65 compiler.isSys = podName == "sys"
66
67 // process intput into tokens
68 switch (input.mode)
69 {
70 case CompilerInputMode.str:
71 Tokenize.make(compiler).runSource(input.srcStrLocation, input.srcStr)
72 case CompilerInputMode.file:
73 FindSourceFiles.make(compiler).run
74 Tokenize.make(compiler).run
75 default:
76 throw err("Unknown input mode $input.mode", null)
77 }
78 }
79
80 **
81 ** If depends home is not null, then check it out.
82 **
83 private Void checkDependsDir(CompilerInput input)
84 {
85 // if null then we are using
86 // compiler's own pods via reflection
87 dir := input.dependsDir
88 if (dir == null) return
89
90 // check that it isn't the same as Sys.homeDir, in
91 // which we're better off using reflection
92 if (dir.normalize == (Sys.homeDir + `lib/fan/`).normalize)
93 {
94 input.dependsDir = null
95 return
96 }
97
98 // check that fan pods directory exists
99 if (!dir.exists) throw err("Invalid dependsHomeDir: $dir", loc)
100
101 // save it away
102 input.dependsDir = dir
103 log.message("Depends [$dir]")
104 }
105
106 //////////////////////////////////////////////////////////////////////////
107 // Fields
108 //////////////////////////////////////////////////////////////////////////
109
110 private Location loc
111 }
2 // Copyright (c) 2006, Brian Frank and Andy Frank
3 // Licensed under the Academic Free License version 3.0
4 //
5 // History:
6 // 5 Jun 06 Brian Frank Creation
7 //
8
9 **
10 ** InitInput is responsible:
11 ** - verifies the CompilerInput instance
12 ** - checks the depends dir
13 ** - constructs the appropiate Namespace
14 ** - initializes Comiler.pod with a PodDef
15 ** - tokenizes the source code from file or string input
16 **
17 class InitInput : CompilerStep
18 {
19
20 //////////////////////////////////////////////////////////////////////////
21 // Construction
22 //////////////////////////////////////////////////////////////////////////
23
24 **
25 ** Constructor takes the associated Compiler
26 **
27 new make(Compiler compiler)
28 : super(compiler)
29 {
30 loc = compiler.input.inputLoc
31 }
32
33 //////////////////////////////////////////////////////////////////////////
34 // Methods
35 //////////////////////////////////////////////////////////////////////////
36
37 **
38 ** Run the step
39 **
40 override Void run()
41 {
42 // validate input
43 input := compiler.input
44 try
45 {
46 input.validate
47 }
48 catch (CompilerErr err)
49 {
50 throw errReport(err)
51 }
52
53 // figure out where our depends are coming from
54 checkDependsDir(input)
55
56 // create the appropiate namespace
57 if (input.dependsDir == null)
58 compiler.ns = ReflectNamespace.make
59 else
60 compiler.ns = FPodNamespace.make(input.dependsDir)
61
62 // init pod
63 podName := input.podName
64 compiler.pod = PodDef.make(ns, Location.make(podName), podName)
65 compiler.isSys = podName == "sys"
66
67 // process intput into tokens
68 switch (input.mode)
69 {
70 case CompilerInputMode.str:
71 Tokenize.make(compiler).runSource(input.srcStrLocation, input.srcStr)
72 case CompilerInputMode.file:
73 FindSourceFiles.make(compiler).run
74 Tokenize.make(compiler).run
75 default:
76 throw err("Unknown input mode $input.mode", null)
77 }
78 }
79
80 **
81 ** If depends home is not null, then check it out.
82 **
83 private Void checkDependsDir(CompilerInput input)
84 {
85 // if null then we are using
86 // compiler's own pods via reflection
87 dir := input.dependsDir
88 if (dir == null) return
89
90 // check that it isn't the same as Sys.homeDir, in
91 // which we're better off using reflection
92 if (dir.normalize == (Sys.homeDir + `lib/fan/`).normalize)
93 {
94 input.dependsDir = null
95 return
96 }
97
98 // check that fan pods directory exists
99 if (!dir.exists) throw err("Invalid dependsHomeDir: $dir", loc)
100
101 // save it away
102 input.dependsDir = dir
103 log.message("Depends [$dir]")
104 }
105
106 //////////////////////////////////////////////////////////////////////////
107 // Fields
108 //////////////////////////////////////////////////////////////////////////
109
110 private Location loc
111 }