Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ee730f8de3a9
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3c49ed5416d7
Choose a head ref
  • 2 commits
  • 3 files changed
  • 2 contributors

Commits on Aug 30, 2016

  1. Copy the full SHA
    753e58b View commit details
  2. Merge pull request #3213 from ozra/clean-dry-refactor

    Simple refactor to unify code duplication.
    bcardiff authored Aug 30, 2016
    Copy the full SHA
    3c49ed5 View commit details
Showing with 18 additions and 26 deletions.
  1. +16 −0 src/compiler/crystal/program.cr
  2. +1 −13 src/compiler/crystal/semantic/main_visitor.cr
  3. +1 −13 src/compiler/crystal/semantic/type_guess_visitor.cr
16 changes: 16 additions & 0 deletions src/compiler/crystal/program.cr
Original file line number Diff line number Diff line change
@@ -425,6 +425,22 @@ module Crystal
@hash_type.not_nil!
end

def type_from_literal_kind(kind)
case kind
when :i8 then int8
when :i16 then int16
when :i32 then int32
when :i64 then int64
when :u8 then uint8
when :u16 then uint16
when :u32 then uint32
when :u64 then uint64
when :f32 then float32
when :f64 then float64
else raise "Invalid node kind: #{kind}"
end
end

# Returns the `IntegerType` that matches the given Int value
def int?(int)
case int
14 changes: 1 addition & 13 deletions src/compiler/crystal/semantic/main_visitor.cr
Original file line number Diff line number Diff line change
@@ -2538,19 +2538,7 @@ module Crystal
end

def visit(node : NumberLiteral)
node.type = case node.kind
when :i8 then program.int8
when :i16 then program.int16
when :i32 then program.int32
when :i64 then program.int64
when :u8 then program.uint8
when :u16 then program.uint16
when :u32 then program.uint32
when :u64 then program.uint64
when :f32 then program.float32
when :f64 then program.float64
else raise "Invalid node kind: #{node.kind}"
end
node.type = program.type_from_literal_kind node.kind
end

def visit(node : CharLiteral)
14 changes: 1 addition & 13 deletions src/compiler/crystal/semantic/type_guess_visitor.cr
Original file line number Diff line number Diff line change
@@ -403,19 +403,7 @@ module Crystal
end

def guess_type(node : NumberLiteral)
case node.kind
when :i8 then program.int8
when :i16 then program.int16
when :i32 then program.int32
when :i64 then program.int64
when :u8 then program.uint8
when :u16 then program.uint16
when :u32 then program.uint32
when :u64 then program.uint64
when :f32 then program.float32
when :f64 then program.float64
else raise "Invalid node kind: #{node.kind}"
end
program.type_from_literal_kind node.kind
end

def guess_type(node : CharLiteral)