module Hydra.Ext.Java.Language where

import Hydra.All

import qualified Data.Set as S


javaLanguage :: Language m
javaLanguage :: forall m. Language m
javaLanguage = forall m. LanguageName -> LanguageConstraints m -> Language m
Language (String -> LanguageName
LanguageName String
"hydra/ext/java") forall a b. (a -> b) -> a -> b
$ LanguageConstraints {
  languageConstraintsEliminationVariants :: Set EliminationVariant
languageConstraintsEliminationVariants = forall a. Ord a => [a] -> Set a
S.fromList [EliminationVariant]
eliminationVariants,

  languageConstraintsLiteralVariants :: Set LiteralVariant
languageConstraintsLiteralVariants = forall a. Ord a => [a] -> Set a
S.fromList [
    LiteralVariant
LiteralVariantBoolean, -- boolean
    LiteralVariant
LiteralVariantFloat, -- (see float types)
    LiteralVariant
LiteralVariantInteger, -- (see integer types)
    LiteralVariant
LiteralVariantString], -- string
  languageConstraintsFloatTypes :: Set FloatType
languageConstraintsFloatTypes = forall a. Ord a => [a] -> Set a
S.fromList [
    -- Bigfloat (e.g. as Java's BigDecimal) is excluded for now
    FloatType
FloatTypeFloat32, -- float
    FloatType
FloatTypeFloat64], -- double
  languageConstraintsFunctionVariants :: Set FunctionVariant
languageConstraintsFunctionVariants = forall a. Ord a => [a] -> Set a
S.fromList [FunctionVariant]
functionVariants,
  languageConstraintsIntegerTypes :: Set IntegerType
languageConstraintsIntegerTypes = forall a. Ord a => [a] -> Set a
S.fromList [
    IntegerType
IntegerTypeBigint, -- BigInteger
    IntegerType
IntegerTypeInt16, -- short
    IntegerType
IntegerTypeInt32, -- int
    IntegerType
IntegerTypeInt64, -- long
    IntegerType
IntegerTypeUint8, -- byte
    IntegerType
IntegerTypeUint16], -- char
  languageConstraintsTermVariants :: Set TermVariant
languageConstraintsTermVariants = forall a. Ord a => [a] -> Set a
S.fromList [
    TermVariant
TermVariantApplication,
    TermVariant
TermVariantElement,
    TermVariant
TermVariantFunction,
    -- Note: "let" is excluded for now
    TermVariant
TermVariantList,
    TermVariant
TermVariantLiteral,
    TermVariant
TermVariantMap,
    TermVariant
TermVariantNominal,
    TermVariant
TermVariantOptional,
    TermVariant
TermVariantRecord,
    TermVariant
TermVariantSet,
    TermVariant
TermVariantUnion,
    TermVariant
TermVariantVariable],
  languageConstraintsTypeVariants :: Set TypeVariant
languageConstraintsTypeVariants = forall a. Ord a => [a] -> Set a
S.fromList [
    TypeVariant
TypeVariantAnnotated,
    TypeVariant
TypeVariantApplication,
    TypeVariant
TypeVariantElement,
    TypeVariant
TypeVariantFunction,
    TypeVariant
TypeVariantLambda,
    TypeVariant
TypeVariantList,
    TypeVariant
TypeVariantLiteral,
    TypeVariant
TypeVariantMap,
    TypeVariant
TypeVariantNominal,
    TypeVariant
TypeVariantOptional,
    TypeVariant
TypeVariantRecord,
    TypeVariant
TypeVariantSet,
    TypeVariant
TypeVariantUnion,
    TypeVariant
TypeVariantVariable],
  languageConstraintsTypes :: Type m -> Bool
languageConstraintsTypes = forall a b. a -> b -> a
const Bool
True }

reservedWords :: S.Set String
reservedWords :: Set String
reservedWords = forall a. Ord a => [a] -> Set a
S.fromList forall a b. (a -> b) -> a -> b
$ [String]
specialNames forall a. [a] -> [a] -> [a]
++ [String]
classNames forall a. [a] -> [a] -> [a]
++ [String]
keywords forall a. [a] -> [a] -> [a]
++ [String]
literals
  where
    -- Special names reserved for use by Hydra
    specialNames :: [String]
specialNames = [String
"Elements"]

    -- java.lang classes as of JDK 7
    -- See: https://docs.oracle.com/javase/7/docs/api/java/lang/package-summary.html
    classNames :: [String]
classNames = [
      String
"AbstractMethodError", String
"Appendable", String
"ArithmeticException", String
"ArrayIndexOutOfBoundsException",
      String
"ArrayStoreException", String
"AssertionError", String
"AutoCloseable", String
"Boolean", String
"BootstrapMethodError", String
"Byte",
      String
"CharSequence", String
"Character", String
"Class", String
"ClassCastException", String
"ClassCircularityError", String
"ClassFormatError",
      String
"ClassLoader", String
"ClassNotFoundException", String
"ClassValue", String
"CloneNotSupportedException", String
"Cloneable", String
"Comparable",
      String
"Compiler", String
"Deprecated", String
"Double", String
"Enum", String
"EnumConstantNotPresentException", String
"Error", String
"Exception",
      String
"ExceptionInInitializerError", String
"Float", String
"IllegalAccessError", String
"IllegalAccessException",
      String
"IllegalArgumentException", String
"IllegalMonitorStateException", String
"IllegalStateException",
      String
"IllegalThreadStateException", String
"IncompatibleClassChangeError", String
"IndexOutOfBoundsException",
      String
"InheritableThreadLocal", String
"InstantiationError", String
"InstantiationException", String
"Integer", String
"InternalError",
      String
"InterruptedException", String
"Iterable", String
"LinkageError", String
"Long", String
"Math", String
"NegativeArraySizeException",
      String
"NoClassDefFoundError", String
"NoSuchFieldError", String
"NoSuchFieldException", String
"NoSuchMethodError", String
"NoSuchMethodException",
      String
"NullPointerException", String
"Number", String
"NumberFormatException", String
"Object", String
"OutOfMemoryError", String
"Override", String
"Package",
      String
"Process", String
"ProcessBuilder", String
"Readable", String
"ReflectiveOperationException", String
"Runnable", String
"Runtime",
      String
"RuntimeException", String
"RuntimePermission", String
"SafeVarargs", String
"SecurityException", String
"SecurityManager", String
"Short",
      String
"StackOverflowError", String
"StackTraceElement", String
"StrictMath", String
"String", String
"StringBuffer", String
"StringBuilder",
      String
"StringIndexOutOfBoundsException", String
"SuppressWarnings", String
"System", String
"Thread", String
"ThreadDeath",
      String
"ThreadGroup", String
"ThreadLocal", String
"Throwable", String
"TypeNotPresentException",
      String
"UnknownError", String
"UnsatisfiedLinkError", String
"UnsupportedClassVersionError",
      String
"UnsupportedOperationException", String
"VerifyError", String
"VirtualMachineError", String
"Void"]
    -- Keywords and literals are taken from Oracle's Java Tutorials on 2022-05-27; said to be complete for Java 1.8 only
    -- See: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html
    keywords :: [String]
keywords = [
      String
"abstract", String
"assert", String
"boolean", String
"break", String
"byte", String
"case", String
"catch", String
"char", String
"class", String
"const", String
"continue",
      String
"default", String
"do", String
"double", String
"else", String
"enum", String
"extends", String
"final", String
"finally", String
"float", String
"for", String
"goto", String
"if",
      String
"implements", String
"import", String
"instanceof", String
"int", String
"interface", String
"long", String
"native", String
"new", String
"package", String
"private",
      String
"protected", String
"public", String
"return", String
"short", String
"static", String
"strictfp", String
"super", String
"switch", String
"synchronized", String
"this",
      String
"throw", String
"throws", String
"transient", String
"try", String
"void", String
"volatile", String
"while"]
    literals :: [String]
literals = [String
"false", String
"null", String
"true"]