Skip to content

Commit

Permalink
Type and declaration for union added.
Browse files Browse the repository at this point in the history
  • Loading branch information
simpletonDL committed Feb 2, 2021
1 parent a37ad77 commit 72130d3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
35 changes: 27 additions & 8 deletions src/Brahma.FSharp.OpenCL.AST/Types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,11 @@ type Image2DType<'lang>(modifier:bool) =

member this.Modifier = modifier

//[<Struct>]
type StructField<'lang> =
type Field<'lang> =
{ Name: string;
Type: Type<'lang> }

type StructType<'lang>(name: string, fields: List<StructField<'lang>>)=
type StructType<'lang>(name: string, fields: List<Field<'lang>>) =
inherit Type<'lang>()

member this.Fields = fields
Expand All @@ -104,12 +103,18 @@ type StructType<'lang>(name: string, fields: List<StructField<'lang>>)=
// NB: fields are omitted in this check
| _ -> false

type StructDecl<'lang>(structType: StructType<'lang>) =
inherit Node<'lang>()
interface TopDef<'lang>
type UnionType<'lang>(name: string, fields: List<Field<'lang>>) =
inherit Type<'lang>()

member val StructType : StructType<'lang> = structType with get, set
override this.Children = []
member this.Fields = fields
member this.Name = name

override this.Size =
this.Fields
|> List.map (fun f -> f.Type.Size)
|> List.fold max 0

override this.Matches _ = failwith "Not implemented"

type TupleType<'lang>(baseStruct: StructType<'lang>, number:int)=
inherit Type<'lang>()
Expand All @@ -131,3 +136,17 @@ type RefType<'lang>(baseType:Type<'lang>, typeQuals:TypeQualifier<'lang> list) =
this.BaseType.Matches(o.BaseType)
&& this.TypeQuals.Equals(o.TypeQuals)
| _ -> false

type StructDecl<'lang>(structType: StructType<'lang>) =
inherit Node<'lang>()
interface TopDef<'lang>

member val StructType: StructType<'lang> = structType with get, set
override this.Children = []

type UnionDecl<'lang>(unionType: UnionType<'lang>) =
inherit Node<'lang>()
interface TopDef<'lang>

member val UnionType: UnionType<'lang> = unionType with get, set
override this.Children = []
1 change: 1 addition & 0 deletions src/Brahma.FSharp.OpenCL.Printer/Printer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ let Print (ast:AST<'lang>) =
| :? FunDecl<'lang> as fd -> FunDecl.Print fd
| :? CLPragma<'lang> as clp -> Pragmas.Print clp
| :? StructDecl<'lang> as s -> TypeDecl.PrintStructDeclaration s
| :? UnionDecl<'lang> as u -> failwith ""
| :? VarDecl<'lang> as s -> Statements.Print false s
| _ -> failwithf "Printer. Unsupported toplevel declaration: %A" d)
|> aboveListL
Expand Down

0 comments on commit 72130d3

Please sign in to comment.