never executed always true always false
    1 -- Copyright (C) 2018-2024 Jun Zhang <zhangjunphy[at]gmail[dot]com>
    2 --
    3 -- This file is a part of decafc.
    4 --
    5 -- decafc is free software: you can redistribute it and/or modify it under the
    6 -- terms of the MIT (X11) License as described in the LICENSE file.
    7 --
    8 -- decafc is distributed in the hope that it will be useful, but WITHOUT ANY
    9 -- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   10 -- FOR A PARTICULAR PURPOSE.  See the X11 license for more details.
   11 
   12 module Parser.Tree where
   13 
   14 import Data.Text (Text)
   15 import Util.SourceLoc as SL
   16 
   17 data Program = Program
   18   { importDecls :: ![SL.Located ImportDecl],
   19     fieldDecls :: ![SL.Located FieldDecl],
   20     methodDecls :: ![SL.Located MethodDecl]
   21   }
   22   deriving (Show)
   23 
   24 data ImportDecl = ImportDecl {importId :: !Text}
   25   deriving (Show)
   26 
   27 data FieldDecl = FieldDecl
   28   { fieldType :: !Type,
   29     elems :: ![SL.Located FieldElem]
   30   }
   31   deriving (Show)
   32 
   33 data FieldElem
   34   = ScalarField {fieldId :: !Text}
   35   | VectorField {fieldId :: !Text, size :: !Text}
   36   deriving (Show)
   37 
   38 data Type = IntType | BoolType
   39   deriving (Show)
   40 
   41 data MethodDecl = MethodDecl
   42   { methodId :: !Text,
   43     returnType :: !(Maybe Type),
   44     arguments :: ![SL.Located Argument],
   45     block :: !Block
   46   }
   47   deriving (Show)
   48 
   49 data Argument = Argument
   50   { argumentId :: !Text,
   51     argumentType :: !Type
   52   }
   53   deriving (Show)
   54 
   55 data Block = Block
   56   { blockFieldDecls :: ![SL.Located FieldDecl],
   57     blockStatements :: ![SL.Located Statement]
   58   }
   59   deriving (Show)
   60 
   61 data Statement
   62   = AssignStatement {assignLocation :: !Location, assignExpr :: !AssignExpr}
   63   | MethodCallStatement {methodCallStatement :: !MethodCall}
   64   | IfStatement {ifExpr :: !(SL.Located Expr), ifBlock :: !Block}
   65   | IfElseStatement {ifExpr :: !(SL.Located Expr), ifBlock :: !Block, elseBlock :: !Block}
   66   | ForStatement
   67       { counterId :: !Text,
   68         counterExpr :: !(SL.Located Expr),
   69         forPredExpr :: !(SL.Located Expr),
   70         counterUpdate :: !CounterUpdate,
   71         forBlock :: !Block
   72       }
   73   | WhileStatement {whileExpr :: !(SL.Located Expr), whileBlock :: !Block}
   74   | ReturnVoidStatement
   75   | ReturnExprStatement {returnExpr :: !(SL.Located Expr)}
   76   | BreakStatement
   77   | ContinueStatement
   78   | ErrorStatement
   79   deriving (Show)
   80 
   81 data Location
   82   = ScalarLocation {locationId :: !Text}
   83   | VectorLocation {locationId :: !Text, arrayIndexExpr :: !(SL.Located Expr)}
   84   deriving (Show)
   85 
   86 data AssignExpr
   87   = AssignExpr {assignOp :: !Text, assignSourceExpr :: !(SL.Located Expr)}
   88   | IncrementExpr {incrementOp :: !Text}
   89   deriving (Show)
   90 
   91 data MethodCall = MethodCall {methodName :: !Text, importArguments :: ![SL.Located ImportArg]}
   92   deriving (Show)
   93 
   94 data ImportArg
   95   = ExprImportArg {argumentExpr :: !(SL.Located Expr)}
   96   | StringImportArg {argumentString :: !Text}
   97   deriving (Show)
   98 
   99 data CounterUpdate = CounterUpdate {counterLocation :: !Location, updateExpr :: !AssignExpr}
  100   deriving (Show)
  101 
  102 data Expr
  103   = LocationExpr {location :: !Location}
  104   | MethodCallExpr {methodCallExpr :: !MethodCall}
  105   | IntLiteralExpr {intLiteral :: !Text}
  106   | CharLiteralExpr {charLiteral :: !Text}
  107   | BoolLiteralExpr {boolLiteral :: !Text}
  108   | LenExpr {lenId :: !Text}
  109   | ArithOpExpr {arithOp :: !Text, lExpr :: !(SL.Located Expr), rExpr :: !(SL.Located Expr)}
  110   | RelOpExpr {relOp :: !Text, lExpr :: !(SL.Located Expr), rExpr :: !(SL.Located Expr)}
  111   | EqOpExpr {eqOp :: !Text, lExpr :: !(SL.Located Expr), rExpr :: !(SL.Located Expr)}
  112   | CondOpExpr {condOp :: !Text, lExpr :: !(SL.Located Expr), rExpr :: !(SL.Located Expr)}
  113   | NegativeExpr {negativeExpr :: !(SL.Located Expr)}
  114   | NegateExpr {negateExpr :: !(SL.Located Expr)}
  115   | ParenExpr {parenExpr :: !(SL.Located Expr)}
  116   | ChoiceExpr {choicePredExpr :: !(SL.Located Expr), lExpr :: !(SL.Located Expr), rExpr :: !(SL.Located Expr)}
  117   deriving (Show)