Skip to content

Commit

Permalink
add Range type
Browse files Browse the repository at this point in the history
  • Loading branch information
Péter Diviánszky committed Feb 26, 2016
1 parent c0d3852 commit 5ea5e05
Show file tree
Hide file tree
Showing 31 changed files with 197 additions and 70 deletions.
9 changes: 7 additions & 2 deletions ddl/Definitions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,17 @@ mesh = do
]

typeInfo = do
data_ "TypeInfo" $ do
constR_ "TypeInfo"
data_ "Range" $ do
constR_ "Range"
[ "startLine" #:: Int
, "startColumn" #:: Int
, "endLine" #:: Int
, "endColumn" #:: Int
]

data_ "TypeInfo" $ do
constR_ "TypeInfo"
[ "range" #:: "Range"
, "text" #:: String
]

Expand Down
2 changes: 1 addition & 1 deletion ddl/out/LambdaCube.IR.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// generated file, do not modify!
// 2016-02-26T10:42:56.948155000000Z
// 2016-02-26T11:29:11.442441000000Z

#include "LambdaCube.IR.hpp"
template<> json toJSON<std::shared_ptr<ArrayValue>>(std::shared_ptr<ArrayValue> &v) {
Expand Down
2 changes: 1 addition & 1 deletion ddl/out/LambdaCube.IR.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// generated file, do not modify!
// 2016-02-26T10:42:56.948155000000Z
// 2016-02-26T11:29:11.442441000000Z

#ifndef HEADER_LambdaCube.IR_H
#define HEADER_LambdaCube.IR_H
Expand Down
2 changes: 1 addition & 1 deletion ddl/out/LambdaCube.IR.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- generated file, do not modify!
-- 2016-02-26T10:42:56.948155000000Z
-- 2016-02-26T11:29:11.442441000000Z

{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
module LambdaCube.IR where
Expand Down
2 changes: 1 addition & 1 deletion ddl/out/LambdaCube.IR.purs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- generated file, do not modify!
-- 2016-02-26T10:42:56.948155000000Z
-- 2016-02-26T11:29:11.442441000000Z

module LambdaCube.IR where
import Prelude
Expand Down
2 changes: 1 addition & 1 deletion ddl/out/LambdaCube.IR.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// generated file, do not modify!
// 2016-02-26T10:42:56.948155000000Z
// 2016-02-26T11:29:11.442441000000Z

typealias StreamName = Int

Expand Down
2 changes: 1 addition & 1 deletion ddl/out/LambdaCube.IR2.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// generated file, do not modify!
// 2016-02-26T10:42:56.948155000000Z
// 2016-02-26T11:29:11.442441000000Z

#ifndef HEADER_LambdaCube.IR_H
#define HEADER_LambdaCube.IR_H
Expand Down
2 changes: 1 addition & 1 deletion ddl/out/LambdaCube.Mesh.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// generated file, do not modify!
// 2016-02-26T10:42:57.342809000000Z
// 2016-02-26T11:29:11.794796000000Z

#include "LambdaCube.Mesh.hpp"
template<> json toJSON<std::shared_ptr<MeshAttribute>>(std::shared_ptr<MeshAttribute> &v) {
Expand Down
2 changes: 1 addition & 1 deletion ddl/out/LambdaCube.Mesh.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// generated file, do not modify!
// 2016-02-26T10:42:57.342809000000Z
// 2016-02-26T11:29:11.794796000000Z

#ifndef HEADER_LambdaCube.Mesh_H
#define HEADER_LambdaCube.Mesh_H
Expand Down
2 changes: 1 addition & 1 deletion ddl/out/LambdaCube.Mesh.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- generated file, do not modify!
-- 2016-02-26T10:42:57.342809000000Z
-- 2016-02-26T11:29:11.794796000000Z

{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
module LambdaCube.Mesh where
Expand Down
2 changes: 1 addition & 1 deletion ddl/out/LambdaCube.Mesh.purs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- generated file, do not modify!
-- 2016-02-26T10:42:57.342809000000Z
-- 2016-02-26T11:29:11.794796000000Z

module LambdaCube.Mesh where
import Prelude
Expand Down
2 changes: 1 addition & 1 deletion ddl/out/LambdaCube.Mesh.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// generated file, do not modify!
// 2016-02-26T10:42:57.342809000000Z
// 2016-02-26T11:29:11.794796000000Z

enum MeshAttribute {
case A_Float(Array<Float>)
Expand Down
2 changes: 1 addition & 1 deletion ddl/out/LambdaCube.Mesh2.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// generated file, do not modify!
// 2016-02-26T10:42:57.342809000000Z
// 2016-02-26T11:29:11.794796000000Z

#ifndef HEADER_LambdaCube.Mesh_H
#define HEADER_LambdaCube.Mesh_H
Expand Down
2 changes: 1 addition & 1 deletion ddl/out/LambdaCube.PipelineSchema.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// generated file, do not modify!
// 2016-02-26T10:42:57.323154000000Z
// 2016-02-26T11:29:11.775644000000Z

#include "LambdaCube.PipelineSchema.hpp"
template<> json toJSON<std::shared_ptr<StreamType>>(std::shared_ptr<StreamType> &v) {
Expand Down
2 changes: 1 addition & 1 deletion ddl/out/LambdaCube.PipelineSchema.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// generated file, do not modify!
// 2016-02-26T10:42:57.323154000000Z
// 2016-02-26T11:29:11.775644000000Z

#ifndef HEADER_LambdaCube.PipelineSchema_H
#define HEADER_LambdaCube.PipelineSchema_H
Expand Down
2 changes: 1 addition & 1 deletion ddl/out/LambdaCube.PipelineSchema.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- generated file, do not modify!
-- 2016-02-26T10:42:57.323154000000Z
-- 2016-02-26T11:29:11.775644000000Z

{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
module LambdaCube.PipelineSchema where
Expand Down
2 changes: 1 addition & 1 deletion ddl/out/LambdaCube.PipelineSchema.purs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- generated file, do not modify!
-- 2016-02-26T10:42:57.323154000000Z
-- 2016-02-26T11:29:11.775644000000Z

module LambdaCube.PipelineSchema where
import Prelude
Expand Down
2 changes: 1 addition & 1 deletion ddl/out/LambdaCube.PipelineSchema.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// generated file, do not modify!
// 2016-02-26T10:42:57.323154000000Z
// 2016-02-26T11:29:11.775644000000Z

enum StreamType {
case Attribute_Word
Expand Down
2 changes: 1 addition & 1 deletion ddl/out/LambdaCube.PipelineSchema2.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// generated file, do not modify!
// 2016-02-26T10:42:57.323154000000Z
// 2016-02-26T11:29:11.775644000000Z

#ifndef HEADER_LambdaCube.PipelineSchema_H
#define HEADER_LambdaCube.PipelineSchema_H
Expand Down
47 changes: 38 additions & 9 deletions ddl/out/LambdaCube.TypeInfo.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,50 @@
// generated file, do not modify!
// 2016-02-26T10:42:57.376331000000Z
// 2016-02-26T11:29:11.823283000000Z

#include "LambdaCube.TypeInfo.hpp"
template<> json toJSON<std::shared_ptr<TypeInfo>>(std::shared_ptr<TypeInfo> &v) {
template<> json toJSON<std::shared_ptr<Range>>(std::shared_ptr<Range> &v) {
json obj({});
switch (v->tag) {
case ::TypeInfo::tag::TypeInfo:
obj["tag"] = "TypeInfo";
case ::Range::tag::Range:
obj["tag"] = "Range";
{
std::shared_ptr<data::TypeInfo> tv = std::static_pointer_cast<data::TypeInfo>(v);
std::shared_ptr<data::Range> tv = std::static_pointer_cast<data::Range>(v);
obj["startLine"] = toJSON(tv->startLine);
obj["startColumn"] = toJSON(tv->startColumn);
obj["endLine"] = toJSON(tv->endLine);
obj["endColumn"] = toJSON(tv->endColumn);
}
break;
}
return obj;
}

template<> std::shared_ptr<Range> fromJSON<std::shared_ptr<Range>>(W<std::shared_ptr<Range>> v, json &obj) {
enum ::Range::tag tagType;
std::string tag = obj["tag"];
if (tag == "Range") {
tagType = ::Range::tag::Range;
std::shared_ptr<data::Range> tv(new data::Range());
tv->startLine = fromJSON(W<Int>(), obj["startLine"]);
tv->startColumn = fromJSON(W<Int>(), obj["startColumn"]);
tv->endLine = fromJSON(W<Int>(), obj["endLine"]);
tv->endColumn = fromJSON(W<Int>(), obj["endColumn"]);
return tv;
}
else throw "unknown constructor: " + tag;
std::shared_ptr<::Range> o(new ::Range());
o->tag = tagType;
return o;
}

template<> json toJSON<std::shared_ptr<TypeInfo>>(std::shared_ptr<TypeInfo> &v) {
json obj({});
switch (v->tag) {
case ::TypeInfo::tag::TypeInfo:
obj["tag"] = "TypeInfo";
{
std::shared_ptr<data::TypeInfo> tv = std::static_pointer_cast<data::TypeInfo>(v);
obj["range"] = toJSON(tv->range);
obj["text"] = toJSON(tv->text);
}
break;
Expand All @@ -26,10 +58,7 @@ template<> std::shared_ptr<TypeInfo> fromJSON<std::shared_ptr<TypeInfo>>(W<std::
if (tag == "TypeInfo") {
tagType = ::TypeInfo::tag::TypeInfo;
std::shared_ptr<data::TypeInfo> tv(new data::TypeInfo());
tv->startLine = fromJSON(W<Int>(), obj["startLine"]);
tv->startColumn = fromJSON(W<Int>(), obj["startColumn"]);
tv->endLine = fromJSON(W<Int>(), obj["endLine"]);
tv->endColumn = fromJSON(W<Int>(), obj["endColumn"]);
tv->range = fromJSON(W<std::shared_ptr<::Range>>(), obj["range"]);
tv->text = fromJSON(W<String>(), obj["text"]);
return tv;
}
Expand Down
21 changes: 17 additions & 4 deletions ddl/out/LambdaCube.TypeInfo.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// generated file, do not modify!
// 2016-02-26T10:42:57.376331000000Z
// 2016-02-26T11:29:11.823283000000Z

#ifndef HEADER_LambdaCube.TypeInfo_H
#define HEADER_LambdaCube.TypeInfo_H
Expand All @@ -8,19 +8,32 @@

#include "LambdaCube.IR.hpp"

class TypeInfo {
class Range {
public:
enum class tag {
TypeInfo
Range
} tag;
};
namespace data {
class TypeInfo : public ::TypeInfo {
class Range : public ::Range {
public:
Int startLine;
Int startColumn;
Int endLine;
Int endColumn;
Range() { tag = tag::Range; }
};
}
class TypeInfo {
public:
enum class tag {
TypeInfo
} tag;
};
namespace data {
class TypeInfo : public ::TypeInfo {
public:
std::shared_ptr<::Range> range;
String text;
TypeInfo() { tag = tag::TypeInfo; }
};
Expand Down
47 changes: 36 additions & 11 deletions ddl/out/LambdaCube.TypeInfo.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- generated file, do not modify!
-- 2016-02-26T10:42:57.376331000000Z
-- 2016-02-26T11:29:11.823283000000Z

{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
module LambdaCube.TypeInfo where
Expand All @@ -17,12 +17,19 @@ import Control.Monad

import LambdaCube.IR

data TypeInfo
= TypeInfo
data Range
= Range
{ startLine :: Int
, startColumn :: Int
, endLine :: Int
, endColumn :: Int
}

deriving (Show, Eq, Ord)

data TypeInfo
= TypeInfo
{ range :: Range
, text :: String
}

Expand All @@ -34,32 +41,50 @@ data CompileResult
deriving (Show, Eq, Ord)


instance ToJSON TypeInfo where
instance ToJSON Range where
toJSON v = case v of
TypeInfo{..} -> object
[ "tag" .= ("TypeInfo" :: Text)
Range{..} -> object
[ "tag" .= ("Range" :: Text)
, "startLine" .= startLine
, "startColumn" .= startColumn
, "endLine" .= endLine
, "endColumn" .= endColumn
, "text" .= text
]

instance FromJSON TypeInfo where
instance FromJSON Range where
parseJSON (Object obj) = do
tag <- obj .: "tag"
case tag :: Text of
"TypeInfo" -> do
"Range" -> do
startLine <- obj .: "startLine"
startColumn <- obj .: "startColumn"
endLine <- obj .: "endLine"
endColumn <- obj .: "endColumn"
text <- obj .: "text"
pure $ TypeInfo
pure $ Range
{ startLine = startLine
, startColumn = startColumn
, endLine = endLine
, endColumn = endColumn
}
parseJSON _ = mzero

instance ToJSON TypeInfo where
toJSON v = case v of
TypeInfo{..} -> object
[ "tag" .= ("TypeInfo" :: Text)
, "range" .= range
, "text" .= text
]

instance FromJSON TypeInfo where
parseJSON (Object obj) = do
tag <- obj .: "tag"
case tag :: Text of
"TypeInfo" -> do
range <- obj .: "range"
text <- obj .: "text"
pure $ TypeInfo
{ range = range
, text = text
}
parseJSON _ = mzero
Expand Down
Loading

0 comments on commit 5ea5e05

Please sign in to comment.