Class: Carbon::Compiler::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/carbon/compiler/project.rb,
lib/carbon/compiler/project/file.rb

Defined Under Namespace

Classes: File

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(files, root, libraries: []) ⇒ Project

Returns a new instance of Project.



15
16
17
18
19
20
21
# File 'lib/carbon/compiler/project.rb', line 15

def initialize(files, root, libraries: [])
  @root = Pathname.new(root).expand_path(Dir.pwd)
  @files = files.map { |f| Project::File.new(f, @root, self) }
  @diagnostics = Metanostic::List.new
  @libraries = []
  @files.each { |f| @diagnostics.files[f.short] = f }
end

Instance Attribute Details

#diagnosticsObject (readonly)

Returns the value of attribute diagnostics.



11
12
13
# File 'lib/carbon/compiler/project.rb', line 11

def diagnostics
  @diagnostics
end

#itemsObject (readonly)

Returns the value of attribute items.



12
13
14
# File 'lib/carbon/compiler/project.rb', line 12

def items
  @items
end

#mainObject (readonly)

Returns the value of attribute main.



13
14
15
# File 'lib/carbon/compiler/project.rb', line 13

def main
  @main
end

Instance Method Details

#callObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/carbon/compiler/project.rb', line 23

def call
  @index ||= begin
    @index = Concrete::Index.new
    @files.each { |f| f.call(@index, @diagnostics.clone) }
    # load libraries...
    @libraries.each do |library|
      @index.link(Carbon::Concrete.load(::File.read(library, "rb")))
    end
    @index.link(Carbon::Core.index)
    @index.finalize
  end
end