Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace mapping with serializable in compiler #6308

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/crystal/macros/macros.cr
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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