Skip to content

Commit

Permalink
replace mapping with serializable in compiler (#6308)
Browse files Browse the repository at this point in the history
  • Loading branch information
kostya authored and Serdar Dogruyol committed Jul 28, 2018
1 parent 9b32f7d commit d36a654
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/compiler/crystal/macros/macros.cr
Expand Up @@ -100,7 +100,7 @@ class Crystal::Program
end

record RequireWithTimestamp, filename : String, epoch : Int64 do
JSON.mapping(filename: String, epoch: Int64)
include JSON::Serializable
end

def macro_compile(filename)
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/program.cr
Expand Up @@ -427,7 +427,7 @@ module Crystal
end

record RecordedRequire, filename : String, relative_to : String? do
JSON.mapping(filename: String, relative_to: String?)
include JSON::Serializable
end
property recorded_requires = [] of RecordedRequire

Expand Down
10 changes: 5 additions & 5 deletions src/compiler/crystal/tools/context.cr
Expand Up @@ -32,11 +32,11 @@ module Crystal
end

class ContextResult
JSON.mapping({
status: {type: String},
message: {type: String},
contexts: {type: Array(HashStringType), nilable: true},
})
include JSON::Serializable

property status : String
property message : String
property contexts : Array(HashStringType)?

def initialize(@status, @message)
end
Expand Down
19 changes: 9 additions & 10 deletions src/compiler/crystal/tools/expand.cr
Expand Up @@ -3,11 +3,11 @@ require "./implementations"

module Crystal
struct ExpandResult
JSON.mapping({
status: {type: String},
message: {type: String},
expansions: {type: Array(Expansion), nilable: true},
})
include JSON::Serializable

property status : String
property message : String
property expansions : Array(Expansion)?

def initialize(@status, @message)
end
Expand Down Expand Up @@ -35,13 +35,12 @@ module Crystal
end

struct Expansion
include JSON::Serializable
alias MacroImplementation = {name: String, implementation: ImplementationTrace}

JSON.mapping({
original_source: {type: String},
expanded_sources: {type: Array(String)},
expanded_macros: {type: Array(Array(MacroImplementation))},
})
property original_source : String
property expanded_sources : Array(String)
property expanded_macros : Array(Array(MacroImplementation))

def initialize(@original_source, @expanded_sources, @expanded_macros)
end
Expand Down
23 changes: 11 additions & 12 deletions src/compiler/crystal/tools/implementations.cr
Expand Up @@ -5,11 +5,10 @@ require "json"

module Crystal
class ImplementationResult
JSON.mapping({
status: {type: String},
message: {type: String},
implementations: {type: Array(ImplementationTrace), nilable: true},
})
include JSON::Serializable
property status : String
property message : String
property implementations : Array(ImplementationTrace)?

def initialize(@status, @message)
end
Expand All @@ -33,13 +32,13 @@ module Crystal
# It keeps track of macro expansion in a human friendly way and
# pointing to the exact line an expansion and method definition occurs.
class ImplementationTrace
JSON.mapping({
line: {type: Int32},
column: {type: Int32},
filename: {type: String},
macro: {type: String, nilable: true},
expands: {type: ImplementationTrace, nilable: true},
})
include JSON::Serializable

property line : Int32
property column : Int32
property filename : String
property macro : String?
property expands : ImplementationTrace?

def initialize(loc : Location)
f = loc.filename
Expand Down

0 comments on commit d36a654

Please sign in to comment.