From 7fec77cc305eeead090f6fef2059146a50a401ce Mon Sep 17 00:00:00 2001 From: Ayman Nadeem Date: Fri, 13 Jul 2018 16:21:34 -0400 Subject: [PATCH] add dimsExpr and arrayCreationExpression assignments and syntaxes --- src/Data/Syntax.hs | 1 - src/Language/Java/Assignment.hs | 18 ++++++++++++++++-- src/Language/Java/Syntax.hs | 18 ++++++++++++++++++ vendor/effects | 2 +- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/Data/Syntax.hs b/src/Data/Syntax.hs index f2e1a40fd..3e6b7f4d4 100644 --- a/src/Data/Syntax.hs +++ b/src/Data/Syntax.hs @@ -64,7 +64,6 @@ handleError = flip Assignment.catchError (\ err -> makeTerm <$> Assignment.locat parseError :: (HasCallStack, Error :< syntaxes, Bounded grammar, Enum grammar, Ix grammar, Apply Foldable syntaxes) => Assignment.Assignment ast grammar (Term (Sum syntaxes) (Record Location)) parseError = makeTerm <$> Assignment.token maxBound <*> pure (Error (ErrorStack $ errorSite <$> getCallStack (freezeCallStack callStack)) [] (Just "ParseError") []) - -- | Match context terms before a subject term, wrapping both up in a Context term if any context terms matched, or otherwise returning the subject term. contextualize :: (HasCallStack, Context :< syntaxes, Alternative m, Semigroup ann, Apply Foldable syntaxes) => m (Term (Sum syntaxes) ann) diff --git a/src/Language/Java/Assignment.hs b/src/Language/Java/Assignment.hs index 44792e185..464383cb9 100644 --- a/src/Language/Java/Assignment.hs +++ b/src/Language/Java/Assignment.hs @@ -68,8 +68,10 @@ type Syntax = , Expression.This , Java.Syntax.Annotation , Java.Syntax.AnnotationField + , Java.Syntax.ArrayCreationExpression , Java.Syntax.Asterisk , Java.Syntax.Constructor + , Java.Syntax.DimsExpr , Java.Syntax.EnumDeclaration , Java.Syntax.GenericType , Java.Syntax.Import @@ -163,8 +165,9 @@ expressions = makeTerm'' <$> location <*> many expression expressionChoices :: [Assignment Term] expressionChoices = [ - arrayInitializer - , arrayAccess + arrayAccess + , arrayCreationExpression + , arrayInitializer , assignment' , block , binary @@ -176,6 +179,7 @@ expressionChoices = , classInstance , continue , constructorDeclaration + , dimsExpr , explicitConstructorInvocation -- , TODO: constantDeclaration , doWhile @@ -237,6 +241,11 @@ variableDeclaratorList = symbol VariableDeclaratorList *> children (makeDecl <$> makeSingleDecl modifiers type' (target, Nothing) = makeTerm1 (Java.Syntax.Variable modifiers type' target) makeSingleDecl modifiers type' (target, Just value) = makeTerm1 (Statement.Assignment [] (makeTerm1 (Java.Syntax.Variable modifiers type' target)) value) +-- variable declarator -> variable initializer -> expression -> primary -> array creation expression +arrayCreationExpression :: Assignment Term +arrayCreationExpression = symbol Grammar.ArrayCreationExpression *> children (makeTerm1 <$> (Java.Syntax.ArrayCreationExpression <$> (new *> type') <*> many dimsExpr)) + where new = token AnonNew *> pure NewKeyword + localVariableDeclarationStatement :: Assignment Term localVariableDeclarationStatement = symbol LocalVariableDeclarationStatement *> children localVariableDeclaration @@ -359,6 +368,11 @@ return' = makeTerm <$> symbol ReturnStatement <*> (Statement.Return <$> children dims :: Assignment [Term] dims = symbol Dims *> children (many (emptyTerm <* token AnonLBracket <* token AnonRBracket)) +-- not sure why we did <* token with the dims (possibly because it's the only thing happening?) +-- will define with manyTerm annotation <*> manyTerm expression and then revisit whether or not I need brackets +dimsExpr :: Assignment Term +dimsExpr = makeTerm <$> symbol Grammar.DimsExpr <*> children (Java.Syntax.DimsExpr <$> manyTerm annotation <*> manyTerm expression) + type' :: Assignment Term type' = choice [ makeTerm <$> token VoidType <*> pure Type.Void diff --git a/src/Language/Java/Syntax.hs b/src/Language/Java/Syntax.hs index ac6793cfe..d8f6ce1b3 100644 --- a/src/Language/Java/Syntax.hs +++ b/src/Language/Java/Syntax.hs @@ -226,3 +226,21 @@ instance Ord1 LambdaBody where liftCompare = genericLiftCompare instance Show1 LambdaBody where liftShowsPrec = genericLiftShowsPrec instance Evaluatable LambdaBody + +data ArrayCreationExpression a = ArrayCreationExpression { arrayCreationExpressionType :: !a, arrayCreationExpressionDims :: ![a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Mergeable, Ord, Show, ToJSONFields1, Traversable) + +instance Eq1 ArrayCreationExpression where liftEq = genericLiftEq +instance Ord1 ArrayCreationExpression where liftCompare = genericLiftCompare +instance Show1 ArrayCreationExpression where liftShowsPrec = genericLiftShowsPrec + +instance Evaluatable ArrayCreationExpression + +data DimsExpr a = DimsExpr { dimsExprAnnotation :: ![a], dimsExprExpression :: ![a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Mergeable, Ord, Show, ToJSONFields1, Traversable) + +instance Eq1 DimsExpr where liftEq = genericLiftEq +instance Ord1 DimsExpr where liftCompare = genericLiftCompare +instance Show1 DimsExpr where liftShowsPrec = genericLiftShowsPrec + +instance Evaluatable DimsExpr diff --git a/vendor/effects b/vendor/effects index 0b6d04713..105a543cc 160000 --- a/vendor/effects +++ b/vendor/effects @@ -1 +1 @@ -Subproject commit 0b6d04713b70e6b0551b841304fb44c9b1564e9b +Subproject commit 105a543ccc98f2929cf0b1f1e97bcc48dfb8f718