diff --git a/doc/OldStuff/ClassDiagram.ucd b/doc/OldStuff/ClassDiagram.ucd index 65091fd1b..041556e28 100755 --- a/doc/OldStuff/ClassDiagram.ucd +++ b/doc/OldStuff/ClassDiagram.ucd @@ -1,2110 +1,2110 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/OldStuff/JavaDoc/package-list b/doc/OldStuff/JavaDoc/package-list index d3f5a12fa..8b1378917 100755 --- a/doc/OldStuff/JavaDoc/package-list +++ b/doc/OldStuff/JavaDoc/package-list @@ -1 +1 @@ - + diff --git a/doc/OldStuff/JavaDoc/stylesheet.css b/doc/OldStuff/JavaDoc/stylesheet.css index 7ac5ff16b..b62ecb51b 100755 --- a/doc/OldStuff/JavaDoc/stylesheet.css +++ b/doc/OldStuff/JavaDoc/stylesheet.css @@ -1,29 +1,29 @@ -/* Javadoc style sheet */ - -/* Define colors, fonts and other style attributes here to override the defaults */ - -/* Page background color */ -body { background-color: #FFFFFF } - -/* Table colors */ -.TableHeadingColor { background: #CCCCFF } /* Dark mauve */ -.TableSubHeadingColor { background: #EEEEFF } /* Light mauve */ -.TableRowColor { background: #FFFFFF } /* White */ - -/* Font used in left-hand frame lists */ -.FrameTitleFont { font-size: 10pts; font-family: Helvetica, Arial, san-serif } -.FrameHeadingFont { font-size: 10pts; font-family: Helvetica, Arial, san-serif } -.FrameItemFont { font-size: 10pts; font-family: Helvetica, Arial, san-serif } - -/* Example of smaller, sans-serif font in frames */ -/* .FrameItemFont { font-size: 10pt; font-family: Helvetica, Arial, sans-serif } */ - -/* Navigation bar fonts and colors */ -.NavBarCell1 { background-color:#EEEEFF;}/* Light mauve */ -.NavBarCell1Rev { background-color:#00008B;}/* Dark Blue */ -.NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;} -.NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;} - -.NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} -.NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} - +/* Javadoc style sheet */ + +/* Define colors, fonts and other style attributes here to override the defaults */ + +/* Page background color */ +body { background-color: #FFFFFF } + +/* Table colors */ +.TableHeadingColor { background: #CCCCFF } /* Dark mauve */ +.TableSubHeadingColor { background: #EEEEFF } /* Light mauve */ +.TableRowColor { background: #FFFFFF } /* White */ + +/* Font used in left-hand frame lists */ +.FrameTitleFont { font-size: 10pts; font-family: Helvetica, Arial, san-serif } +.FrameHeadingFont { font-size: 10pts; font-family: Helvetica, Arial, san-serif } +.FrameItemFont { font-size: 10pts; font-family: Helvetica, Arial, san-serif } + +/* Example of smaller, sans-serif font in frames */ +/* .FrameItemFont { font-size: 10pt; font-family: Helvetica, Arial, sans-serif } */ + +/* Navigation bar fonts and colors */ +.NavBarCell1 { background-color:#EEEEFF;}/* Light mauve */ +.NavBarCell1Rev { background-color:#00008B;}/* Dark Blue */ +.NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;} +.NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;} + +.NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} +.NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} + diff --git a/doc/OldStuff/Operator.ucd b/doc/OldStuff/Operator.ucd index f6f2c6984..9799f2e57 100755 --- a/doc/OldStuff/Operator.ucd +++ b/doc/OldStuff/Operator.ucd @@ -1,220 +1,220 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/OldStuff/Rest.ucd b/doc/OldStuff/Rest.ucd index aba1b1496..48a6ade4d 100755 --- a/doc/OldStuff/Rest.ucd +++ b/doc/OldStuff/Rest.ucd @@ -1,696 +1,696 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/OldStuff/Rest/ClassDiagram.svg b/doc/OldStuff/Rest/ClassDiagram.svg index 143b2ea2a..4c300b8e6 100755 --- a/doc/OldStuff/Rest/ClassDiagram.svg +++ b/doc/OldStuff/Rest/ClassDiagram.svg @@ -1,6746 +1,6746 @@ - - - - - - - - - - - - - - - - - - - if_codegen(in ClassFile, in CodeAttribute, in boolean): void - - - codegen(in ClassFile, in CodeAttribute, in boolean): void - - UnaryNot - - - - - - - - - - hamaDebug: boolean - - - super_class: short - - - class_name: String - - - attributes: Menge - - - class_block: Menge - - - interfaces: Menge - - - this_class: short - - - methods: Menge - - - key_Menge: Menge - - - constructor_founded: boolean - - - constant_pool: Menge - - - super_class_name: String - - - access_flags: short - - - system_out2: boolean - - - fields: Menge - - - system_out: boolean - - - magic: int - - - minor_version: short - - - major_version: short - - - add_field_ref(in String, in String, in String): int - - - set_access_flags(in short): void - - - get_key_Menge(): Menge - - - get_constructor_founded(): boolean - - - writeInt(in FileOutputStream, in int): void - - - get_this_class(): short - - - codegen(): void - - - get_access_flags(): short - - - add_classblock_Element(in Assign): void - - - set_methods(in Menge): void - - - get_system_out(): boolean - - - set_system_out(in boolean): void - - - set_attributes(in Menge): void - - - set_constructor_founded(in boolean): void - - - add_CONSTANT_Class_info(in String): int - - - add_class(in String, in String, in short): void - - - get_constant_pool(): Menge - - - get_constant_pool_element(in byte, in String): short - - - add_CONSTANT_Utf8_info(in String): int - - - get_attributes(): Menge - - - writeShort(in FileOutputStream, in short): void - - - set_this_class(in short): void - - - writeByte(in FileOutputStream, in byte): void - - - add_CONSTANT_NameAndType_info(in String, in String): int - - - add_method_ref(in String, in String, in String): int - - - add_CONSTANT_String_info(in String): int - - - set_super_class(in short): void - - - get_class_block(): Menge - - - get_super_class(): short - - - set_fields(in Menge): void - - - add_field(in String, in String, in short): void - - - get_fields(): Menge - - - set_constant_pool(in Menge): void - - - get_methods(): Menge - - - writeByteArray(in FileOutputStream, in byte[]): void - - - ClassFile(in boolean): void - - - add_method(in String, in String, in ParameterList, in Type, in Block, in short, in Menge): void - - - add_CONSTANT_Integer_info(in int): int - - ClassFile - - - - - - - - - - modifier: Menge - - - calculate_access_flags(): short - - - get_modifiers(): Menge - - Modifiers - - - - - - - - - - KlassenVektor: Menge - - - isTVinRefType(in TyploseVariable, in RefType): boolean - - - isRXSimilarRY(in RefType, in RefType): boolean - - - isInFC(in RefType, in RefType, in Menge): Pair - - - Subst(in Pair, in int, in TyploseVariable, in RefType, in boolean): void - - - hasSolvedForm(in Menge): boolean - - - adapt(in String, in Type, in Menge, in Menge): Pair - - - unify(in Menge, in Menge): Menge - - - pi(in int, in String, in String): int - - - makeFC(): Menge - - - set_Class(in Class): void - - - sc_check(in boolean): void - - - codegen(in boolean): void - - - isRealSubClass(in String, in String): boolean - - - printMenge(in String, in Menge, in int): void - - SourceFile - - - - - - - - - - scerrors: Menge - - - add_classexceptions(in SCClassException): void - - - fehlerausgabe(): void - - SCException - - - - - - - - - - exlist: Menge - - - fehlerausgabe(): void - - - addException(in Menge): void - - - addClassname(in String): void - - SCClassException - - - - - - - - - - start_pc: short - - - catch_type: short - - - end_pc: short - - - handler_pc: short - - - codegen(in ClassFile, in FileOutputStream): void - - ExceptionTable - - - - - - - - - attribute_name_index: short - - - attribute_length: int - - - constantvalue_index: short - - ConstantValueAttribute - - - - - - - - - - a: String - - - tag: byte - - - set_tag(in byte): void - - - get_a(): String - - - get_tag(): byte - - - codegen(in ClassFile, in FileOutputStream): void - - - set_a(in String): void - - - equals(in Object): boolean - - - Key(in byte, in String): void - - Key - - - - - - - - - - name_index: short - - - attributes: Menge - - - access_flags: short - - - descriptor_index: short - - - get_attributes(): Menge - - - set_name_index(in short): void - - - codegen(in ClassFile, in FileOutputStream): void - - - set_access_flags(in short): void - - - set_attributes(in Menge): void - - - get_descriptor_index(): short - - - set_descriptor_index(in short): void - - - get_access_flags(): short - - - get_name_index(): short - - MethodInfo - - - - - - - - - - formalparameter: Menge - - - hamaDebug: boolean - - - sc_get_Formalparalist(): Menge - - - codegen(in ClassFile, in CodeAttribute): void - - - get_codegen_ParameterList(in Menge): String - - - set_AddParameter(in FormalParameter): void - - ParameterList - - - - - - - - - - declid: DeclId - - - type: Type - - - set_Type(in Type): void - - - set_DeclId(in DeclId): void - - - get_Type(): Type - - - get_St_Type(): String - - - get_Name(): String - - - codegen(in ClassFile, in CodeAttribute): void - - FormalParameter - - - - - - - - - - kill: Hashtable - - - fielddecl: Menge - - - hash: Hashtable - - - paraclasshash: Hashtable - - - is_declared(in Type, in Menge): boolean - - - get_FieldDeclMenge(): Menge - - - sc_check(in Menge, in boolean): void - - - complete_parahashtable(in Menge, in UsedId, in Hashtable, in boolean): Hashtable - - - get_hash(): Hashtable - - - sc_init_hashtable(in Menge, in String, in String, in boolean): void - - - codegen(in ClassFile, in Menge): void - - - sc_init_hashtable_for_extended_classes(in Menge, in String, in Hashtable, in Menge, in Hashtable, in Hashtable, in boolean): void - - - init_parahashtable(in Menge, in boolean): Hashtable - - - istParameterOK(in Menge, in Menge): void - - - set_FieldDecl(in FieldDecl): void - - - print_rec(in Hashtable): void - - - print_rec(in Menge): void - - - print_rec(in String, in Menge): void - - - print_rec(in String, in Hashtable): void - - ClassBody - - - - - - - - - - bEqual: boolean - - - bSubst: boolean - - - TA1: Type - - - TA2: Type - - - getTA2Copy(): Type - - - copyType(in Type): Type - - - Pair(in Type, in Type): void - - - isInMenge(in Menge): boolean - - - getTA1Copy(): Type - - - Pair(in Type, in Type, in boolean): void - - - isEqual(): boolean - - - toString(): String - - Pair - - - - - - - TypeSpec - - - - - - - - - - exlist: Menge - - - addException(in SCExcept): void - - - get_exlist(): Menge - - SCClassBodyException - - - - - - - - - - reftype: Menge - - - set_addElem(in RefType): void - - ExceptionList - - - - - - - - - - paratyp: Menge - - - hamaDebug: boolean - - - modifiers: Modifiers - - - name: String - - - wert: ExprStmt - - - DeclId(in String): void - - - set_Paratyp(in Menge): void - - - get_Modifiers(): Modifiers - - - set_ListType(in Type): void - - - get_access_flags(): short - - - get_Paratyp(): Menge - - - codegen_InstVarDecl(in ClassFile, in Type, in Menge): void - - - set_Wert(in ExprStmt): void - - - get_Wert(): ExprStmt - - - codegen_LocalVarDecl(in ClassFile, in CodeAttribute, in Type, in Menge): void - - - DeclId(): void - - - set_Modifiers(in Modifiers): void - - - set_Name(in String): void - - - get_Name(): String - - DeclId - - - - - - - - - - classname: String - - - modifiers: Modifiers - - - get_classname(): String - - - set_Modifiers(in Modifiers): void - - - set_classname(in String): void - - - get_access_flags(): short - - - get_Modifiers(): Modifiers - - ClassDeclId - - - - - - - - - - name: Menge - - - vParaOrg: Menge - - - typen: Menge - - - paralist: Menge - - - get_ParaList(): Menge - - - set_Name(in String): void - - - get_codegen_UsedId(): String - - - get_Typen(): Menge - - - get_Name_1Element(): String - - - set_Typen(in Menge): void - - - get_Name(): Menge - - - set_ParaList(in Menge): void - - UsedId - - - - - - - - - - exlist: Menge - - - get_exlist(): Menge - - - addException(in SCExcept): void - - SCStatementException - - - - - - - - - - type: String - - - class_name: String - - - descriptor_index: short - - - access_flags: short - - - name_index: short - - - attributes: Menge - - - name: String - - - set_name_index(in short): void - - - get_access_flags(): short - - - set_Name(in String): void - - - get_Name(): String - - - set_Type(in String): void - - - set_attributes(in Menge): void - - - get_name_index(): short - - - get_Class_Name(): String - - - set_descriptor_index(in short): void - - - set_access_flags(in short): void - - - get_Type(): String - - - codegen(in ClassFile, in FileOutputStream): void - - - get_descriptor_index(): short - - - set_Class_Name(in String): void - - - get_attributes(): Menge - - FieldInfo - - - - - - - - - - superclassid: UsedId - - - vParaOrg: Menge - - - parahash: Hashtable - - - cdid: ClassDeclId - - - paralist: Menge - - - body: ClassBody - - - java: Class - - - status: Status - - - class_block: Block - - - get_ParaList(): Menge - - - set_Status(in Status): void - - - get_class_block(): Block - - - set_UsedId(in UsedId): void - - - complete_paralist(in boolean): Menge - - - codegen(in boolean): void - - - get_classname(): String - - - get_ClassBody(): ClassBody - - - get_ParaHash(): Hashtable - - - set_ParaList(in Menge): void - - - does_Class_extend(): boolean - - - set_ClassBody(in ClassBody): void - - - sc_check_for_extended_classes(in Menge, in Hashtable, in boolean): void - - - get_Superclass_Name(): String - - - para_check(in Menge, in boolean): void - - - set_ParaHash(in Hashtable): void - - - sc_check(in Menge, in boolean): void - - - set_class_block(in Block): void - - - is_member(in String): String - - - set_ClassDeclId(in ClassDeclId): void - - - print_rec(in String, in Menge): void - - - print_rec(in String, in Hashtable): void - - - print_rec(in Hashtable): void - - - print_rec(in Menge): void - - Class - - - - - - - - - - expr: Menge - - - get_codegen_ArgumentList(in Menge): String - - - get_firstElement(): Object - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - ArgumentList - - - - - - - - - - exlist: Menge - - - get_exlist(): Menge - - - set_exlist(in Menge): void - - SCMethodException - - - - - - - - - - ndiv(in String): Byte - - - nstore(in String): Byte - - - bytes_to_int(in Byte): int - - - get_nType(in String): int - - - nstore_n(in String, in int): Byte - - - nsub(in String): Byte - - - nrem(in String): Byte - - - nor(in String): Byte - - - nconst_n(in String, in int): Byte - - - ncmpg(in String): Byte - - - nneg(in String): Byte - - - if_ncmpeq(in String): Byte - - - nand(in String): Byte - - - nadd(in String): Byte - - - get_codegen_Type(in String, in Menge): String - - - bytes_to_int(in Byte, in Byte): int - - - nreturn(in String): Byte - - - nload_n(in String, in int): Byte - - - ncmpl(in String): Byte - - - bytes_to_int(in Byte, in Byte, in Byte, in Byte): int - - - nmul(in String): Byte - - - if_ncmpne(in String): Byte - - - nload(in String): Byte - - - nastore(in String): Byte - - - nshl(in String): Byte - - - naload(in String): Byte - - - nushr(in String): Byte - - - get_Command(in Menge): void - - - nshr(in String): Byte - - - nxor(in String): Byte - - - n2n(in String, in String): Byte - - JVMCode - - - - - - - - - - paralist: Menge - - - ParaList(in Type): void - - - ParaList(): void - - - get_firstElement(): Object - - - get_ParaList(): Menge - - - add_ParaList(in Object): void - - ParaList - - - - - - - UnaryPlus - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in String, in boolean): void - - UnaryMinus - - - - - - - - - - token: Object - - - lexem: String - - - Token(in int): void - - - Token(in int, in String): void - - - Token(in int, in char): void - - - String2Int(): int - - - get_String(): String - - - getLexem(): String - - - CharInString(): char - - - String2Bool(): boolean - - Token - - - - - - - - - - classname: String - - - function: String - - - statement: String - - - error: String - - - get_classname(): String - - - set_classname(in String): void - - - set_function(in String): void - - - get_statement(): String - - - set_error(in String): void - - - set_statement(in String): void - - - get_function(): String - - - fehlerausgabe(): void - - SCExcept - - - - - - - - - - message: String - - - get_Message(): String - - - JVMCodeException(in String): void - - JVMCodeException - - - - - - - - - - bytes[0..*]: byte - - - codegen(in ClassFile, in FileOutputStream): void - - - get_bytes(): byte[] - - - set_bytes(in byte[]): void - - CONSTANT_Utf8_info - - - - - - - - - - name_and_type_index: short - - - class_index: short - - - set_name_and_type_index(in short): void - - - set_class_index(in short): void - - - get_class_index(): short - - - codegen(in ClassFile, in FileOutputStream): void - - - get_name_and_type_index(): short - - CONSTANT_Fieldref_info - - - - - - - - - - bytes: int - - - get_bytes(): int - - - set_bytes(in int): void - - - codegen(in ClassFile, in FileOutputStream): void - - CONSTANT_Float_info - - - - - - - - - - bytes: int - - - set_bytes(in int): void - - - codegen(in ClassFile, in FileOutputStream): void - - - get_bytes(): int - - CONSTANT_Integer_info - - - - - - - - - - string_index: short - - - set_string_index(in short): void - - - get_string_index(): short - - - codegen(in ClassFile, in FileOutputStream): void - - CONSTANT_String_info - - - - - - - - - - name_and_type_index: short - - - class_index: short - - - set_class_index(in short): void - - - codegen(in ClassFile, in FileOutputStream): void - - - get_name_and_type_index(): short - - - get_class_index(): short - - - set_name_and_type_index(in short): void - - CONSTANT_Methodref_info - - - - - - - - - - tag: byte - - - get_tag(): byte - - - set_tag(in byte): void - - - codegen(in ClassFile, in FileOutputStream): void - - CPInfo - - - - - - - - - - name_index: short - - - set_name_index(in short): void - - - codegen(in ClassFile, in FileOutputStream): void - - - get_name_index(): short - - CONSTANT_Class_info - - - - - - - - - - descriptor_index: short - - - name_index: short - - - get_name_index(): short - - - set_name_index(in short): void - - - get_descriptor_index(): short - - - codegen(in ClassFile, in FileOutputStream): void - - - set_descriptor_index(in short): void - - CONSTANT_NameAndType_info - - - - - - - - - - name_and_type_index: short - - - class_index: short - - - codegen(in ClassFile, in FileOutputStream): void - - - get_name_and_type_index(): short - - - set_name_and_type_index(in short): void - - - set_class_index(in short): void - - - get_class_index(): short - - CONSTANT_InterfaceMethodref_info - - - - - - - - - - low_bytes: int - - - high_bytes: int - - - set_high_bytes(in int): void - - - get_high_bytes(): int - - - set_low_bytes(in int): void - - - get_low_bytes(): int - - - codegen(in ClassFile, in FileOutputStream): void - - CONSTANT_Double_info - - - - - - - - - - low_bytes: int - - - high_bytes: int - - - codegen(in ClassFile, in FileOutputStream): void - - - set_low_bytes(in int): void - - - set_high_bytes(in int): void - - - get_low_bytes(): int - - - get_high_bytes(): int - - CONSTANT_Long_info - - - - - - - - - - advance(): boolean - - - Scanner(in Reader): void - - - value(): Object - - - token(): int - - Scanner - - - - - - - - - - yylex(): boolean - - - JavaLexer(in InputStream): void - - - JavaLexer(in Reader): void - - - yybegin(in int): void - - - yy_to_mark(): void - - - yy_advance(): int - - - yy_mark_start(): void - - - unpackFromString(in int, in int, in String): int[][] - - - yy_move_end(): void - - - JavaLexer(): void - - - yylength(): int - - - yy_mark_end(): void - - - yytext(): String - - - yy_double(in char[]): char[] - - - yy_error(in int, in boolean): void - - JavaLexer - - - - - - - - - - nDebug2: int - - - nDebug: int - - - wandleTV2RefType(in Menge, in Menge): void - - - Debug(in String, in int): void - - - main(in String[]): void - - MyCompiler - - - - - - - - - - main(in String[]): void - - JavaCompiler - - - - - - - - - - - yyerror(in String, in String[]): void - - - yyerror(in String): void - - - yyparse(in yyInput, in Object): Object - - - yyparse(in yyInput): Object - - - yyExpecting(in int): String[] - - - yyDefault(in Object): Object - - - - - - - - - - value(): Object - - - token(): int - - - advance(): boolean - «interface» - - yyInput - - - - - - - - - - yyException(in String): void - - yyException - - JavaParser - - - - - - - UserDef - - - - - - - Import - - - - - - - - - - userdef: UserDef - - - imp: Import - - - set_UserDef(in UserDef): void - - - set_Import(in Import): void - - Status - - - - - - - CharacterType - - - - - - - ReturnType - - - - - - - - - - parameter: Menge - - - set_ParaList(in Menge): void - - - isTV(in int): boolean - - - get_Type(): String - - - add_Parameter(in Object): void - - - RefType(in String, in Menge): void - - - getParaN(in int): String - - - RefType(): void - - - get_ParaList(): Menge - - - getTypeName(): String - - - RefType(in RefType): void - - - RefType(in String): void - - RefType - - - - - - - - - - strNextName: String - - - TyploseVariable(in String): void - - - makeNewName(): String - - - manipulate(in int, in char): void - - - inc(in int): void - - TyploseVariable - - - - - - - IntegerType - - - - - - - - - - used: UsedId - - - type: String - - - hamaDebug: boolean - - - get_Name(): String - - - Type(): void - - - Type(in String): void - - - get_UsedId(): UsedId - - - set_UsedId(in UsedId): void - - - get_codegen_Type(in Menge): String - - - get_Type(): String - - - set_Type(in String): void - - Type - - - - - - - BooleanType - - - - - - - - - - name: String - - - get_Name(): String - - - set_Name(in String): void - - Void - - - - - - - BaseType - - - - - - - Abstract - - - - - - - Public - - - - - - - Modifier - - - - - - - Private - - - - - - - Protected - - - - - - - Static - - - - - - - NoReceiver - - - - - - - - - - noreceiver: NoReceiver - - - expr: Expr - - - set_Expr(in Expr): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - get_Type(): String - - Receiver - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - EmptyStmt - - - - - - - - - - expr: Expr - - - get_Name(): String - - - set_Expr(in Expr): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - PostDecExpr - - - - - - - - - - Bool: boolean - - - BoolLiteral(): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - get_Name(): String - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - set_Bool(in boolean): void - - BoolLiteral - - - - - - - - - - expr: Expr - - - set_Expr(in Expr): void - - - get_Name(): String - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - PreDecExpr - - - - - - - - - - op: Operator - - - expr1: Expr - - - expr2: Expr - - - set_Expr1(in Expr): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - get_Expr2(): Expr - - - neg_codegen(in ClassFile, in CodeAttribute, in Menge): void - - - get_Operator(): Operator - - - set_Expr2(in Expr): void - - - get_Name(): String - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - type_check(in CodeAttribute): boolean - - - not_codegen(in ClassFile, in CodeAttribute, in Menge): void - - - set_Operator(in Operator): void - - - get_Expr1(): Expr - - Binary - - - - - - - - - - LocalOrFieldVar(in String): void - - - set_UsedId(in UsedId): void - - - get_Name(): String - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - LocalOrFieldVar(): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - LocalOrFieldVar - - - - - - - - - - class_name: String - - - arglist: ArgumentList - - - exprtypes: Menge - - - finde_method: Menge - - - uebernachdurch: Hashtable - - - called_method: Method - - - receiver: Receiver - - - counter: int - - - add_Expr(in Expr): void - - - set_UsedId(in UsedId): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - set_Receiver(in Receiver): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - sc_init_extended_fcts(in Menge, in Menge, in String, in String, in boolean): void - - - get_Name(): String - - - sc_check_method_kleiner(in Menge, in String, in String, in boolean): boolean - - - set_ArgumentList(in ArgumentList): void - - - set_Expr_Menge(in Menge): void - - - sc_check_uebergabe(in Menge, in Menge, in boolean, in int, in Hashtable, in Hashtable): void - - - sc_check_get_Method(in Menge, in String, in boolean, in Hashtable, in Hashtable): void - - MethodCall - - - - - - - - - - statements: Menge - - - HashTabelleBlock: Hashtable - - - sc_meth_ret_type: String - - - HashTabelleKlasse: Hashtable - - - block_para: Hashtable - - - set_Statement_Menge(in Menge): void - - - set_Statement(in Statement): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - get_Statement(): Menge - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - Block - - - - - - - - - - expr: Expr - - - plus: UnaryPlus - - - get_Name(): String - - - set_Expr(in Expr): void - - - set_UnaryPlus(in UnaryPlus): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - PositivExpr - - - - - - - - - - type: Type - - - expr: Expr - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - get_Name(): String - - - set_Expr(in Expr): void - - - set_Type(in Type): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - CastExpr - - - - - - - - - - declid: Menge - - - paralist: Menge - - - parahash: Hashtable - - - type: Type - - - set_Type(in Type): void - - - is_declared(in Type, in Menge): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - set_DeclId(in DeclId): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - check_anz(in Type, in Menge, in Menge): void - - - get_Name(): String - - - set_ParaList(in Menge): void - - LocalVarDecl - - - - - - - - - - expr1: Expr - - - expr2: Expr - - - get_Name(): String - - - set_Expr(in Expr, in Expr): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - Assign - - - - - - - - - - usedid: UsedId - - - get_Name_Menge(): Menge - - - get_UsedId(): UsedId - - - set_Type(in Type): void - - - get_Type_Menge(): Menge - - - set_UsedId(in UsedId): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - get_Name(): String - - Expr - - - - - - - - - - Int: int - - - set_Int(in int): void - - - IntLiteral(): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - get_Name(): String - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - IntLiteral - - - - - - - - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - print_rec(in String, in Hashtable): void - - - print_rec(in String, in Menge): void - - - print_rec(in Hashtable): void - - - print_rec(in Menge): void - - Statement - - - - - - - - - - expr: Expr - - - not: UnaryNot - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - set_Expr(in Expr): void - - - get_Name(): String - - - get_Expr(): Expr - - - not_codegen(in ClassFile, in CodeAttribute, in Menge): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - set_UnaryNot(in UnaryNot): void - - NotExpr - - - - - - - - - - expr: Expr - - - else_block: Statement - - - then_block: Statement - - - hamaDebug: boolean - - - set_Then_block(in Statement): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - set_Else_block(in Statement): void - - - set_Expr(in Expr): void - - - if_codegen(in ClassFile, in CodeAttribute, in boolean, in Menge): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - IfStmt - - - - - - - - - - arglist: ArgumentList - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - get_Name(): String - - - set_UsedId(in UsedId): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - set_ArgumentList(in ArgumentList): void - - NewClass - - - - - - - - - - expr: Expr - - - type: String - - - usedid: UsedId - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - InstVar(in String, in String): void - - - get_Name(): String - - - get_codegen_UsedId(): String - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - InstVar - - - - - - - - - - type: Type - - - get_Type(): String - - ExprStmt - - - - - - - - - - Null(): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - get_Name(): String - - Null - - - - - - - - - - expr: Expr - - - reftype: RefType - - - is_instance: boolean - - - InstanceOf(): void - - - get_Name(): String - - - set_Type(in RefType): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - set_Expr(in Expr): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - InstanceOf - - - - - - - - - - Char: char - - - CharLiteral(): void - - - get_Name(): String - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - set_Char(in char): void - - CharLiteral - - - - - - - - - - expr: Expr - - - loop_block: Statement - - - set_Expr(in Expr): void - - - set_Loop_block(in Statement): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - loop_codegen(in ClassFile, in CodeAttribute, in int, in boolean, in Menge): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - WhileStmt - - - - - - - - - - string: String - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - StringLiteral(): void - - - get_Name(): String - - - set_String(in String): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - StringLiteral - - - - - - - Literal - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - UnaryExpr - - - - - - - - - - arglist: ArgumentList - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - set_UsedId(in UsedId): void - - - set_ArgumentList(in ArgumentList): void - - - get_Name(): String - - This - - - - - - - - - - retexpr: Expr - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - set_ReturnExpr(in Expr): void - - - get_Type(): String - - Return - - - - - - - - - - expr: Expr - - - get_Name(): String - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - set_Expr(in Expr): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - PostIncExpr - - - - - - - - - - expr: Expr - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - get_Name(): String - - - set_Expr(in Expr): void - - PreIncExpr - - - - - - - - - - expr: Expr - - - neg: UnaryMinus - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - set_Expr(in Expr): void - - - set_UnaryMinus(in UnaryMinus): void - - - get_Name(): String - - - neg_codegen(in ClassFile, in CodeAttribute, in Menge): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - NegativeExpr - - - - - - - - - - expr: Menge - - - type: Type - - - get_Name(): String - - - get_codegen_Array_Type(): int - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - NewArray - - - - - - - BinaryExpr - - - - - - - AndOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - - if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void - - LessOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - MinusOp - - - - - - - OrOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - - if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void - - LessEquOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - PlusOp - - - - - - - - - - if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - EqualOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - - if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void - - NotEqualOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - - if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void - - GreaterEquOp - - - - - - - - - - if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - GreaterOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - TimesOp - - - - - - - MulOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - Operator - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - DivideOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - - if_codegen(in ClassFile, in CodeAttribute, in boolean, in Expr, in Statement, in Statement, in Menge): void - - - loop_codegen(in ClassFile, in CodeAttribute, in Expr, in int, in boolean, in Menge): void - - - replace_index(in CodeAttribute, in Menge, in int, in int): void - - - build(in ClassFile, in CodeAttribute, in Expr, in Menge, in boolean, in boolean, in boolean, in Menge): void - - LogOp - - - - - - - - - - if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void - - RelOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - AddOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - ModuloOp - - - - - - - - - - info[0..*]: byte - - - set_info(in byte[]): void - - - get_attributes_length(): int - - - set_info(in Menge): void - - - codegen(in ClassFile, in FileOutputStream): void - - - get_info(): byte[] - - - get_info_Menge(): Menge - - AttributeInfo - - - - - - - - - - local_name_Menge: Menge - - - code_Menge: Menge - - - attributes: Menge - - - exception_tables: Menge - - - local_type_Menge: Menge - - - CodeAttribute(in String, in short): void - - - add_code_int(in int): void - - - get_attributes_Menge(): Menge - - - add_code_short(in int): void - - - add_code_byte_array(in byte[]): void - - - get_indexOf_Var(in String): int - - - add_local(in String, in Type): void - - - add_code(in Byte): void - - - get_code_Menge(): Menge - - - get_TypeOf_Var(in String): Type - - - set_exception_table_Menge(in Menge): void - - - set_code_short(in int, in int): void - - - get_attributes_length(): int - - - codegen(in ClassFile, in FileOutputStream): void - - - add_code_byte(in int): void - - - set_code(in Byte, in int): void - - - get_local_Menge(): Menge - - - get_code_length(): int - - - get_exception_table_Menge(): Menge - - - set_attributes_Menge(in Menge): void - - - calculate_max_stack(): short - - CodeAttribute - - - - - - - - - - attribute_name_index: short - - - get_attribute_name_index(): short - - - set_attribute_name_index(in short): void - - - get_attributes_length(): int - - - codegen(in ClassFile, in FileOutputStream): void - - Attribute - - - - - - - - - - get_codegen_Param_Type(in Menge): String - - - Constructor(): void - - - codegen(in ClassFile, in Menge): void - - Constructor - - - - - - - - - - type: Type - - - get_Type(): String - - - set_Type(in Type): void - - - codegen(in ClassFile, in Menge): void - - InstVarDecl - - - - - - - - - - parameterlist: ParameterList - - - exceptionlist: ExceptionList - - - block: Block - - - returntype: Type - - - types_in_parameterlist: Menge - - - get_Method_Name(): String - - - get_ParaList(): ParameterList - - - set_ExceptionList(in ExceptionList): void - - - set_Modifiers(in Modifiers): void - - - get_Block(): Block - - - set_Block(in Block): void - - - get_Type_Paralist(): Menge - - - set_ReturnType(in Type): void - - - set_ParaList(in ParameterList): void - - - get_ReturnType(): Type - - - call_sc_check(in Menge, in Hashtable, in boolean, in Hashtable): void - - - get_codegen_Param_Type(in Menge): String - - - get_Type(): String - - - sc_init_parameterlist(in boolean): void - - - codegen(in ClassFile, in Menge): void - - - get_ExceptionList(): ExceptionList - - Method - - - - - - - - - - declid: Menge - - - get_Type(): String - - - codegen(in ClassFile, in Menge): void - - - getDeclIdMenge(): Menge - - - get_Name(): Menge - - - set_DeclId(in DeclId): void - - - setDeclIdMenge(in Menge): void - - FieldDecl - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + if_codegen(in ClassFile, in CodeAttribute, in boolean): void + + + codegen(in ClassFile, in CodeAttribute, in boolean): void + + UnaryNot + + + + + + + + + + hamaDebug: boolean + + + super_class: short + + + class_name: String + + + attributes: Menge + + + class_block: Menge + + + interfaces: Menge + + + this_class: short + + + methods: Menge + + + key_Menge: Menge + + + constructor_founded: boolean + + + constant_pool: Menge + + + super_class_name: String + + + access_flags: short + + + system_out2: boolean + + + fields: Menge + + + system_out: boolean + + + magic: int + + + minor_version: short + + + major_version: short + + + add_field_ref(in String, in String, in String): int + + + set_access_flags(in short): void + + + get_key_Menge(): Menge + + + get_constructor_founded(): boolean + + + writeInt(in FileOutputStream, in int): void + + + get_this_class(): short + + + codegen(): void + + + get_access_flags(): short + + + add_classblock_Element(in Assign): void + + + set_methods(in Menge): void + + + get_system_out(): boolean + + + set_system_out(in boolean): void + + + set_attributes(in Menge): void + + + set_constructor_founded(in boolean): void + + + add_CONSTANT_Class_info(in String): int + + + add_class(in String, in String, in short): void + + + get_constant_pool(): Menge + + + get_constant_pool_element(in byte, in String): short + + + add_CONSTANT_Utf8_info(in String): int + + + get_attributes(): Menge + + + writeShort(in FileOutputStream, in short): void + + + set_this_class(in short): void + + + writeByte(in FileOutputStream, in byte): void + + + add_CONSTANT_NameAndType_info(in String, in String): int + + + add_method_ref(in String, in String, in String): int + + + add_CONSTANT_String_info(in String): int + + + set_super_class(in short): void + + + get_class_block(): Menge + + + get_super_class(): short + + + set_fields(in Menge): void + + + add_field(in String, in String, in short): void + + + get_fields(): Menge + + + set_constant_pool(in Menge): void + + + get_methods(): Menge + + + writeByteArray(in FileOutputStream, in byte[]): void + + + ClassFile(in boolean): void + + + add_method(in String, in String, in ParameterList, in Type, in Block, in short, in Menge): void + + + add_CONSTANT_Integer_info(in int): int + + ClassFile + + + + + + + + + + modifier: Menge + + + calculate_access_flags(): short + + + get_modifiers(): Menge + + Modifiers + + + + + + + + + + KlassenVektor: Menge + + + isTVinRefType(in TyploseVariable, in RefType): boolean + + + isRXSimilarRY(in RefType, in RefType): boolean + + + isInFC(in RefType, in RefType, in Menge): Pair + + + Subst(in Pair, in int, in TyploseVariable, in RefType, in boolean): void + + + hasSolvedForm(in Menge): boolean + + + adapt(in String, in Type, in Menge, in Menge): Pair + + + unify(in Menge, in Menge): Menge + + + pi(in int, in String, in String): int + + + makeFC(): Menge + + + set_Class(in Class): void + + + sc_check(in boolean): void + + + codegen(in boolean): void + + + isRealSubClass(in String, in String): boolean + + + printMenge(in String, in Menge, in int): void + + SourceFile + + + + + + + + + + scerrors: Menge + + + add_classexceptions(in SCClassException): void + + + fehlerausgabe(): void + + SCException + + + + + + + + + + exlist: Menge + + + fehlerausgabe(): void + + + addException(in Menge): void + + + addClassname(in String): void + + SCClassException + + + + + + + + + + start_pc: short + + + catch_type: short + + + end_pc: short + + + handler_pc: short + + + codegen(in ClassFile, in FileOutputStream): void + + ExceptionTable + + + + + + + + + attribute_name_index: short + + + attribute_length: int + + + constantvalue_index: short + + ConstantValueAttribute + + + + + + + + + + a: String + + + tag: byte + + + set_tag(in byte): void + + + get_a(): String + + + get_tag(): byte + + + codegen(in ClassFile, in FileOutputStream): void + + + set_a(in String): void + + + equals(in Object): boolean + + + Key(in byte, in String): void + + Key + + + + + + + + + + name_index: short + + + attributes: Menge + + + access_flags: short + + + descriptor_index: short + + + get_attributes(): Menge + + + set_name_index(in short): void + + + codegen(in ClassFile, in FileOutputStream): void + + + set_access_flags(in short): void + + + set_attributes(in Menge): void + + + get_descriptor_index(): short + + + set_descriptor_index(in short): void + + + get_access_flags(): short + + + get_name_index(): short + + MethodInfo + + + + + + + + + + formalparameter: Menge + + + hamaDebug: boolean + + + sc_get_Formalparalist(): Menge + + + codegen(in ClassFile, in CodeAttribute): void + + + get_codegen_ParameterList(in Menge): String + + + set_AddParameter(in FormalParameter): void + + ParameterList + + + + + + + + + + declid: DeclId + + + type: Type + + + set_Type(in Type): void + + + set_DeclId(in DeclId): void + + + get_Type(): Type + + + get_St_Type(): String + + + get_Name(): String + + + codegen(in ClassFile, in CodeAttribute): void + + FormalParameter + + + + + + + + + + kill: Hashtable + + + fielddecl: Menge + + + hash: Hashtable + + + paraclasshash: Hashtable + + + is_declared(in Type, in Menge): boolean + + + get_FieldDeclMenge(): Menge + + + sc_check(in Menge, in boolean): void + + + complete_parahashtable(in Menge, in UsedId, in Hashtable, in boolean): Hashtable + + + get_hash(): Hashtable + + + sc_init_hashtable(in Menge, in String, in String, in boolean): void + + + codegen(in ClassFile, in Menge): void + + + sc_init_hashtable_for_extended_classes(in Menge, in String, in Hashtable, in Menge, in Hashtable, in Hashtable, in boolean): void + + + init_parahashtable(in Menge, in boolean): Hashtable + + + istParameterOK(in Menge, in Menge): void + + + set_FieldDecl(in FieldDecl): void + + + print_rec(in Hashtable): void + + + print_rec(in Menge): void + + + print_rec(in String, in Menge): void + + + print_rec(in String, in Hashtable): void + + ClassBody + + + + + + + + + + bEqual: boolean + + + bSubst: boolean + + + TA1: Type + + + TA2: Type + + + getTA2Copy(): Type + + + copyType(in Type): Type + + + Pair(in Type, in Type): void + + + isInMenge(in Menge): boolean + + + getTA1Copy(): Type + + + Pair(in Type, in Type, in boolean): void + + + isEqual(): boolean + + + toString(): String + + Pair + + + + + + + TypeSpec + + + + + + + + + + exlist: Menge + + + addException(in SCExcept): void + + + get_exlist(): Menge + + SCClassBodyException + + + + + + + + + + reftype: Menge + + + set_addElem(in RefType): void + + ExceptionList + + + + + + + + + + paratyp: Menge + + + hamaDebug: boolean + + + modifiers: Modifiers + + + name: String + + + wert: ExprStmt + + + DeclId(in String): void + + + set_Paratyp(in Menge): void + + + get_Modifiers(): Modifiers + + + set_ListType(in Type): void + + + get_access_flags(): short + + + get_Paratyp(): Menge + + + codegen_InstVarDecl(in ClassFile, in Type, in Menge): void + + + set_Wert(in ExprStmt): void + + + get_Wert(): ExprStmt + + + codegen_LocalVarDecl(in ClassFile, in CodeAttribute, in Type, in Menge): void + + + DeclId(): void + + + set_Modifiers(in Modifiers): void + + + set_Name(in String): void + + + get_Name(): String + + DeclId + + + + + + + + + + classname: String + + + modifiers: Modifiers + + + get_classname(): String + + + set_Modifiers(in Modifiers): void + + + set_classname(in String): void + + + get_access_flags(): short + + + get_Modifiers(): Modifiers + + ClassDeclId + + + + + + + + + + name: Menge + + + vParaOrg: Menge + + + typen: Menge + + + paralist: Menge + + + get_ParaList(): Menge + + + set_Name(in String): void + + + get_codegen_UsedId(): String + + + get_Typen(): Menge + + + get_Name_1Element(): String + + + set_Typen(in Menge): void + + + get_Name(): Menge + + + set_ParaList(in Menge): void + + UsedId + + + + + + + + + + exlist: Menge + + + get_exlist(): Menge + + + addException(in SCExcept): void + + SCStatementException + + + + + + + + + + type: String + + + class_name: String + + + descriptor_index: short + + + access_flags: short + + + name_index: short + + + attributes: Menge + + + name: String + + + set_name_index(in short): void + + + get_access_flags(): short + + + set_Name(in String): void + + + get_Name(): String + + + set_Type(in String): void + + + set_attributes(in Menge): void + + + get_name_index(): short + + + get_Class_Name(): String + + + set_descriptor_index(in short): void + + + set_access_flags(in short): void + + + get_Type(): String + + + codegen(in ClassFile, in FileOutputStream): void + + + get_descriptor_index(): short + + + set_Class_Name(in String): void + + + get_attributes(): Menge + + FieldInfo + + + + + + + + + + superclassid: UsedId + + + vParaOrg: Menge + + + parahash: Hashtable + + + cdid: ClassDeclId + + + paralist: Menge + + + body: ClassBody + + + java: Class + + + status: Status + + + class_block: Block + + + get_ParaList(): Menge + + + set_Status(in Status): void + + + get_class_block(): Block + + + set_UsedId(in UsedId): void + + + complete_paralist(in boolean): Menge + + + codegen(in boolean): void + + + get_classname(): String + + + get_ClassBody(): ClassBody + + + get_ParaHash(): Hashtable + + + set_ParaList(in Menge): void + + + does_Class_extend(): boolean + + + set_ClassBody(in ClassBody): void + + + sc_check_for_extended_classes(in Menge, in Hashtable, in boolean): void + + + get_Superclass_Name(): String + + + para_check(in Menge, in boolean): void + + + set_ParaHash(in Hashtable): void + + + sc_check(in Menge, in boolean): void + + + set_class_block(in Block): void + + + is_member(in String): String + + + set_ClassDeclId(in ClassDeclId): void + + + print_rec(in String, in Menge): void + + + print_rec(in String, in Hashtable): void + + + print_rec(in Hashtable): void + + + print_rec(in Menge): void + + Class + + + + + + + + + + expr: Menge + + + get_codegen_ArgumentList(in Menge): String + + + get_firstElement(): Object + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + ArgumentList + + + + + + + + + + exlist: Menge + + + get_exlist(): Menge + + + set_exlist(in Menge): void + + SCMethodException + + + + + + + + + + ndiv(in String): Byte + + + nstore(in String): Byte + + + bytes_to_int(in Byte): int + + + get_nType(in String): int + + + nstore_n(in String, in int): Byte + + + nsub(in String): Byte + + + nrem(in String): Byte + + + nor(in String): Byte + + + nconst_n(in String, in int): Byte + + + ncmpg(in String): Byte + + + nneg(in String): Byte + + + if_ncmpeq(in String): Byte + + + nand(in String): Byte + + + nadd(in String): Byte + + + get_codegen_Type(in String, in Menge): String + + + bytes_to_int(in Byte, in Byte): int + + + nreturn(in String): Byte + + + nload_n(in String, in int): Byte + + + ncmpl(in String): Byte + + + bytes_to_int(in Byte, in Byte, in Byte, in Byte): int + + + nmul(in String): Byte + + + if_ncmpne(in String): Byte + + + nload(in String): Byte + + + nastore(in String): Byte + + + nshl(in String): Byte + + + naload(in String): Byte + + + nushr(in String): Byte + + + get_Command(in Menge): void + + + nshr(in String): Byte + + + nxor(in String): Byte + + + n2n(in String, in String): Byte + + JVMCode + + + + + + + + + + paralist: Menge + + + ParaList(in Type): void + + + ParaList(): void + + + get_firstElement(): Object + + + get_ParaList(): Menge + + + add_ParaList(in Object): void + + ParaList + + + + + + + UnaryPlus + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in String, in boolean): void + + UnaryMinus + + + + + + + + + + token: Object + + + lexem: String + + + Token(in int): void + + + Token(in int, in String): void + + + Token(in int, in char): void + + + String2Int(): int + + + get_String(): String + + + getLexem(): String + + + CharInString(): char + + + String2Bool(): boolean + + Token + + + + + + + + + + classname: String + + + function: String + + + statement: String + + + error: String + + + get_classname(): String + + + set_classname(in String): void + + + set_function(in String): void + + + get_statement(): String + + + set_error(in String): void + + + set_statement(in String): void + + + get_function(): String + + + fehlerausgabe(): void + + SCExcept + + + + + + + + + + message: String + + + get_Message(): String + + + JVMCodeException(in String): void + + JVMCodeException + + + + + + + + + + bytes[0..*]: byte + + + codegen(in ClassFile, in FileOutputStream): void + + + get_bytes(): byte[] + + + set_bytes(in byte[]): void + + CONSTANT_Utf8_info + + + + + + + + + + name_and_type_index: short + + + class_index: short + + + set_name_and_type_index(in short): void + + + set_class_index(in short): void + + + get_class_index(): short + + + codegen(in ClassFile, in FileOutputStream): void + + + get_name_and_type_index(): short + + CONSTANT_Fieldref_info + + + + + + + + + + bytes: int + + + get_bytes(): int + + + set_bytes(in int): void + + + codegen(in ClassFile, in FileOutputStream): void + + CONSTANT_Float_info + + + + + + + + + + bytes: int + + + set_bytes(in int): void + + + codegen(in ClassFile, in FileOutputStream): void + + + get_bytes(): int + + CONSTANT_Integer_info + + + + + + + + + + string_index: short + + + set_string_index(in short): void + + + get_string_index(): short + + + codegen(in ClassFile, in FileOutputStream): void + + CONSTANT_String_info + + + + + + + + + + name_and_type_index: short + + + class_index: short + + + set_class_index(in short): void + + + codegen(in ClassFile, in FileOutputStream): void + + + get_name_and_type_index(): short + + + get_class_index(): short + + + set_name_and_type_index(in short): void + + CONSTANT_Methodref_info + + + + + + + + + + tag: byte + + + get_tag(): byte + + + set_tag(in byte): void + + + codegen(in ClassFile, in FileOutputStream): void + + CPInfo + + + + + + + + + + name_index: short + + + set_name_index(in short): void + + + codegen(in ClassFile, in FileOutputStream): void + + + get_name_index(): short + + CONSTANT_Class_info + + + + + + + + + + descriptor_index: short + + + name_index: short + + + get_name_index(): short + + + set_name_index(in short): void + + + get_descriptor_index(): short + + + codegen(in ClassFile, in FileOutputStream): void + + + set_descriptor_index(in short): void + + CONSTANT_NameAndType_info + + + + + + + + + + name_and_type_index: short + + + class_index: short + + + codegen(in ClassFile, in FileOutputStream): void + + + get_name_and_type_index(): short + + + set_name_and_type_index(in short): void + + + set_class_index(in short): void + + + get_class_index(): short + + CONSTANT_InterfaceMethodref_info + + + + + + + + + + low_bytes: int + + + high_bytes: int + + + set_high_bytes(in int): void + + + get_high_bytes(): int + + + set_low_bytes(in int): void + + + get_low_bytes(): int + + + codegen(in ClassFile, in FileOutputStream): void + + CONSTANT_Double_info + + + + + + + + + + low_bytes: int + + + high_bytes: int + + + codegen(in ClassFile, in FileOutputStream): void + + + set_low_bytes(in int): void + + + set_high_bytes(in int): void + + + get_low_bytes(): int + + + get_high_bytes(): int + + CONSTANT_Long_info + + + + + + + + + + advance(): boolean + + + Scanner(in Reader): void + + + value(): Object + + + token(): int + + Scanner + + + + + + + + + + yylex(): boolean + + + JavaLexer(in InputStream): void + + + JavaLexer(in Reader): void + + + yybegin(in int): void + + + yy_to_mark(): void + + + yy_advance(): int + + + yy_mark_start(): void + + + unpackFromString(in int, in int, in String): int[][] + + + yy_move_end(): void + + + JavaLexer(): void + + + yylength(): int + + + yy_mark_end(): void + + + yytext(): String + + + yy_double(in char[]): char[] + + + yy_error(in int, in boolean): void + + JavaLexer + + + + + + + + + + nDebug2: int + + + nDebug: int + + + wandleTV2RefType(in Menge, in Menge): void + + + Debug(in String, in int): void + + + main(in String[]): void + + MyCompiler + + + + + + + + + + main(in String[]): void + + JavaCompiler + + + + + + + + + + + yyerror(in String, in String[]): void + + + yyerror(in String): void + + + yyparse(in yyInput, in Object): Object + + + yyparse(in yyInput): Object + + + yyExpecting(in int): String[] + + + yyDefault(in Object): Object + + + + + + + + + + value(): Object + + + token(): int + + + advance(): boolean + «interface» + + yyInput + + + + + + + + + + yyException(in String): void + + yyException + + JavaParser + + + + + + + UserDef + + + + + + + Import + + + + + + + + + + userdef: UserDef + + + imp: Import + + + set_UserDef(in UserDef): void + + + set_Import(in Import): void + + Status + + + + + + + CharacterType + + + + + + + ReturnType + + + + + + + + + + parameter: Menge + + + set_ParaList(in Menge): void + + + isTV(in int): boolean + + + get_Type(): String + + + add_Parameter(in Object): void + + + RefType(in String, in Menge): void + + + getParaN(in int): String + + + RefType(): void + + + get_ParaList(): Menge + + + getTypeName(): String + + + RefType(in RefType): void + + + RefType(in String): void + + RefType + + + + + + + + + + strNextName: String + + + TyploseVariable(in String): void + + + makeNewName(): String + + + manipulate(in int, in char): void + + + inc(in int): void + + TyploseVariable + + + + + + + IntegerType + + + + + + + + + + used: UsedId + + + type: String + + + hamaDebug: boolean + + + get_Name(): String + + + Type(): void + + + Type(in String): void + + + get_UsedId(): UsedId + + + set_UsedId(in UsedId): void + + + get_codegen_Type(in Menge): String + + + get_Type(): String + + + set_Type(in String): void + + Type + + + + + + + BooleanType + + + + + + + + + + name: String + + + get_Name(): String + + + set_Name(in String): void + + Void + + + + + + + BaseType + + + + + + + Abstract + + + + + + + Public + + + + + + + Modifier + + + + + + + Private + + + + + + + Protected + + + + + + + Static + + + + + + + NoReceiver + + + + + + + + + + noreceiver: NoReceiver + + + expr: Expr + + + set_Expr(in Expr): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + get_Type(): String + + Receiver + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + EmptyStmt + + + + + + + + + + expr: Expr + + + get_Name(): String + + + set_Expr(in Expr): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + PostDecExpr + + + + + + + + + + Bool: boolean + + + BoolLiteral(): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + get_Name(): String + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + set_Bool(in boolean): void + + BoolLiteral + + + + + + + + + + expr: Expr + + + set_Expr(in Expr): void + + + get_Name(): String + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + PreDecExpr + + + + + + + + + + op: Operator + + + expr1: Expr + + + expr2: Expr + + + set_Expr1(in Expr): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + get_Expr2(): Expr + + + neg_codegen(in ClassFile, in CodeAttribute, in Menge): void + + + get_Operator(): Operator + + + set_Expr2(in Expr): void + + + get_Name(): String + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + type_check(in CodeAttribute): boolean + + + not_codegen(in ClassFile, in CodeAttribute, in Menge): void + + + set_Operator(in Operator): void + + + get_Expr1(): Expr + + Binary + + + + + + + + + + LocalOrFieldVar(in String): void + + + set_UsedId(in UsedId): void + + + get_Name(): String + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + LocalOrFieldVar(): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + LocalOrFieldVar + + + + + + + + + + class_name: String + + + arglist: ArgumentList + + + exprtypes: Menge + + + finde_method: Menge + + + uebernachdurch: Hashtable + + + called_method: Method + + + receiver: Receiver + + + counter: int + + + add_Expr(in Expr): void + + + set_UsedId(in UsedId): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + set_Receiver(in Receiver): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + sc_init_extended_fcts(in Menge, in Menge, in String, in String, in boolean): void + + + get_Name(): String + + + sc_check_method_kleiner(in Menge, in String, in String, in boolean): boolean + + + set_ArgumentList(in ArgumentList): void + + + set_Expr_Menge(in Menge): void + + + sc_check_uebergabe(in Menge, in Menge, in boolean, in int, in Hashtable, in Hashtable): void + + + sc_check_get_Method(in Menge, in String, in boolean, in Hashtable, in Hashtable): void + + MethodCall + + + + + + + + + + statements: Menge + + + HashTabelleBlock: Hashtable + + + sc_meth_ret_type: String + + + HashTabelleKlasse: Hashtable + + + block_para: Hashtable + + + set_Statement_Menge(in Menge): void + + + set_Statement(in Statement): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + get_Statement(): Menge + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + Block + + + + + + + + + + expr: Expr + + + plus: UnaryPlus + + + get_Name(): String + + + set_Expr(in Expr): void + + + set_UnaryPlus(in UnaryPlus): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + PositivExpr + + + + + + + + + + type: Type + + + expr: Expr + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + get_Name(): String + + + set_Expr(in Expr): void + + + set_Type(in Type): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + CastExpr + + + + + + + + + + declid: Menge + + + paralist: Menge + + + parahash: Hashtable + + + type: Type + + + set_Type(in Type): void + + + is_declared(in Type, in Menge): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + set_DeclId(in DeclId): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + check_anz(in Type, in Menge, in Menge): void + + + get_Name(): String + + + set_ParaList(in Menge): void + + LocalVarDecl + + + + + + + + + + expr1: Expr + + + expr2: Expr + + + get_Name(): String + + + set_Expr(in Expr, in Expr): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + Assign + + + + + + + + + + usedid: UsedId + + + get_Name_Menge(): Menge + + + get_UsedId(): UsedId + + + set_Type(in Type): void + + + get_Type_Menge(): Menge + + + set_UsedId(in UsedId): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + get_Name(): String + + Expr + + + + + + + + + + Int: int + + + set_Int(in int): void + + + IntLiteral(): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + get_Name(): String + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + IntLiteral + + + + + + + + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + print_rec(in String, in Hashtable): void + + + print_rec(in String, in Menge): void + + + print_rec(in Hashtable): void + + + print_rec(in Menge): void + + Statement + + + + + + + + + + expr: Expr + + + not: UnaryNot + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + set_Expr(in Expr): void + + + get_Name(): String + + + get_Expr(): Expr + + + not_codegen(in ClassFile, in CodeAttribute, in Menge): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + set_UnaryNot(in UnaryNot): void + + NotExpr + + + + + + + + + + expr: Expr + + + else_block: Statement + + + then_block: Statement + + + hamaDebug: boolean + + + set_Then_block(in Statement): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + set_Else_block(in Statement): void + + + set_Expr(in Expr): void + + + if_codegen(in ClassFile, in CodeAttribute, in boolean, in Menge): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + IfStmt + + + + + + + + + + arglist: ArgumentList + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + get_Name(): String + + + set_UsedId(in UsedId): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + set_ArgumentList(in ArgumentList): void + + NewClass + + + + + + + + + + expr: Expr + + + type: String + + + usedid: UsedId + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + InstVar(in String, in String): void + + + get_Name(): String + + + get_codegen_UsedId(): String + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + InstVar + + + + + + + + + + type: Type + + + get_Type(): String + + ExprStmt + + + + + + + + + + Null(): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + get_Name(): String + + Null + + + + + + + + + + expr: Expr + + + reftype: RefType + + + is_instance: boolean + + + InstanceOf(): void + + + get_Name(): String + + + set_Type(in RefType): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + set_Expr(in Expr): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + InstanceOf + + + + + + + + + + Char: char + + + CharLiteral(): void + + + get_Name(): String + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + set_Char(in char): void + + CharLiteral + + + + + + + + + + expr: Expr + + + loop_block: Statement + + + set_Expr(in Expr): void + + + set_Loop_block(in Statement): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + loop_codegen(in ClassFile, in CodeAttribute, in int, in boolean, in Menge): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + WhileStmt + + + + + + + + + + string: String + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + StringLiteral(): void + + + get_Name(): String + + + set_String(in String): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + StringLiteral + + + + + + + Literal + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + UnaryExpr + + + + + + + + + + arglist: ArgumentList + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + set_UsedId(in UsedId): void + + + set_ArgumentList(in ArgumentList): void + + + get_Name(): String + + This + + + + + + + + + + retexpr: Expr + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + set_ReturnExpr(in Expr): void + + + get_Type(): String + + Return + + + + + + + + + + expr: Expr + + + get_Name(): String + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + set_Expr(in Expr): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + PostIncExpr + + + + + + + + + + expr: Expr + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + get_Name(): String + + + set_Expr(in Expr): void + + PreIncExpr + + + + + + + + + + expr: Expr + + + neg: UnaryMinus + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + set_Expr(in Expr): void + + + set_UnaryMinus(in UnaryMinus): void + + + get_Name(): String + + + neg_codegen(in ClassFile, in CodeAttribute, in Menge): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + NegativeExpr + + + + + + + + + + expr: Menge + + + type: Type + + + get_Name(): String + + + get_codegen_Array_Type(): int + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + NewArray + + + + + + + BinaryExpr + + + + + + + AndOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + + if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void + + LessOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + MinusOp + + + + + + + OrOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + + if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void + + LessEquOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + PlusOp + + + + + + + + + + if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + EqualOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + + if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void + + NotEqualOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + + if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void + + GreaterEquOp + + + + + + + + + + if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + GreaterOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + TimesOp + + + + + + + MulOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + Operator + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + DivideOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + + if_codegen(in ClassFile, in CodeAttribute, in boolean, in Expr, in Statement, in Statement, in Menge): void + + + loop_codegen(in ClassFile, in CodeAttribute, in Expr, in int, in boolean, in Menge): void + + + replace_index(in CodeAttribute, in Menge, in int, in int): void + + + build(in ClassFile, in CodeAttribute, in Expr, in Menge, in boolean, in boolean, in boolean, in Menge): void + + LogOp + + + + + + + + + + if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void + + RelOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + AddOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + ModuloOp + + + + + + + + + + info[0..*]: byte + + + set_info(in byte[]): void + + + get_attributes_length(): int + + + set_info(in Menge): void + + + codegen(in ClassFile, in FileOutputStream): void + + + get_info(): byte[] + + + get_info_Menge(): Menge + + AttributeInfo + + + + + + + + + + local_name_Menge: Menge + + + code_Menge: Menge + + + attributes: Menge + + + exception_tables: Menge + + + local_type_Menge: Menge + + + CodeAttribute(in String, in short): void + + + add_code_int(in int): void + + + get_attributes_Menge(): Menge + + + add_code_short(in int): void + + + add_code_byte_array(in byte[]): void + + + get_indexOf_Var(in String): int + + + add_local(in String, in Type): void + + + add_code(in Byte): void + + + get_code_Menge(): Menge + + + get_TypeOf_Var(in String): Type + + + set_exception_table_Menge(in Menge): void + + + set_code_short(in int, in int): void + + + get_attributes_length(): int + + + codegen(in ClassFile, in FileOutputStream): void + + + add_code_byte(in int): void + + + set_code(in Byte, in int): void + + + get_local_Menge(): Menge + + + get_code_length(): int + + + get_exception_table_Menge(): Menge + + + set_attributes_Menge(in Menge): void + + + calculate_max_stack(): short + + CodeAttribute + + + + + + + + + + attribute_name_index: short + + + get_attribute_name_index(): short + + + set_attribute_name_index(in short): void + + + get_attributes_length(): int + + + codegen(in ClassFile, in FileOutputStream): void + + Attribute + + + + + + + + + + get_codegen_Param_Type(in Menge): String + + + Constructor(): void + + + codegen(in ClassFile, in Menge): void + + Constructor + + + + + + + + + + type: Type + + + get_Type(): String + + + set_Type(in Type): void + + + codegen(in ClassFile, in Menge): void + + InstVarDecl + + + + + + + + + + parameterlist: ParameterList + + + exceptionlist: ExceptionList + + + block: Block + + + returntype: Type + + + types_in_parameterlist: Menge + + + get_Method_Name(): String + + + get_ParaList(): ParameterList + + + set_ExceptionList(in ExceptionList): void + + + set_Modifiers(in Modifiers): void + + + get_Block(): Block + + + set_Block(in Block): void + + + get_Type_Paralist(): Menge + + + set_ReturnType(in Type): void + + + set_ParaList(in ParameterList): void + + + get_ReturnType(): Type + + + call_sc_check(in Menge, in Hashtable, in boolean, in Hashtable): void + + + get_codegen_Param_Type(in Menge): String + + + get_Type(): String + + + sc_init_parameterlist(in boolean): void + + + codegen(in ClassFile, in Menge): void + + + get_ExceptionList(): ExceptionList + + Method + + + + + + + + + + declid: Menge + + + get_Type(): String + + + codegen(in ClassFile, in Menge): void + + + getDeclIdMenge(): Menge + + + get_Name(): Menge + + + set_DeclId(in DeclId): void + + + setDeclIdMenge(in Menge): void + + FieldDecl + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/OldStuff/Rest/Operator.svg b/doc/OldStuff/Rest/Operator.svg index 5bb765ad4..618a39901 100755 --- a/doc/OldStuff/Rest/Operator.svg +++ b/doc/OldStuff/Rest/Operator.svg @@ -1,458 +1,458 @@ - - - - - - - - - - - - - - - - - - - if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void - - RelOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - - if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void - - EqualOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - - if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void - - LessOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - - if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void - - NotEqualOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - MinusOp - - - - - - - OrOp - - - - - - - AndOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - TimesOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - - if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void - - GreaterEquOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - AddOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - ModuloOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - - if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void - - GreaterOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - DivideOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - PlusOp - - - - - - - MulOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - - if_codegen(in ClassFile, in CodeAttribute, in boolean, in Expr, in Statement, in Statement, in Menge): void - - - loop_codegen(in ClassFile, in CodeAttribute, in Expr, in int, in boolean, in Menge): void - - - replace_index(in CodeAttribute, in Menge, in int, in int): void - - - build(in ClassFile, in CodeAttribute, in Expr, in Menge, in boolean, in boolean, in boolean, in Menge): void - - LogOp - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - Operator - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void - - - if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void - - LessEquOp - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void + + RelOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + + if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void + + EqualOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + + if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void + + LessOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + + if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void + + NotEqualOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + MinusOp + + + + + + + OrOp + + + + + + + AndOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + TimesOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + + if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void + + GreaterEquOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + AddOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + ModuloOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + + if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void + + GreaterOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + DivideOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + PlusOp + + + + + + + MulOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + + if_codegen(in ClassFile, in CodeAttribute, in boolean, in Expr, in Statement, in Statement, in Menge): void + + + loop_codegen(in ClassFile, in CodeAttribute, in Expr, in int, in boolean, in Menge): void + + + replace_index(in CodeAttribute, in Menge, in int, in int): void + + + build(in ClassFile, in CodeAttribute, in Expr, in Menge, in boolean, in boolean, in boolean, in Menge): void + + LogOp + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + Operator + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Expr, in boolean, in Menge): void + + + if_codegen(in ClassFile, in CodeAttribute, in String, in boolean): void + + LessEquOp + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/OldStuff/Rest/Rest.svg b/doc/OldStuff/Rest/Rest.svg index b1ea27642..0b70339ad 100755 --- a/doc/OldStuff/Rest/Rest.svg +++ b/doc/OldStuff/Rest/Rest.svg @@ -1,2013 +1,2013 @@ - - - - - - - - - - - - - - - - - - - declid: Menge - - - codegen(in ClassFile, in Menge): void - - - getDeclIdMenge(): Menge - - - get_Name(): Menge - - - get_Type(): String - - - set_DeclId(in DeclId): void - - - setDeclIdMenge(in Menge): void - - FieldDecl - - - - - - - - - - parameterlist: ParameterList - - - exceptionlist: ExceptionList - - - types_in_parameterlist: Menge - - - returntype: Type - - - block: Block - - - sc_init_parameterlist(in boolean): void - - - get_Block(): Block - - - get_ReturnType(): Type - - - set_Block(in Block): void - - - set_Modifiers(in Modifiers): void - - - get_Type(): String - - - set_ExceptionList(in ExceptionList): void - - - set_ParaList(in ParameterList): void - - - get_ExceptionList(): ExceptionList - - - codegen(in ClassFile, in Menge): void - - - get_Type_Paralist(): Menge - - - get_Method_Name(): String - - - get_ParaList(): ParameterList - - - call_sc_check(in Menge, in Hashtable, in boolean, in Hashtable): void - - - set_ReturnType(in Type): void - - - get_codegen_Param_Type(in Menge): String - - Method - - - - - - - - - - type: Type - - - set_Type(in Type): void - - - codegen(in ClassFile, in Menge): void - - - get_Type(): String - - InstVarDecl - - - - - - - - - - get_codegen_Param_Type(in Menge): String - - - Constructor(): void - - - codegen(in ClassFile, in Menge): void - - Constructor - - - - - - - - - - info[0..*]: byte - - - get_attributes_length(): int - - - codegen(in ClassFile, in FileOutputStream): void - - - get_info_Menge(): Menge - - - set_info(in byte[]): void - - - set_info(in Menge): void - - - get_info(): byte[] - - AttributeInfo - - - - - - - - - - attribute_name_index: short - - - codegen(in ClassFile, in FileOutputStream): void - - - get_attribute_name_index(): short - - - get_attributes_length(): int - - - set_attribute_name_index(in short): void - - Attribute - - - - - - - - - - local_name_Menge: Menge - - - exception_tables: Menge - - - attributes: Menge - - - local_type_Menge: Menge - - - code_Menge: Menge - - - CodeAttribute(in String, in short): void - - - set_code_short(in int, in int): void - - - get_indexOf_Var(in String): int - - - add_code(in Byte): void - - - set_attributes_Menge(in Menge): void - - - add_code_byte_array(in byte[]): void - - - get_code_Menge(): Menge - - - codegen(in ClassFile, in FileOutputStream): void - - - get_code_length(): int - - - get_attributes_Menge(): Menge - - - set_code(in Byte, in int): void - - - add_local(in String, in Type): void - - - add_code_short(in int): void - - - get_TypeOf_Var(in String): Type - - - set_exception_table_Menge(in Menge): void - - - add_code_byte(in int): void - - - get_local_Menge(): Menge - - - get_exception_table_Menge(): Menge - - - add_code_int(in int): void - - - get_attributes_length(): int - - - calculate_max_stack(): short - - CodeAttribute - - - - - - - - - - expr: Expr - - - noreceiver: NoReceiver - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - set_Expr(in Expr): void - - - get_Type(): String - - Receiver - - - - - - - NoReceiver - - - - - - - Public - - - - - - - Private - - - - - - - Protected - - - - - - - Modifier - - - - - - - Abstract - - - - - - - Static - - - - - - - - - - parameter: Menge - - - add_Parameter(in Object): void - - - set_ParaList(in Menge): void - - - get_ParaList(): Menge - - - getTypeName(): String - - - getParaN(in int): String - - - isTV(in int): boolean - - - RefType(in RefType): void - - - RefType(in String, in Menge): void - - - get_Type(): String - - - RefType(): void - - - RefType(in String): void - - RefType - - - - - - - - - - strNextName: String - - - TyploseVariable(in String): void - - - makeNewName(): String - - - inc(in int): void - - - manipulate(in int, in char): void - - TyploseVariable - - - - - - - ReturnType - - - - - - - BooleanType - - - - - - - - - - hamaDebug: boolean - - - type: String - - - used: UsedId - - - get_Type(): String - - - Type(): void - - - get_UsedId(): UsedId - - - set_UsedId(in UsedId): void - - - set_Type(in String): void - - - Type(in String): void - - - get_Name(): String - - - get_codegen_Type(in Menge): String - - Type - - - - - - - - - - name: String - - - set_Name(in String): void - - - get_Name(): String - - Void - - - - - - - BaseType - - - - - - - IntegerType - - - - - - - CharacterType - - - - - - - - - - imp: Import - - - userdef: UserDef - - - set_UserDef(in UserDef): void - - - set_Import(in Import): void - - Status - - - - - - - Import - - - - - - - UserDef - - - - - - - - - - nDebug: int - - - nDebug2: int - - - wandleTV2RefType(in Menge, in Menge): void - - - Debug(in String, in int): void - - - main(in String[]): void - - MyCompiler - - - - - - - - - - Scanner(in Reader): void - - - token(): int - - - advance(): boolean - - - value(): Object - - Scanner - - - - - - - - - - JavaLexer(in Reader): void - - - yylex(): boolean - - - JavaLexer(in InputStream): void - - - yytext(): String - - - yy_double(in char[]): char[] - - - unpackFromString(in int, in int, in String): int[][] - - - yy_to_mark(): void - - - JavaLexer(): void - - - yy_error(in int, in boolean): void - - - yy_mark_end(): void - - - yybegin(in int): void - - - yy_mark_start(): void - - - yy_advance(): int - - - yylength(): int - - - yy_move_end(): void - - JavaLexer - - - - - - - - - - main(in String[]): void - - JavaCompiler - - - - - - - - - - - yyparse(in yyInput, in Object): Object - - - yyerror(in String, in String[]): void - - - yyerror(in String): void - - - yyparse(in yyInput): Object - - - yyExpecting(in int): String[] - - - yyDefault(in Object): Object - - - - - - - - - - advance(): boolean - - - value(): Object - - - token(): int - «interface» - - yyInput - - - - - - - - - - yyException(in String): void - - yyException - - JavaParser - - - - - - - - - - low_bytes: int - - - high_bytes: int - - - get_low_bytes(): int - - - get_high_bytes(): int - - - set_high_bytes(in int): void - - - set_low_bytes(in int): void - - - codegen(in ClassFile, in FileOutputStream): void - - CONSTANT_Double_info - - - - - - - - - - class_index: short - - - name_and_type_index: short - - - set_name_and_type_index(in short): void - - - codegen(in ClassFile, in FileOutputStream): void - - - get_name_and_type_index(): short - - - set_class_index(in short): void - - - get_class_index(): short - - CONSTANT_Fieldref_info - - - - - - - - - - low_bytes: int - - - high_bytes: int - - - set_high_bytes(in int): void - - - codegen(in ClassFile, in FileOutputStream): void - - - get_high_bytes(): int - - - set_low_bytes(in int): void - - - get_low_bytes(): int - - CONSTANT_Long_info - - - - - - - - - - bytes: int - - - codegen(in ClassFile, in FileOutputStream): void - - - set_bytes(in int): void - - - get_bytes(): int - - CONSTANT_Float_info - - - - - - - - - - bytes[0..*]: byte - - - set_bytes(in byte[]): void - - - codegen(in ClassFile, in FileOutputStream): void - - - get_bytes(): byte[] - - CONSTANT_Utf8_info - - - - - - - - - - tag: byte - - - codegen(in ClassFile, in FileOutputStream): void - - - get_tag(): byte - - - set_tag(in byte): void - - CPInfo - - - - - - - - - - descriptor_index: short - - - name_index: short - - - get_name_index(): short - - - codegen(in ClassFile, in FileOutputStream): void - - - set_descriptor_index(in short): void - - - get_descriptor_index(): short - - - set_name_index(in short): void - - CONSTANT_NameAndType_info - - - - - - - - - - bytes: int - - - set_bytes(in int): void - - - get_bytes(): int - - - codegen(in ClassFile, in FileOutputStream): void - - CONSTANT_Integer_info - - - - - - - - - - class_index: short - - - name_and_type_index: short - - - get_name_and_type_index(): short - - - get_class_index(): short - - - codegen(in ClassFile, in FileOutputStream): void - - - set_class_index(in short): void - - - set_name_and_type_index(in short): void - - CONSTANT_InterfaceMethodref_info - - - - - - - - - - name_index: short - - - get_name_index(): short - - - set_name_index(in short): void - - - codegen(in ClassFile, in FileOutputStream): void - - CONSTANT_Class_info - - - - - - - - - - name_and_type_index: short - - - class_index: short - - - set_class_index(in short): void - - - set_name_and_type_index(in short): void - - - get_name_and_type_index(): short - - - get_class_index(): short - - - codegen(in ClassFile, in FileOutputStream): void - - CONSTANT_Methodref_info - - - - - - - - - - string_index: short - - - get_string_index(): short - - - codegen(in ClassFile, in FileOutputStream): void - - - set_string_index(in short): void - - CONSTANT_String_info - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + declid: Menge + + + codegen(in ClassFile, in Menge): void + + + getDeclIdMenge(): Menge + + + get_Name(): Menge + + + get_Type(): String + + + set_DeclId(in DeclId): void + + + setDeclIdMenge(in Menge): void + + FieldDecl + + + + + + + + + + parameterlist: ParameterList + + + exceptionlist: ExceptionList + + + types_in_parameterlist: Menge + + + returntype: Type + + + block: Block + + + sc_init_parameterlist(in boolean): void + + + get_Block(): Block + + + get_ReturnType(): Type + + + set_Block(in Block): void + + + set_Modifiers(in Modifiers): void + + + get_Type(): String + + + set_ExceptionList(in ExceptionList): void + + + set_ParaList(in ParameterList): void + + + get_ExceptionList(): ExceptionList + + + codegen(in ClassFile, in Menge): void + + + get_Type_Paralist(): Menge + + + get_Method_Name(): String + + + get_ParaList(): ParameterList + + + call_sc_check(in Menge, in Hashtable, in boolean, in Hashtable): void + + + set_ReturnType(in Type): void + + + get_codegen_Param_Type(in Menge): String + + Method + + + + + + + + + + type: Type + + + set_Type(in Type): void + + + codegen(in ClassFile, in Menge): void + + + get_Type(): String + + InstVarDecl + + + + + + + + + + get_codegen_Param_Type(in Menge): String + + + Constructor(): void + + + codegen(in ClassFile, in Menge): void + + Constructor + + + + + + + + + + info[0..*]: byte + + + get_attributes_length(): int + + + codegen(in ClassFile, in FileOutputStream): void + + + get_info_Menge(): Menge + + + set_info(in byte[]): void + + + set_info(in Menge): void + + + get_info(): byte[] + + AttributeInfo + + + + + + + + + + attribute_name_index: short + + + codegen(in ClassFile, in FileOutputStream): void + + + get_attribute_name_index(): short + + + get_attributes_length(): int + + + set_attribute_name_index(in short): void + + Attribute + + + + + + + + + + local_name_Menge: Menge + + + exception_tables: Menge + + + attributes: Menge + + + local_type_Menge: Menge + + + code_Menge: Menge + + + CodeAttribute(in String, in short): void + + + set_code_short(in int, in int): void + + + get_indexOf_Var(in String): int + + + add_code(in Byte): void + + + set_attributes_Menge(in Menge): void + + + add_code_byte_array(in byte[]): void + + + get_code_Menge(): Menge + + + codegen(in ClassFile, in FileOutputStream): void + + + get_code_length(): int + + + get_attributes_Menge(): Menge + + + set_code(in Byte, in int): void + + + add_local(in String, in Type): void + + + add_code_short(in int): void + + + get_TypeOf_Var(in String): Type + + + set_exception_table_Menge(in Menge): void + + + add_code_byte(in int): void + + + get_local_Menge(): Menge + + + get_exception_table_Menge(): Menge + + + add_code_int(in int): void + + + get_attributes_length(): int + + + calculate_max_stack(): short + + CodeAttribute + + + + + + + + + + expr: Expr + + + noreceiver: NoReceiver + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + set_Expr(in Expr): void + + + get_Type(): String + + Receiver + + + + + + + NoReceiver + + + + + + + Public + + + + + + + Private + + + + + + + Protected + + + + + + + Modifier + + + + + + + Abstract + + + + + + + Static + + + + + + + + + + parameter: Menge + + + add_Parameter(in Object): void + + + set_ParaList(in Menge): void + + + get_ParaList(): Menge + + + getTypeName(): String + + + getParaN(in int): String + + + isTV(in int): boolean + + + RefType(in RefType): void + + + RefType(in String, in Menge): void + + + get_Type(): String + + + RefType(): void + + + RefType(in String): void + + RefType + + + + + + + + + + strNextName: String + + + TyploseVariable(in String): void + + + makeNewName(): String + + + inc(in int): void + + + manipulate(in int, in char): void + + TyploseVariable + + + + + + + ReturnType + + + + + + + BooleanType + + + + + + + + + + hamaDebug: boolean + + + type: String + + + used: UsedId + + + get_Type(): String + + + Type(): void + + + get_UsedId(): UsedId + + + set_UsedId(in UsedId): void + + + set_Type(in String): void + + + Type(in String): void + + + get_Name(): String + + + get_codegen_Type(in Menge): String + + Type + + + + + + + + + + name: String + + + set_Name(in String): void + + + get_Name(): String + + Void + + + + + + + BaseType + + + + + + + IntegerType + + + + + + + CharacterType + + + + + + + + + + imp: Import + + + userdef: UserDef + + + set_UserDef(in UserDef): void + + + set_Import(in Import): void + + Status + + + + + + + Import + + + + + + + UserDef + + + + + + + + + + nDebug: int + + + nDebug2: int + + + wandleTV2RefType(in Menge, in Menge): void + + + Debug(in String, in int): void + + + main(in String[]): void + + MyCompiler + + + + + + + + + + Scanner(in Reader): void + + + token(): int + + + advance(): boolean + + + value(): Object + + Scanner + + + + + + + + + + JavaLexer(in Reader): void + + + yylex(): boolean + + + JavaLexer(in InputStream): void + + + yytext(): String + + + yy_double(in char[]): char[] + + + unpackFromString(in int, in int, in String): int[][] + + + yy_to_mark(): void + + + JavaLexer(): void + + + yy_error(in int, in boolean): void + + + yy_mark_end(): void + + + yybegin(in int): void + + + yy_mark_start(): void + + + yy_advance(): int + + + yylength(): int + + + yy_move_end(): void + + JavaLexer + + + + + + + + + + main(in String[]): void + + JavaCompiler + + + + + + + + + + + yyparse(in yyInput, in Object): Object + + + yyerror(in String, in String[]): void + + + yyerror(in String): void + + + yyparse(in yyInput): Object + + + yyExpecting(in int): String[] + + + yyDefault(in Object): Object + + + + + + + + + + advance(): boolean + + + value(): Object + + + token(): int + «interface» + + yyInput + + + + + + + + + + yyException(in String): void + + yyException + + JavaParser + + + + + + + + + + low_bytes: int + + + high_bytes: int + + + get_low_bytes(): int + + + get_high_bytes(): int + + + set_high_bytes(in int): void + + + set_low_bytes(in int): void + + + codegen(in ClassFile, in FileOutputStream): void + + CONSTANT_Double_info + + + + + + + + + + class_index: short + + + name_and_type_index: short + + + set_name_and_type_index(in short): void + + + codegen(in ClassFile, in FileOutputStream): void + + + get_name_and_type_index(): short + + + set_class_index(in short): void + + + get_class_index(): short + + CONSTANT_Fieldref_info + + + + + + + + + + low_bytes: int + + + high_bytes: int + + + set_high_bytes(in int): void + + + codegen(in ClassFile, in FileOutputStream): void + + + get_high_bytes(): int + + + set_low_bytes(in int): void + + + get_low_bytes(): int + + CONSTANT_Long_info + + + + + + + + + + bytes: int + + + codegen(in ClassFile, in FileOutputStream): void + + + set_bytes(in int): void + + + get_bytes(): int + + CONSTANT_Float_info + + + + + + + + + + bytes[0..*]: byte + + + set_bytes(in byte[]): void + + + codegen(in ClassFile, in FileOutputStream): void + + + get_bytes(): byte[] + + CONSTANT_Utf8_info + + + + + + + + + + tag: byte + + + codegen(in ClassFile, in FileOutputStream): void + + + get_tag(): byte + + + set_tag(in byte): void + + CPInfo + + + + + + + + + + descriptor_index: short + + + name_index: short + + + get_name_index(): short + + + codegen(in ClassFile, in FileOutputStream): void + + + set_descriptor_index(in short): void + + + get_descriptor_index(): short + + + set_name_index(in short): void + + CONSTANT_NameAndType_info + + + + + + + + + + bytes: int + + + set_bytes(in int): void + + + get_bytes(): int + + + codegen(in ClassFile, in FileOutputStream): void + + CONSTANT_Integer_info + + + + + + + + + + class_index: short + + + name_and_type_index: short + + + get_name_and_type_index(): short + + + get_class_index(): short + + + codegen(in ClassFile, in FileOutputStream): void + + + set_class_index(in short): void + + + set_name_and_type_index(in short): void + + CONSTANT_InterfaceMethodref_info + + + + + + + + + + name_index: short + + + get_name_index(): short + + + set_name_index(in short): void + + + codegen(in ClassFile, in FileOutputStream): void + + CONSTANT_Class_info + + + + + + + + + + name_and_type_index: short + + + class_index: short + + + set_class_index(in short): void + + + set_name_and_type_index(in short): void + + + get_name_and_type_index(): short + + + get_class_index(): short + + + codegen(in ClassFile, in FileOutputStream): void + + CONSTANT_Methodref_info + + + + + + + + + + string_index: short + + + get_string_index(): short + + + codegen(in ClassFile, in FileOutputStream): void + + + set_string_index(in short): void + + CONSTANT_String_info + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/OldStuff/Rest/Statement.svg b/doc/OldStuff/Rest/Statement.svg index 1c7a9dd1f..985c9e9f4 100755 --- a/doc/OldStuff/Rest/Statement.svg +++ b/doc/OldStuff/Rest/Statement.svg @@ -1,1868 +1,1868 @@ - - - - - - - - - - - - - - - - - - - expr: Expr - - - set_Expr(in Expr): void - - - get_Name(): String - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - PreIncExpr - - - - - - - - - - expr: Expr - - - get_Name(): String - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - set_Expr(in Expr): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - PostIncExpr - - - - - - - - - - arglist: ArgumentList - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - set_ArgumentList(in ArgumentList): void - - - get_Name(): String - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - set_UsedId(in UsedId): void - - This - - - - - - - - - - Char: char - - - CharLiteral(): void - - - set_Char(in char): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - get_Name(): String - - CharLiteral - - - - - - - - - - type: String - - - expr: Expr - - - usedid: UsedId - - - get_codegen_UsedId(): String - - - InstVar(in String, in String): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - get_Name(): String - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - InstVar - - - - - - - - - - get_Name(): String - - - set_UsedId(in UsedId): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - LocalOrFieldVar(in String): void - - - LocalOrFieldVar(): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - LocalOrFieldVar - - - - - - - - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - print_rec(in String, in Menge): void - - - print_rec(in Hashtable): void - - - print_rec(in Menge): void - - - print_rec(in String, in Hashtable): void - - Statement - - - - - - - Literal - - - - - - - - - - loop_block: Statement - - - expr: Expr - - - set_Loop_block(in Statement): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - set_Expr(in Expr): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - loop_codegen(in ClassFile, in CodeAttribute, in int, in boolean, in Menge): void - - WhileStmt - - - - - - - - - - expr: Expr - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - set_Expr(in Expr): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - get_Name(): String - - PostDecExpr - - - - - - - - - - Bool: boolean - - - BoolLiteral(): void - - - get_Name(): String - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - set_Bool(in boolean): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - BoolLiteral - - - - - - - - - - called_method: Method - - - exprtypes: Menge - - - receiver: Receiver - - - class_name: String - - - finde_method: Menge - - - arglist: ArgumentList - - - counter: int - - - uebernachdurch: Hashtable - - - set_UsedId(in UsedId): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - set_Expr_Menge(in Menge): void - - - set_ArgumentList(in ArgumentList): void - - - sc_check_get_Method(in Menge, in String, in boolean, in Hashtable, in Hashtable): void - - - add_Expr(in Expr): void - - - sc_check_uebergabe(in Menge, in Menge, in boolean, in int, in Hashtable, in Hashtable): void - - - get_Name(): String - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - sc_init_extended_fcts(in Menge, in Menge, in String, in String, in boolean): void - - - set_Receiver(in Receiver): void - - - sc_check_method_kleiner(in Menge, in String, in String, in boolean): boolean - - MethodCall - - - - - - - - - - expr1: Expr - - - expr2: Expr - - - set_Expr(in Expr, in Expr): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - get_Name(): String - - Assign - - - - - - - - - - type: Type - - - get_Type(): String - - ExprStmt - - - - - - - - - - type: Type - - - expr: Expr - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - get_Name(): String - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - set_Expr(in Expr): void - - - set_Type(in Type): void - - CastExpr - - - - - - - - - - plus: UnaryPlus - - - expr: Expr - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - set_Expr(in Expr): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - set_UnaryPlus(in UnaryPlus): void - - - get_Name(): String - - PositivExpr - - - - - - - - - - string: String - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - StringLiteral(): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - set_String(in String): void - - - get_Name(): String - - StringLiteral - - - - - - - - - - else_block: Statement - - - hamaDebug: boolean - - - expr: Expr - - - then_block: Statement - - - set_Expr(in Expr): void - - - set_Then_block(in Statement): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - set_Else_block(in Statement): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - if_codegen(in ClassFile, in CodeAttribute, in boolean, in Menge): void - - IfStmt - - - - - - - - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - get_Name(): String - - - Null(): void - - Null - - - - - - - BinaryExpr - - - - - - - - - - op: Operator - - - expr2: Expr - - - expr1: Expr - - - not_codegen(in ClassFile, in CodeAttribute, in Menge): void - - - neg_codegen(in ClassFile, in CodeAttribute, in Menge): void - - - set_Expr2(in Expr): void - - - get_Name(): String - - - get_Operator(): Operator - - - get_Expr2(): Expr - - - set_Expr1(in Expr): void - - - type_check(in CodeAttribute): boolean - - - get_Expr1(): Expr - - - set_Operator(in Operator): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - Binary - - - - - - - - - - neg: UnaryMinus - - - expr: Expr - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - set_UnaryMinus(in UnaryMinus): void - - - set_Expr(in Expr): void - - - get_Name(): String - - - neg_codegen(in ClassFile, in CodeAttribute, in Menge): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - NegativeExpr - - - - - - - - - - usedid: UsedId - - - get_Name(): String - - - get_Name_Menge(): Menge - - - get_UsedId(): UsedId - - - get_Type_Menge(): Menge - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - set_Type(in Type): void - - - set_UsedId(in UsedId): void - - Expr - - - - - - - - - - expr: Menge - - - type: Type - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - get_codegen_Array_Type(): int - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - get_Name(): String - - NewArray - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - UnaryExpr - - - - - - - - - - Int: int - - - IntLiteral(): void - - - get_Name(): String - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - set_Int(in int): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - IntLiteral - - - - - - - - - - retexpr: Expr - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - set_ReturnExpr(in Expr): void - - - get_Type(): String - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - Return - - - - - - - - - - arglist: ArgumentList - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - set_UsedId(in UsedId): void - - - set_ArgumentList(in ArgumentList): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - get_Name(): String - - NewClass - - - - - - - - - - not: UnaryNot - - - expr: Expr - - - get_Name(): String - - - set_UnaryNot(in UnaryNot): void - - - not_codegen(in ClassFile, in CodeAttribute, in Menge): void - - - get_Expr(): Expr - - - set_Expr(in Expr): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - NotExpr - - - - - - - - - - is_instance: boolean - - - reftype: RefType - - - expr: Expr - - - InstanceOf(): void - - - set_Type(in RefType): void - - - set_Expr(in Expr): void - - - get_Name(): String - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - InstanceOf - - - - - - - - - - statements: Menge - - - HashTabelleBlock: Hashtable - - - block_para: Hashtable - - - sc_meth_ret_type: String - - - HashTabelleKlasse: Hashtable - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - set_Statement(in Statement): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - get_Statement(): Menge - - - set_Statement_Menge(in Menge): void - - Block - - - - - - - - - - expr: Expr - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - get_Name(): String - - - set_Expr(in Expr): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - PreDecExpr - - - - - - - - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - EmptyStmt - - - - - - - - - - declid: Menge - - - type: Type - - - paralist: Menge - - - parahash: Hashtable - - - sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void - - - is_declared(in Type, in Menge): void - - - codegen(in ClassFile, in CodeAttribute, in Menge): void - - - check_anz(in Type, in Menge, in Menge): void - - - set_ParaList(in Menge): void - - - set_Type(in Type): void - - - set_DeclId(in DeclId): void - - - get_Name(): String - - LocalVarDecl - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + expr: Expr + + + set_Expr(in Expr): void + + + get_Name(): String + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + PreIncExpr + + + + + + + + + + expr: Expr + + + get_Name(): String + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + set_Expr(in Expr): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + PostIncExpr + + + + + + + + + + arglist: ArgumentList + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + set_ArgumentList(in ArgumentList): void + + + get_Name(): String + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + set_UsedId(in UsedId): void + + This + + + + + + + + + + Char: char + + + CharLiteral(): void + + + set_Char(in char): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + get_Name(): String + + CharLiteral + + + + + + + + + + type: String + + + expr: Expr + + + usedid: UsedId + + + get_codegen_UsedId(): String + + + InstVar(in String, in String): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + get_Name(): String + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + InstVar + + + + + + + + + + get_Name(): String + + + set_UsedId(in UsedId): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + LocalOrFieldVar(in String): void + + + LocalOrFieldVar(): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + LocalOrFieldVar + + + + + + + + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + print_rec(in String, in Menge): void + + + print_rec(in Hashtable): void + + + print_rec(in Menge): void + + + print_rec(in String, in Hashtable): void + + Statement + + + + + + + Literal + + + + + + + + + + loop_block: Statement + + + expr: Expr + + + set_Loop_block(in Statement): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + set_Expr(in Expr): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + loop_codegen(in ClassFile, in CodeAttribute, in int, in boolean, in Menge): void + + WhileStmt + + + + + + + + + + expr: Expr + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + set_Expr(in Expr): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + get_Name(): String + + PostDecExpr + + + + + + + + + + Bool: boolean + + + BoolLiteral(): void + + + get_Name(): String + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + set_Bool(in boolean): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + BoolLiteral + + + + + + + + + + called_method: Method + + + exprtypes: Menge + + + receiver: Receiver + + + class_name: String + + + finde_method: Menge + + + arglist: ArgumentList + + + counter: int + + + uebernachdurch: Hashtable + + + set_UsedId(in UsedId): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + set_Expr_Menge(in Menge): void + + + set_ArgumentList(in ArgumentList): void + + + sc_check_get_Method(in Menge, in String, in boolean, in Hashtable, in Hashtable): void + + + add_Expr(in Expr): void + + + sc_check_uebergabe(in Menge, in Menge, in boolean, in int, in Hashtable, in Hashtable): void + + + get_Name(): String + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + sc_init_extended_fcts(in Menge, in Menge, in String, in String, in boolean): void + + + set_Receiver(in Receiver): void + + + sc_check_method_kleiner(in Menge, in String, in String, in boolean): boolean + + MethodCall + + + + + + + + + + expr1: Expr + + + expr2: Expr + + + set_Expr(in Expr, in Expr): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + get_Name(): String + + Assign + + + + + + + + + + type: Type + + + get_Type(): String + + ExprStmt + + + + + + + + + + type: Type + + + expr: Expr + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + get_Name(): String + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + set_Expr(in Expr): void + + + set_Type(in Type): void + + CastExpr + + + + + + + + + + plus: UnaryPlus + + + expr: Expr + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + set_Expr(in Expr): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + set_UnaryPlus(in UnaryPlus): void + + + get_Name(): String + + PositivExpr + + + + + + + + + + string: String + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + StringLiteral(): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + set_String(in String): void + + + get_Name(): String + + StringLiteral + + + + + + + + + + else_block: Statement + + + hamaDebug: boolean + + + expr: Expr + + + then_block: Statement + + + set_Expr(in Expr): void + + + set_Then_block(in Statement): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + set_Else_block(in Statement): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + if_codegen(in ClassFile, in CodeAttribute, in boolean, in Menge): void + + IfStmt + + + + + + + + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + get_Name(): String + + + Null(): void + + Null + + + + + + + BinaryExpr + + + + + + + + + + op: Operator + + + expr2: Expr + + + expr1: Expr + + + not_codegen(in ClassFile, in CodeAttribute, in Menge): void + + + neg_codegen(in ClassFile, in CodeAttribute, in Menge): void + + + set_Expr2(in Expr): void + + + get_Name(): String + + + get_Operator(): Operator + + + get_Expr2(): Expr + + + set_Expr1(in Expr): void + + + type_check(in CodeAttribute): boolean + + + get_Expr1(): Expr + + + set_Operator(in Operator): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + Binary + + + + + + + + + + neg: UnaryMinus + + + expr: Expr + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + set_UnaryMinus(in UnaryMinus): void + + + set_Expr(in Expr): void + + + get_Name(): String + + + neg_codegen(in ClassFile, in CodeAttribute, in Menge): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + NegativeExpr + + + + + + + + + + usedid: UsedId + + + get_Name(): String + + + get_Name_Menge(): Menge + + + get_UsedId(): UsedId + + + get_Type_Menge(): Menge + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + set_Type(in Type): void + + + set_UsedId(in UsedId): void + + Expr + + + + + + + + + + expr: Menge + + + type: Type + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + get_codegen_Array_Type(): int + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + get_Name(): String + + NewArray + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + UnaryExpr + + + + + + + + + + Int: int + + + IntLiteral(): void + + + get_Name(): String + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + set_Int(in int): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + IntLiteral + + + + + + + + + + retexpr: Expr + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + set_ReturnExpr(in Expr): void + + + get_Type(): String + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + Return + + + + + + + + + + arglist: ArgumentList + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + set_UsedId(in UsedId): void + + + set_ArgumentList(in ArgumentList): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + get_Name(): String + + NewClass + + + + + + + + + + not: UnaryNot + + + expr: Expr + + + get_Name(): String + + + set_UnaryNot(in UnaryNot): void + + + not_codegen(in ClassFile, in CodeAttribute, in Menge): void + + + get_Expr(): Expr + + + set_Expr(in Expr): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + NotExpr + + + + + + + + + + is_instance: boolean + + + reftype: RefType + + + expr: Expr + + + InstanceOf(): void + + + set_Type(in RefType): void + + + set_Expr(in Expr): void + + + get_Name(): String + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + InstanceOf + + + + + + + + + + statements: Menge + + + HashTabelleBlock: Hashtable + + + block_para: Hashtable + + + sc_meth_ret_type: String + + + HashTabelleKlasse: Hashtable + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + set_Statement(in Statement): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + get_Statement(): Menge + + + set_Statement_Menge(in Menge): void + + Block + + + + + + + + + + expr: Expr + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + get_Name(): String + + + set_Expr(in Expr): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + PreDecExpr + + + + + + + + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + EmptyStmt + + + + + + + + + + declid: Menge + + + type: Type + + + paralist: Menge + + + parahash: Hashtable + + + sc_check(in Menge, in Hashtable, in Hashtable, in boolean, in Hashtable, in Hashtable): void + + + is_declared(in Type, in Menge): void + + + codegen(in ClassFile, in CodeAttribute, in Menge): void + + + check_anz(in Type, in Menge, in Menge): void + + + set_ParaList(in Menge): void + + + set_Type(in Type): void + + + set_DeclId(in DeclId): void + + + get_Name(): String + + LocalVarDecl + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/OldStuff/Statement.ucd b/doc/OldStuff/Statement.ucd index 1136e26ec..9e2b116f5 100755 --- a/doc/OldStuff/Statement.ucd +++ b/doc/OldStuff/Statement.ucd @@ -1,623 +1,623 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericGeneratorResultsForAllMethods.java b/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericGeneratorResultsForAllMethods.java index bd3d224d8..9798ad7f4 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericGeneratorResultsForAllMethods.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericGeneratorResultsForAllMethods.java @@ -3,8 +3,11 @@ */ package de.dhbwstuttgart.bytecode.simplifyRes; +import java.util.Collections; import java.util.List; +import com.google.common.collect.Collections2; + /** * @author fayez * @@ -12,7 +15,9 @@ import java.util.List; public class GenericGeneratorResultsForAllMethods { private final List methodsAndConstraints; - + public GenericGeneratorResultsForAllMethods() { + this(Collections.emptyList()); + } /** * @param methodsAndConstraints */ diff --git a/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericGenratorResultForSourceFile.java b/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericGenratorResultForSourceFile.java index e1928893d..f311899e7 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericGenratorResultForSourceFile.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericGenratorResultForSourceFile.java @@ -40,9 +40,11 @@ public class GenericGenratorResultForSourceFile { public GenericsGeneratorResultForClass getSimplifyResultsByName(String pkgName, String name) { if (this.pkgName.equals(pkgName)) { - return genericGeneratorResultForAllClasses.stream().filter(sr -> sr.getClassName().equals(name)).findAny() - .orElseThrow(() -> new NoSuchElementException( - "Simplify results for the class " + pkgName + "." + name + " are not found")); + return genericGeneratorResultForAllClasses + .stream() + .filter(sr -> sr.getClassName().equals(name)) + .findAny() + .orElse(new GenericsGeneratorResultForClass(name)); } throw new NoSuchElementException("Simplify results for the class " + pkgName + "." + name + " are not found"); } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericsGeneratorResultForClass.java b/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericsGeneratorResultForClass.java index 5b53efcc7..a02cd1625 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericsGeneratorResultForClass.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericsGeneratorResultForClass.java @@ -3,6 +3,7 @@ */ package de.dhbwstuttgart.bytecode.simplifyRes; +import java.util.Collections; import java.util.List; /** @@ -14,6 +15,9 @@ public class GenericsGeneratorResultForClass { private final List classConstraints; private final GenericGeneratorResultsForAllMethods methodsAndTheirConstraints; + public GenericsGeneratorResultForClass(String className) { + this(className, Collections.emptyList(), new GenericGeneratorResultsForAllMethods()); + } /** * @param className * @param classConstraints @@ -52,6 +56,9 @@ public class GenericsGeneratorResultForClass { .anyMatch(i -> i.equals(id)); } + + + public List getMethodConstraintsByID(String id) { return methodsAndTheirConstraints.getMethodsAndConstraints().stream().filter(mc -> mc.getMethodID().equals(id)) .findFirst().get().getConstraints(); diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 5650b8ef4..c4d0407a7 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -59,43 +59,64 @@ import org.apache.commons.io.output.NullOutputStream; public class JavaTXCompiler { - final CompilationEnvironment environment; - Boolean resultmodel = true; - public final Map sourceFiles = new HashMap<>(); - Boolean log = true; // gibt an ob ein Log-File nach - // System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden - // soll? - public volatile UnifyTaskModel usedTasks = new UnifyTaskModel(); + public static JavaTXCompiler INSTANCE; + final CompilationEnvironment environment; + Boolean resultmodel = true; + public final Map sourceFiles = new HashMap<>(); + Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll? + public volatile UnifyTaskModel usedTasks = new UnifyTaskModel(); + + /** + * Äußerste Liste der Source-Files. + * Danach Liste der Klassen in Source File. + * Danach Map Klassenname + */ + private List>> simplifyResultsSF = new ArrayList<>(); + + public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException { + this(Arrays.asList(sourceFile)); + INSTANCE = this; + } - public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException { - this(Arrays.asList(sourceFile)); - } + public JavaTXCompiler(File sourceFile, Boolean log) throws IOException, ClassNotFoundException { + this(sourceFile); + this.log = log; + INSTANCE = this; + } + + public JavaTXCompiler(List sources) throws IOException, ClassNotFoundException { + environment = new CompilationEnvironment(sources); + for (File s : sources) { + sourceFiles.put(s, parse(s)); + } + INSTANCE = this; + } - public JavaTXCompiler(File sourceFile, Boolean log) throws IOException, ClassNotFoundException { - this(sourceFile); - this.log = log; - } + public ConstraintSet getConstraints() throws ClassNotFoundException { + List allClasses = new ArrayList<>();//environment.getAllAvailableClasses(); + for (SourceFile sf : sourceFiles.values()) { + allClasses.addAll(sf.getClasses()); + } + List importedClasses = new ArrayList<>(); + //Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC + for (File forSourceFile : sourceFiles.keySet()) + for (JavaClassName name : sourceFiles.get(forSourceFile).getImports()) { + //TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet + ClassOrInterface importedClass = ASTFactory.createClass( + ClassLoader.getSystemClassLoader().loadClass(name.toString())); + importedClasses.add(importedClass); + } + allClasses.addAll(importedClasses); - public JavaTXCompiler(List sources) throws IOException, ClassNotFoundException { - environment = new CompilationEnvironment(sources); - for (File s : sources) { - sourceFiles.put(s, parse(s)); - } - } + return new TYPE(sourceFiles.values(), allClasses).getConstraints(); + } - public ConstraintSet getConstraints() throws ClassNotFoundException { - List allClasses = new ArrayList<>();// environment.getAllAvailableClasses(); - for (SourceFile sf : sourceFiles.values()) { - allClasses.addAll(sf.getClasses()); - } - List importedClasses = new ArrayList<>(); - // Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC - for (File forSourceFile : sourceFiles.keySet()) - for (JavaClassName name : sourceFiles.get(forSourceFile).getImports()) { - // TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet - ClassOrInterface importedClass = ASTFactory - .createClass(ClassLoader.getSystemClassLoader().loadClass(name.toString())); - importedClasses.add(importedClass); + public List getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException { + //PL 2018-09-18: List durch Set ersetzt, damit die Klassen nur einmal hinzugefuegt werden + //List allClasses = new ArrayList<>();//environment.getAllAvailableClasses(); + Set allClasses = new HashSet<>(); + + /* PL 2018-09-19 geloescht werden bereits in typeInference hinzugefuegt } allClasses.addAll(importedClasses); @@ -711,6 +732,20 @@ public class JavaTXCompiler { return ret; } + public void generateBytecodForFile(String path, HashMap classFiles, SourceFile sf, + List typeinferenceResult) throws IOException { + try { + List genericResults = getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult); + BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult, genericResults, sf,path); + bytecodeGen.visit(sf); + this.writeClassFile(bytecodeGen.getClassFiles(), path); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public List getGeneratedGenericResultsForAllSourceFiles() throws ClassNotFoundException { List result = new ArrayList<>(); diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java b/src/main/java/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java index 6a2646845..426b57f35 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java @@ -2,6 +2,10 @@ package de.dhbwstuttgart.syntaxtree; import org.antlr.v4.runtime.Token; +import com.google.common.collect.Lists; + +import de.dhbwstuttgart.parser.NullToken; + import java.util.*; @@ -15,11 +19,21 @@ public class GenericDeclarationList extends SyntaxTreeNode implements Iterable gtvs = new ArrayList<>(); - - public GenericDeclarationList(List values, Token endOffset) { + + @SuppressWarnings("unchecked") + public GenericDeclarationList(Iterable values, Token endOffset) { + super(endOffset); + gtvs = isListOfGenericTypeVar(values) ? (List)values : Lists.newArrayList(values); + this.offsetOfLastElement = endOffset; + } + + public GenericDeclarationList(ArrayList values, Token endOffset) { super(endOffset); gtvs = values; - this.offsetOfLastElement = endOffset; + this.offsetOfLastElement = endOffset; } + + private boolean isListOfGenericTypeVar(Iterable values) { + return values instanceof List && ((List)values).size() > 0 && ((List)values).get(0) instanceof GenericTypeVar; } @Override diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/NewArray.java b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/NewArray.java index 0f6991614..14c54d8c0 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/NewArray.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/NewArray.java @@ -1,24 +1,24 @@ -package de.dhbwstuttgart.syntaxtree.statement; -import java.util.List; - -import de.dhbwstuttgart.syntaxtree.StatementVisitor; -import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; -import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation; -import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; -import de.dhbwstuttgart.exceptions.NotImplementedException; - - -public class NewArray extends Expression -{ - public NewArray(int offset,int variableLength) - { - super(null,null); - } - private RefTypeOrTPHOrWildcardOrGeneric type; - public List expr; - - @Override - public void accept(StatementVisitor visitor) { - visitor.visit(this); - } -} +package de.dhbwstuttgart.syntaxtree.statement; +import java.util.List; + +import de.dhbwstuttgart.syntaxtree.StatementVisitor; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; +import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation; +import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; +import de.dhbwstuttgart.exceptions.NotImplementedException; + + +public class NewArray extends Expression +{ + public NewArray(int offset,int variableLength) + { + super(null,null); + } + private RefTypeOrTPHOrWildcardOrGeneric type; + public List expr; + + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } +} diff --git a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java index 3fee03f6e..7f039bdc6 100644 --- a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java +++ b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java @@ -1,11 +1,37 @@ package de.dhbwstuttgart.typedeployment; +import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; +import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor; +import de.dhbwstuttgart.bytecode.simplifyRes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.simplifyRes.GenericsGeneratorResult; +import de.dhbwstuttgart.bytecode.simplifyRes.GenericsGeneratorResultForClass; +import de.dhbwstuttgart.bytecode.utilities.MethodUtility; +import de.dhbwstuttgart.bytecode.utilities.Resolver; +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.syntaxtree.*; +import de.dhbwstuttgart.syntaxtree.statement.NewArray; import de.dhbwstuttgart.syntaxtree.type.*; import de.dhbwstuttgart.typeinference.result.*; -import org.antlr.v4.runtime.Token; +import org.antlr.v4.parse.ANTLRParser.action_return; +import org.antlr.v4.parse.ANTLRParser.block_return; +import org.antlr.v4.parse.ANTLRParser.labeledAlt_return; +import org.antlr.v4.parse.ANTLRParser.parserRule_return; +import org.antlr.v4.runtime.Token; +import org.objectweb.asm.Type; +import org.stringtemplate.v4.compiler.STParser.ifstat_return; + +import java.io.File; +import java.io.IOException; +import java.io.Serializable; import java.util.*; +import java.util.Map.Entry; +import java.util.stream.Collectors; + +import javax.print.DocFlavor.STRING; +import javax.security.auth.kerberos.KerberosKey; /** * TODO: @@ -29,62 +55,90 @@ public class TypeInsertFactory { public static TypeInsert createInsertPoints(RefTypeOrTPHOrWildcardOrGeneric type, Token offset, ClassOrInterface cl, Method m, ResultSet resultSet) { - ResolvedType resolvedType = resultSet.resolveType(type); - TypeInsertPoint insertPoint = new TypeInsertPoint(offset, - new TypeToInsertString(resolvedType.resolvedType).insert); - return new TypeInsert(insertPoint, new HashSet<>(), resolvedType.getResultPair()); + + try { + ResolvedType resolvedType = resultSet.resolveType(type); + TypeInsertPoint insertPoint = new TypeInsertPoint(offset, + new TypeToInsertString(resolvedType.resolvedType).insert); + List simplifyResults = JavaTXCompiler.INSTANCE.getGeneratedGenericResultsForAllSourceFiles(); + for (GenericGenratorResultForSourceFile simplifyResultsEntries : simplifyResults) { + GenericsGeneratorResultForClass genericResultsForClass = simplifyResultsEntries.getSimplifyResultsByName("", cl.getClassName().toString()); + return new TypeInsert(insertPoint, createGenericInsert(genericResultsForClass, cl, m, resultSet), resolvedType.getResultPair()); + } + + return new TypeInsert(insertPoint, new HashSet<>(), resolvedType.getResultPair()); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + return null; + } } - private static TypeInsertPoint createGenericInsert(Set toInsert, ClassOrInterface cl, Method m){ - //Momentan wird Methode ignoriert. Parameter werden immer als Klassenparameter angefügt: - //Offset zum Einstzen bestimmen: - Token offset; - String insert = ""; - String end; - if(cl.getGenerics().iterator().hasNext()){ - //offset = cl.getGenerics().iterator().next().getOffset(); - offset = cl.getGenerics().getOffset(); - end=","; - }else{ - offset = cl.getGenerics().getOffset(); - insert += "<"; - end = ">"; + private static synchronized Set createGenericInsert(GenericsGeneratorResultForClass genericResult, ClassOrInterface cl, Method m, ResultSet resultSet){ + Set result = createGenericClassInserts(genericResult, cl); + + for (Method method : cl.getMethods()) { + Resolver resolver = new Resolver(resultSet); + List methodConstraints = genericResult.getMethodConstraintsByID(MethodUtility.createID(resolver, method)); + createMethodConstraints(method, methodConstraints); } - - //Alle einzusetzenden Generics und deren Bounds bestimmen: - HashMap> genericsAndBounds = new HashMap<>(); - for(GenericInsertPair p : toInsert){ - if(!genericsAndBounds.containsKey(p.TA1)){ - genericsAndBounds.put((TypePlaceholder) p.TA1, new HashSet<>()); - } - if(p.TA2 != null){ - genericsAndBounds.get(p.TA1).add((TypePlaceholder) p.TA2); - if(!genericsAndBounds.containsKey(p.TA2)){ - genericsAndBounds.put((TypePlaceholder) p.TA2, new HashSet<>()); - } - } - } - - //String zum Einsetzen (Generics mit bounds) generieren: - Iterator it = genericsAndBounds.keySet().iterator(); - if(! it.hasNext())return new TypeInsertPoint(offset, ""); - while(it.hasNext()){ - TypePlaceholder tph = it.next(); - insert += tph.getName(); - Set bounds = genericsAndBounds.get(tph); - if(bounds.size() > 0){ - insert += " extends "; - Iterator boundIt = bounds.iterator(); - while(boundIt.hasNext()){ - TypePlaceholder bound = boundIt.next(); - insert += bound.getName(); - if(boundIt.hasNext())insert += " & "; - } - } - if(it.hasNext())insert+=","; - } - return new TypeInsertPoint(offset, insert + end); + + return result; } + + private static Set createMethodConstraints(Method method, List constraints) { + Set result = new HashSet<>(); + Token offset = new GenericDeclarationList(method.getGenerics(), new NullToken()).getOffset(); + + if (constraints.size() == 0) { + result.add(new TypeInsertPoint(offset, "")); + return result; + } + + String insert = " <"; + + for (GenericsGeneratorResult genericInsertConstraint : constraints) { + if (genericInsertConstraint.getConstraint().getRight().equals(Type.getInternalName(Object.class))) { + insert += genericInsertConstraint.getConstraint().getLeft(); + } else { + insert += genericInsertConstraint.getConstraint().getLeft() + " extends " + genericInsertConstraint.getConstraint().getRight() + ", "; + } + } + + insert = insert.substring(0, insert.length() -2); + insert += ">"; + + result.add(new TypeInsertPoint(offset, insert)); + return result; + } + + private static Set createGenericClassInserts(GenericsGeneratorResultForClass genericResult, ClassOrInterface cl) { + Set result = new HashSet<>(); + Token offset = cl.getGenerics().getOffset(); + + List classConstraints = genericResult.getClassConstraints(); + + if (classConstraints.size() == 0) { + result.add(new TypeInsertPoint(offset, "")); + return result; + } + + String insert = " <"; + + for (GenericsGeneratorResult genericInsertConstraint : classConstraints) { + if (genericInsertConstraint.getConstraint().getRight().equals(Type.getInternalName(Object.class))) { + insert += genericInsertConstraint.getConstraint().getLeft(); + } else { + insert += genericInsertConstraint.getConstraint().getLeft() + " extends " + genericInsertConstraint.getConstraint().getRight() + ", "; + } + } + + insert = insert.substring(0, insert.length() -2); + insert += ">"; + + result.add(new TypeInsertPoint(offset, insert)); + + return result; + } } class TypeToInsertString implements ResultSetVisitor{ diff --git a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java index 6ccf5620e..9e5ba545a 100644 --- a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java +++ b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java @@ -1,73 +1,73 @@ -package de.dhbwstuttgart.typedeployment; - -import de.dhbwstuttgart.exceptions.NotImplementedException; -import de.dhbwstuttgart.syntaxtree.*; -import de.dhbwstuttgart.syntaxtree.statement.JavaInternalExpression; -import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression; -import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; -import de.dhbwstuttgart.typeinference.result.ResultSet; - -import java.util.HashSet; -import java.util.Set; - -public class TypeInsertPlacer extends AbstractASTWalker{ - Set inserts = new HashSet<>(); - private ResultSet withResults; - - public Set getTypeInserts(SourceFile forSourceFile, ResultSet withResults){ - this.withResults = withResults; - forSourceFile.accept(this); - return inserts; - } - - @Override - public void visit(ClassOrInterface classOrInterface) { - TypeInsertPlacerClass cl = new TypeInsertPlacerClass(classOrInterface, withResults); - this.inserts.addAll(cl.inserts); - } -} - -class TypeInsertPlacerClass extends AbstractASTWalker{ - protected final ResultSet results; - protected final ClassOrInterface cl; - public final Set inserts = new HashSet<>(); - private Method method; - - TypeInsertPlacerClass(ClassOrInterface forClass, ResultSet withResults){ - this.cl = forClass; - this.method = null; - this.results = withResults; - forClass.accept(this); - } - - @Override - public void visit(Method method) { - this.method = method; - if(method.getReturnType() instanceof TypePlaceholder) - inserts.add(TypeInsertFactory.createInsertPoints( - method.getReturnType(), method.getReturnType().getOffset(), cl, method, results)); - super.visit(method); - } - - @Override - public void visit(Field field) { - if(field.getType() instanceof TypePlaceholder){ - inserts.add(TypeInsertFactory.createInsertPoints( - field.getType(), field.getType().getOffset(), cl, method, results)); - } - super.visit(field); - } - - @Override - public void visit(FormalParameter param) { - if(param.getType() instanceof TypePlaceholder) - inserts.add(TypeInsertFactory.createInsertPoints( - param.getType(), param.getType().getOffset(), cl, method, results)); - super.visit(param); - } - - @Override - public void visit(LambdaExpression lambdaExpression) { - //Lambda-Ausdrücke brauchen keine Typeinsetzungen - } -} +package de.dhbwstuttgart.typedeployment; + +import de.dhbwstuttgart.exceptions.NotImplementedException; +import de.dhbwstuttgart.syntaxtree.*; +import de.dhbwstuttgart.syntaxtree.statement.JavaInternalExpression; +import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression; +import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; +import de.dhbwstuttgart.typeinference.result.ResultSet; + +import java.util.HashSet; +import java.util.Set; + +public class TypeInsertPlacer extends AbstractASTWalker{ + Set inserts = new HashSet<>(); + private ResultSet withResults; + + public Set getTypeInserts(SourceFile forSourceFile, ResultSet withResults){ + this.withResults = withResults; + forSourceFile.accept(this); + return inserts; + } + + @Override + public void visit(ClassOrInterface classOrInterface) { + TypeInsertPlacerClass cl = new TypeInsertPlacerClass(classOrInterface, withResults); + this.inserts.addAll(cl.inserts); + } +} + +class TypeInsertPlacerClass extends AbstractASTWalker{ + protected final ResultSet results; + protected final ClassOrInterface cl; + public final Set inserts = new HashSet<>(); + private Method method; + + TypeInsertPlacerClass(ClassOrInterface forClass, ResultSet withResults){ + this.cl = forClass; + this.method = null; + this.results = withResults; + forClass.accept(this); + } + + @Override + public void visit(Method method) { + this.method = method; + if(method.getReturnType() instanceof TypePlaceholder) + inserts.add(TypeInsertFactory.createInsertPoints( + method.getReturnType(), method.getReturnType().getOffset(), cl, method, results)); + super.visit(method); + } + + @Override + public void visit(Field field) { + if(field.getType() instanceof TypePlaceholder){ + inserts.add(TypeInsertFactory.createInsertPoints( + field.getType(), field.getType().getOffset(), cl, method, results)); + } + super.visit(field); + } + + @Override + public void visit(FormalParameter param) { + if(param.getType() instanceof TypePlaceholder) + inserts.add(TypeInsertFactory.createInsertPoints( + param.getType(), param.getType().getOffset(), cl, method, results)); + super.visit(param); + } + + @Override + public void visit(LambdaExpression lambdaExpression) { + //Lambda-Ausdrücke brauchen keine Typeinsetzungen + } +} diff --git a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPoint.java b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPoint.java index 4c495d653..bde45df12 100644 --- a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPoint.java +++ b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPoint.java @@ -1,59 +1,59 @@ -package de.dhbwstuttgart.typedeployment; - -import org.antlr.v4.runtime.Token; - -import de.dhbwstuttgart.typeinference.unify.model.ReferenceType; - -import java.time.OffsetDateTime; -import java.util.List; -import java.util.stream.Collectors; - -public class TypeInsertPoint { - public Token point; - private String insertString; - private int extraOffset = 0; - - public TypeInsertPoint(Token point, String toInsert){ - this.point = point; - this.insertString = (toInsert.endsWith(" ")) ? toInsert : toInsert + " " ; - } - - public String insert(String intoSource, List additionalOffset){ - int offset = additionalOffset.stream().filter((token -> - //token.point.getLine() != point.getLine() && token.point.getCharPositionInLine() <= point.getCharPositionInLine())) - token.point.getStartIndex() <= point.getStartIndex())) - .mapToInt((typeInsertPoint -> typeInsertPoint.insertString.length())).sum(); - return new StringBuilder(intoSource).insert(point.getStartIndex()+offset+extraOffset, insertString).toString(); - } - - public String getInsertString() { - return insertString; - } - - public void addExtraOffset(int toAdd) { - this.extraOffset += toAdd; - } - - public int getPositionInCode() { - return point.getStartIndex() + extraOffset; - } - - /* PL 2018-06-19 - * Zwei TypeInsertPoint's sind gleich, wenn ihre point's gleich sind - * eingefuegt damit man TypeReplaceMarker vergleichen kann - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object obj) { - if(!(obj instanceof TypeInsertPoint)) { - return false; - } - else { - return ((TypeInsertPoint)obj).point.equals(this.point) && - ((TypeInsertPoint)obj).insertString.equals(this.insertString); - } - } - - public String toString() { - return point.toString() + " " + insertString.toString(); - } -} +package de.dhbwstuttgart.typedeployment; + +import org.antlr.v4.runtime.Token; + +import de.dhbwstuttgart.typeinference.unify.model.ReferenceType; + +import java.time.OffsetDateTime; +import java.util.List; +import java.util.stream.Collectors; + +public class TypeInsertPoint { + public Token point; + private String insertString; + private int extraOffset = 0; + + public TypeInsertPoint(Token point, String toInsert){ + this.point = point; + this.insertString = (toInsert.endsWith(" ")) ? toInsert : toInsert + " " ; + } + + public String insert(String intoSource, List additionalOffset){ + int offset = additionalOffset.stream().filter((token -> + //token.point.getLine() != point.getLine() && token.point.getCharPositionInLine() <= point.getCharPositionInLine())) + token.point.getStartIndex() <= point.getStartIndex())) + .mapToInt((typeInsertPoint -> typeInsertPoint.insertString.length())).sum(); + return new StringBuilder(intoSource).insert(point.getStartIndex()+offset+extraOffset, insertString).toString(); + } + + public String getInsertString() { + return insertString; + } + + public void addExtraOffset(int toAdd) { + this.extraOffset += toAdd; + } + + public int getPositionInCode() { + return point.getStartIndex() + extraOffset; + } + + /* PL 2018-06-19 + * Zwei TypeInsertPoint's sind gleich, wenn ihre point's gleich sind + * eingefuegt damit man TypeReplaceMarker vergleichen kann + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object obj) { + if(!(obj instanceof TypeInsertPoint)) { + return false; + } + else { + return ((TypeInsertPoint)obj).point.equals(this.point) && + ((TypeInsertPoint)obj).insertString.equals(this.insertString); + } + } + + public String toString() { + return point.toString() + " " + insertString.toString(); + } +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/result/ResultPair.java b/src/main/java/de/dhbwstuttgart/typeinference/result/ResultPair.java index 552bf4948..490e6f95a 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/result/ResultPair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/result/ResultPair.java @@ -1,62 +1,62 @@ -package de.dhbwstuttgart.typeinference.result; - -import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; - -/** - * Paare, welche das Unifikationsergebnis darstellen - */ -public abstract class ResultPair { - private final A left; - private final B right; - - public abstract void accept(ResultPairVisitor visitor); - - public ResultPair(A left, B right){ - this.left = left; - this.right = right; - } - - public A getLeft() { - return left; - } - - public B getRight() { - return right; - } - - public String toString() { - return "(" + left.toString() + ", " + right.toString() + ")"; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((left == null) ? 0 : left.getOffset().hashCode()); - result = prime * result + ((right == null) ? 0 : right.getOffset().hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ResultPair other = (ResultPair) obj; - if (left == null) { - if (other.left != null) - return false; - } else if (!left.getOffset().equals(other.left.getOffset())) - return false; - if (right == null) { - if (other.right != null) - return false; - } else if (!right.getOffset().equals(other.right.getOffset())) - return false; - return true; - } - -} +package de.dhbwstuttgart.typeinference.result; + +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; + +/** + * Paare, welche das Unifikationsergebnis darstellen + */ +public abstract class ResultPair { + private final A left; + private final B right; + + public abstract void accept(ResultPairVisitor visitor); + + public ResultPair(A left, B right){ + this.left = left; + this.right = right; + } + + public A getLeft() { + return left; + } + + public B getRight() { + return right; + } + + public String toString() { + return "(" + left.toString() + ", " + right.toString() + ")"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((left == null) ? 0 : left.getOffset().hashCode()); + result = prime * result + ((right == null) ? 0 : right.getOffset().hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ResultPair other = (ResultPair) obj; + if (left == null) { + if (other.left != null) + return false; + } else if (!left.getOffset().equals(other.left.getOffset())) + return false; + if (right == null) { + if (other.right != null) + return false; + } else if (!right.getOffset().equals(other.right.getOffset())) + return false; + return true; + } + +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java b/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java index f508fe345..a46b9ed2c 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java @@ -1,309 +1,309 @@ -package de.dhbwstuttgart.typeinference.result; - -import java.util.HashSet; -import java.util.Set; - -import de.dhbwstuttgart.exceptions.NotImplementedException; -import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType; -import de.dhbwstuttgart.syntaxtree.type.GenericRefType; -import de.dhbwstuttgart.syntaxtree.type.RefType; -import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; -import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType; -import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; - -@SuppressWarnings("rawtypes") -public class ResultSet { - - public final Set results; - public Set> genIns; - - public ResultSet(Set set){ - this.results = set; - this.genIns = new HashSet<>(); +package de.dhbwstuttgart.typeinference.result; + +import java.util.HashSet; +import java.util.Set; + +import de.dhbwstuttgart.exceptions.NotImplementedException; +import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType; +import de.dhbwstuttgart.syntaxtree.type.GenericRefType; +import de.dhbwstuttgart.syntaxtree.type.RefType; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; +import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType; +import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; + +@SuppressWarnings("rawtypes") +public class ResultSet { + + public final Set results; + public Set> genIns; + + public ResultSet(Set set){ + this.results = set; + this.genIns = new HashSet<>(); results.forEach(x -> { if (x instanceof PairTPHsmallerTPH) { this.genIns.add(x);}} ); - } - - public boolean contains(ResultPair toCheck) { - return this.results.contains(toCheck); - } - - public void remove(ResultPair toCheck) { - results.remove(toCheck); - } - - public ResolvedType resolveType(RefTypeOrTPHOrWildcardOrGeneric type) { - if(type instanceof TypePlaceholder) - return new Resolver(this).resolve((TypePlaceholder)type); - if(type instanceof GenericRefType)return new ResolvedType(type, new HashSet<>()); - if(type instanceof RefType) { - RelatedTypeWalker related = new RelatedTypeWalker(null, this); - type.accept(related); - return new ResolvedType(type, related.relatedTPHs); - } else { - throw new NotImplementedException(); - //return new ResolvedType(type,new HashSet<>()); - } - } - - public String toString() { - return results.toString(); - } - - @Override - public boolean equals(Object o) { - if (o instanceof ResultSet) { - ResultSet other = (ResultSet)o; - return this.results.equals(other.results); - } else { - return false; - } - } - - @Override - public int hashCode() { - return results.hashCode(); - } -} - -class Resolver implements ResultSetVisitor { - private final ResultSet result; - private TypePlaceholder toResolve; - private RefTypeOrTPHOrWildcardOrGeneric resolved; - private final Set additionalTPHs = new HashSet<>(); - private ResultPair currentPair; - - public Resolver(ResultSet resultPairs){ - this.result = resultPairs; - } - - public ResolvedType resolve(TypePlaceholder tph){ - toResolve = tph; - resolved = null; - System.out.println(tph.toString()); - for(ResultPair resultPair : result.results) { - if(resultPair instanceof PairTPHEqualTPH && ((PairTPHEqualTPH) resultPair).getLeft().equals(toResolve)){ - currentPair = resultPair; - return resolve(((PairTPHEqualTPH) resultPair).getRight()); - } - } - for(ResultPair resultPair : result.results){ - currentPair = resultPair; - resultPair.accept(this); - } - if(resolved==null){//TPH kommt nicht im Result vor: - resolved = tph; - } - - ResolvedType result = new ResolvedType(resolved, additionalTPHs);//resolved; - result.setResultPair(currentPair); - return result; - } - - @Override - public void visit(PairTPHsmallerTPH p) { - currentPair = p; - if(p.left.equals(toResolve)){ - additionalTPHs.add(new GenericInsertPair(p.left, p.right)); - additionalTPHs.addAll(new RelatedTypeWalker(p.right, result).relatedTPHs); - } - if(p.right.equals(toResolve)) - additionalTPHs.addAll(new RelatedTypeWalker(p.left, result).relatedTPHs); - } - - @Override - public void visit(PairTPHequalRefTypeOrWildcardType p) { - currentPair = p; - if(p.left.equals(toResolve)){ - resolved = p.right; - RelatedTypeWalker related = new RelatedTypeWalker(null, result); - p.right.accept(related); - additionalTPHs.addAll(related.relatedTPHs); - } - } - - @Override - public void visit(PairTPHEqualTPH p) { - //Do nothing. Dieser Fall wird in der resolve-Methode abgefangen - } - - @Override - public void visit(RefType refType) { - - } - - @Override - public void visit(GenericRefType genericRefType) { - - } - - @Override - public void visit(SuperWildcardType superWildcardType) { - - } - - @Override - public void visit(TypePlaceholder typePlaceholder) { - - } - - @Override - public void visit(ExtendsWildcardType extendsWildcardType) { - - } - - - -} - -/** - * Sucht aus dem Result Set den Sub/supertyp für einen TPH - */ -@SuppressWarnings("rawtypes") -class TPHResolver implements ResultSetVisitor { - - private final TypePlaceholder tph; - Set resolved = new HashSet<>(); - private final ResultSet resultSet; - - TPHResolver(TypePlaceholder tph, ResultSet resultSet){ - this.resultSet = resultSet; - this.tph = tph; - for(ResultPair p : resultSet.results){ - p.accept(this); - } - if(resolved.size() == 0){ - resolved.add(new GenericInsertPair(tph, null)); - } - } - - @Override - public void visit(PairTPHsmallerTPH p) { - if(p.left.equals(tph) || p.right.equals(tph)){ - resolved.add(new GenericInsertPair(p.left, p.right)); - } - } - - @Override - public void visit(PairTPHequalRefTypeOrWildcardType p) { - TypePlaceholder otherSide = null; - if(p.right.equals(tph)){ - otherSide = p.left; - } - if(otherSide != null){ - Set newResultSet = new HashSet<>(this.resultSet.results); - newResultSet.remove(p); - resolved.addAll(new TPHResolver(otherSide, new ResultSet(newResultSet)).resolved); - } - } - - @Override - public void visit(PairTPHEqualTPH p) { - //ignorieren. Wird vom Resolver behandelt - } - - @Override - public void visit(RefType refType) { - - } - - @Override - public void visit(GenericRefType genericRefType) { - - } - - @Override - public void visit(SuperWildcardType superWildcardType) { - - } - - @Override - public void visit(TypePlaceholder typePlaceholder) { - - } - - @Override - public void visit(ExtendsWildcardType extendsWildcardType) { - - } -} - -@SuppressWarnings("rawtypes") -class RelatedTypeWalker implements ResultSetVisitor { - - final Set relatedTPHs = new HashSet<>(); - private final TypePlaceholder toResolve; - private final ResultSet resultSet; - - /** - * Läuft über das resultSet und speichert alle TPHs, welche mit start in Verbindung stehen - * @param start - kann null sein, wenn der Walker für einen RefType benutzt wird - * @param resultSet - */ - RelatedTypeWalker(TypePlaceholder start, ResultSet resultSet){ - this.toResolve = start; - this.resultSet = resultSet; - int resolved = 0; - do{ - resolved = relatedTPHs.size(); - for(ResultPair p : resultSet.results){ - p.accept(this); - p.accept(this); - } - }while(resolved - relatedTPHs.size() > 0); - } - - @Override - public void visit(PairTPHsmallerTPH p) { - if(p.getRight().equals(toResolve)){ - relatedTPHs.addAll(new TPHResolver(p.right, resultSet).resolved); - //relatedTPHs.addAll(new RelatedTypeWalker(p.right, resultSet).relatedTPHs); - } - if(p.getLeft().equals(toResolve)){ - relatedTPHs.addAll(new TPHResolver(p.left, resultSet).resolved); - //relatedTPHs.addAll(new RelatedTypeWalker(p.left, resultSet).relatedTPHs); - } - } - - @Override - public void visit(PairTPHequalRefTypeOrWildcardType p) { - if(p.getLeft().equals(toResolve)){ - p.getRight().accept(this); - } - } - - @Override - public void visit(PairTPHEqualTPH p) { - //Kann ignoriert werden. Diese Fälle werden vom Resolver behandelt - } - - /* - Die folgenden Funktionen fügen alle TPHs an die relatedTPHs an, denen sie begegnen: - Das wird verwendet, wenn alle relatedTPHs aus den Parametern eines RefTypes angefügt werden sollen - */ - - @Override - public void visit(RefType refType) { - for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){ - param.accept(this); - } - } - - @Override - public void visit(SuperWildcardType superWildcardType) { - superWildcardType.getInnerType().accept(this); - } - - @Override - public void visit(TypePlaceholder typePlaceholder) { - relatedTPHs.addAll(new TPHResolver(typePlaceholder, resultSet).resolved); - } - - @Override - public void visit(ExtendsWildcardType extendsWildcardType) { - extendsWildcardType.getInnerType().accept(this); - } - - @Override - public void visit(GenericRefType genericRefType) { - } + } + + public boolean contains(ResultPair toCheck) { + return this.results.contains(toCheck); + } + + public void remove(ResultPair toCheck) { + results.remove(toCheck); + } + + public ResolvedType resolveType(RefTypeOrTPHOrWildcardOrGeneric type) { + if(type instanceof TypePlaceholder) + return new Resolver(this).resolve((TypePlaceholder)type); + if(type instanceof GenericRefType)return new ResolvedType(type, new HashSet<>()); + if(type instanceof RefType) { + RelatedTypeWalker related = new RelatedTypeWalker(null, this); + type.accept(related); + return new ResolvedType(type, related.relatedTPHs); + } else { + throw new NotImplementedException(); + //return new ResolvedType(type,new HashSet<>()); + } + } + + public String toString() { + return results.toString(); + } + + @Override + public boolean equals(Object o) { + if (o instanceof ResultSet) { + ResultSet other = (ResultSet)o; + return this.results.equals(other.results); + } else { + return false; + } + } + + @Override + public int hashCode() { + return results.hashCode(); + } +} + +class Resolver implements ResultSetVisitor { + private final ResultSet result; + private TypePlaceholder toResolve; + private RefTypeOrTPHOrWildcardOrGeneric resolved; + private final Set additionalTPHs = new HashSet<>(); + private ResultPair currentPair; + + public Resolver(ResultSet resultPairs){ + this.result = resultPairs; + } + + public ResolvedType resolve(TypePlaceholder tph){ + toResolve = tph; + resolved = null; + System.out.println(tph.toString()); + for(ResultPair resultPair : result.results) { + if(resultPair instanceof PairTPHEqualTPH && ((PairTPHEqualTPH) resultPair).getLeft().equals(toResolve)){ + currentPair = resultPair; + return resolve(((PairTPHEqualTPH) resultPair).getRight()); + } + } + for(ResultPair resultPair : result.results){ + currentPair = resultPair; + resultPair.accept(this); + } + if(resolved==null){//TPH kommt nicht im Result vor: + resolved = tph; + } + + ResolvedType result = new ResolvedType(resolved, additionalTPHs);//resolved; + result.setResultPair(currentPair); + return result; + } + + @Override + public void visit(PairTPHsmallerTPH p) { + currentPair = p; + if(p.left.equals(toResolve)){ + additionalTPHs.add(new GenericInsertPair(p.left, p.right)); + additionalTPHs.addAll(new RelatedTypeWalker(p.right, result).relatedTPHs); + } + if(p.right.equals(toResolve)) + additionalTPHs.addAll(new RelatedTypeWalker(p.left, result).relatedTPHs); + } + + @Override + public void visit(PairTPHequalRefTypeOrWildcardType p) { + currentPair = p; + if(p.left.equals(toResolve)){ + resolved = p.right; + RelatedTypeWalker related = new RelatedTypeWalker(null, result); + p.right.accept(related); + additionalTPHs.addAll(related.relatedTPHs); + } + } + + @Override + public void visit(PairTPHEqualTPH p) { + //Do nothing. Dieser Fall wird in der resolve-Methode abgefangen + } + + @Override + public void visit(RefType refType) { + + } + + @Override + public void visit(GenericRefType genericRefType) { + + } + + @Override + public void visit(SuperWildcardType superWildcardType) { + + } + + @Override + public void visit(TypePlaceholder typePlaceholder) { + + } + + @Override + public void visit(ExtendsWildcardType extendsWildcardType) { + + } + + + +} + +/** + * Sucht aus dem Result Set den Sub/supertyp für einen TPH + */ +@SuppressWarnings("rawtypes") +class TPHResolver implements ResultSetVisitor { + + private final TypePlaceholder tph; + Set resolved = new HashSet<>(); + private final ResultSet resultSet; + + TPHResolver(TypePlaceholder tph, ResultSet resultSet){ + this.resultSet = resultSet; + this.tph = tph; + for(ResultPair p : resultSet.results){ + p.accept(this); + } + if(resolved.size() == 0){ + resolved.add(new GenericInsertPair(tph, null)); + } + } + + @Override + public void visit(PairTPHsmallerTPH p) { + if(p.left.equals(tph) || p.right.equals(tph)){ + resolved.add(new GenericInsertPair(p.left, p.right)); + } + } + + @Override + public void visit(PairTPHequalRefTypeOrWildcardType p) { + TypePlaceholder otherSide = null; + if(p.right.equals(tph)){ + otherSide = p.left; + } + if(otherSide != null){ + Set newResultSet = new HashSet<>(this.resultSet.results); + newResultSet.remove(p); + resolved.addAll(new TPHResolver(otherSide, new ResultSet(newResultSet)).resolved); + } + } + + @Override + public void visit(PairTPHEqualTPH p) { + //ignorieren. Wird vom Resolver behandelt + } + + @Override + public void visit(RefType refType) { + + } + + @Override + public void visit(GenericRefType genericRefType) { + + } + + @Override + public void visit(SuperWildcardType superWildcardType) { + + } + + @Override + public void visit(TypePlaceholder typePlaceholder) { + + } + + @Override + public void visit(ExtendsWildcardType extendsWildcardType) { + + } +} + +@SuppressWarnings("rawtypes") +class RelatedTypeWalker implements ResultSetVisitor { + + final Set relatedTPHs = new HashSet<>(); + private final TypePlaceholder toResolve; + private final ResultSet resultSet; + + /** + * Läuft über das resultSet und speichert alle TPHs, welche mit start in Verbindung stehen + * @param start - kann null sein, wenn der Walker für einen RefType benutzt wird + * @param resultSet + */ + RelatedTypeWalker(TypePlaceholder start, ResultSet resultSet){ + this.toResolve = start; + this.resultSet = resultSet; + int resolved = 0; + do{ + resolved = relatedTPHs.size(); + for(ResultPair p : resultSet.results){ + p.accept(this); + p.accept(this); + } + }while(resolved - relatedTPHs.size() > 0); + } + + @Override + public void visit(PairTPHsmallerTPH p) { + if(p.getRight().equals(toResolve)){ + relatedTPHs.addAll(new TPHResolver(p.right, resultSet).resolved); + //relatedTPHs.addAll(new RelatedTypeWalker(p.right, resultSet).relatedTPHs); + } + if(p.getLeft().equals(toResolve)){ + relatedTPHs.addAll(new TPHResolver(p.left, resultSet).resolved); + //relatedTPHs.addAll(new RelatedTypeWalker(p.left, resultSet).relatedTPHs); + } + } + + @Override + public void visit(PairTPHequalRefTypeOrWildcardType p) { + if(p.getLeft().equals(toResolve)){ + p.getRight().accept(this); + } + } + + @Override + public void visit(PairTPHEqualTPH p) { + //Kann ignoriert werden. Diese Fälle werden vom Resolver behandelt + } + + /* + Die folgenden Funktionen fügen alle TPHs an die relatedTPHs an, denen sie begegnen: + Das wird verwendet, wenn alle relatedTPHs aus den Parametern eines RefTypes angefügt werden sollen + */ + + @Override + public void visit(RefType refType) { + for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){ + param.accept(this); + } + } + + @Override + public void visit(SuperWildcardType superWildcardType) { + superWildcardType.getInnerType().accept(this); + } + + @Override + public void visit(TypePlaceholder typePlaceholder) { + relatedTPHs.addAll(new TPHResolver(typePlaceholder, resultSet).resolved); + } + + @Override + public void visit(ExtendsWildcardType extendsWildcardType) { + extendsWildcardType.getInnerType().accept(this); + } + + @Override + public void visit(GenericRefType genericRefType) { + } } \ No newline at end of file diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/GuavaSetOperations.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/GuavaSetOperations.java index b51fb648f..19e7c48fc 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/GuavaSetOperations.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/GuavaSetOperations.java @@ -1,23 +1,23 @@ -package de.dhbwstuttgart.typeinference.unify; - -import java.util.List; -import java.util.Set; - -import com.google.common.collect.Sets; - -import de.dhbwstuttgart.typeinference.unify.interfaces.ISetOperations; - -/** - * Implements set operations using google guava. - * @author DH10STF - * - */ -public class GuavaSetOperations implements ISetOperations { - - @Override - public Set> cartesianProduct(List> sets) { - // Wraps the call to google guava - return Sets.cartesianProduct(sets); - } - -} +package de.dhbwstuttgart.typeinference.unify; + +import java.util.List; +import java.util.Set; + +import com.google.common.collect.Sets; + +import de.dhbwstuttgart.typeinference.unify.interfaces.ISetOperations; + +/** + * Implements set operations using google guava. + * @author DH10STF + * + */ +public class GuavaSetOperations implements ISetOperations { + + @Override + public Set> cartesianProduct(List> sets) { + // Wraps the call to google guava + return Sets.cartesianProduct(sets); + } + +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java index 087b89430..2fceb245d 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java @@ -1,108 +1,108 @@ -package de.dhbwstuttgart.typeinference.unify; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify; -import de.dhbwstuttgart.typeinference.unify.model.PairOperator; -import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; -import de.dhbwstuttgart.typeinference.unify.model.TypeParams; -import de.dhbwstuttgart.typeinference.unify.model.Unifier; -import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; -import de.dhbwstuttgart.typeinference.unify.model.UnifyType; - -/** - * Implementation of the Martelli-Montanari unification algorithm. - * @author Florian Steurer - */ -public class MartelliMontanariUnify implements IUnify { - - @Override - public Optional unify(Set terms) { - // Sets with less than 2 terms are trivially unified - if(terms.size() < 2) - return Optional.of(Unifier.identity()); - - // For the the set of terms {t1,...,tn}, - // build a list of equations {(t1 = t2), (t2 = t3), (t3 = t4), ....} - ArrayList termsList = new ArrayList(); - Iterator iter = terms.iterator(); - UnifyType prev = iter.next(); +package de.dhbwstuttgart.typeinference.unify; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify; +import de.dhbwstuttgart.typeinference.unify.model.PairOperator; +import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; +import de.dhbwstuttgart.typeinference.unify.model.TypeParams; +import de.dhbwstuttgart.typeinference.unify.model.Unifier; +import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; +import de.dhbwstuttgart.typeinference.unify.model.UnifyType; + +/** + * Implementation of the Martelli-Montanari unification algorithm. + * @author Florian Steurer + */ +public class MartelliMontanariUnify implements IUnify { + + @Override + public Optional unify(Set terms) { + // Sets with less than 2 terms are trivially unified + if(terms.size() < 2) + return Optional.of(Unifier.identity()); + + // For the the set of terms {t1,...,tn}, + // build a list of equations {(t1 = t2), (t2 = t3), (t3 = t4), ....} + ArrayList termsList = new ArrayList(); + Iterator iter = terms.iterator(); + UnifyType prev = iter.next(); while(iter.hasNext()) { - UnifyType next = iter.next(); + UnifyType next = iter.next(); termsList.add(new UnifyPair(prev, next, PairOperator.EQUALSDOT)); - prev = next; - } - - // Start with the identity unifier. Substitutions will be added later. - Unifier mgu = Unifier.identity(); - - // Apply rules while possible - int idx = 0; - while(idx < termsList.size()) { - UnifyPair pair = termsList.get(idx); - UnifyType rhsType = pair.getRhsType(); - UnifyType lhsType = pair.getLhsType(); - TypeParams rhsTypeParams = rhsType.getTypeParams(); - TypeParams lhsTypeParams = lhsType.getTypeParams(); - - // REDUCE - Rule - if(!(rhsType instanceof PlaceholderType) && !(lhsType instanceof PlaceholderType)) { - Set result = new HashSet<>(); - - // f<...> = g<...> with f != g are not unifiable - if(!rhsType.getName().equals(lhsType.getName())) - return Optional.empty(); // conflict - // f = f are not unifiable - if(rhsTypeParams.size() != lhsTypeParams.size()) - return Optional.empty(); // conflict - // f = g is not unifiable (cannot be f = f because erase rule would have been applied) - //if(rhsTypeParams.size() == 0) - //return Optional.empty(); - - // Unpack the arguments - for(int i = 0; i < rhsTypeParams.size(); i++) - result.add(new UnifyPair(rhsTypeParams.get(i), lhsTypeParams.get(i), PairOperator.EQUALSDOT)); - - termsList.remove(idx); - termsList.addAll(result); - continue; - } - - // DELETE - Rule - if(pair.getRhsType().equals(pair.getLhsType())) { - termsList.remove(idx); - continue; - } - - // SWAP - Rule - if(!(lhsType instanceof PlaceholderType) && (rhsType instanceof PlaceholderType)) { - termsList.remove(idx); - termsList.add(new UnifyPair(rhsType, lhsType, PairOperator.EQUALSDOT)); - continue; - } - - // OCCURS-CHECK - if(pair.getLhsType() instanceof PlaceholderType - && pair.getRhsType().getTypeParams().occurs((PlaceholderType) pair.getLhsType())) - return Optional.empty(); - - // SUBST - Rule - if(lhsType instanceof PlaceholderType) { - mgu.add((PlaceholderType) lhsType, rhsType); - //PL 2018-04-01 nach checken, ob es richtig ist, dass keine Substitutionen uebergeben werden muessen. - termsList = termsList.stream().map(x -> mgu.apply(x)).collect(Collectors.toCollection(ArrayList::new)); - idx = idx+1 == termsList.size() ? 0 : idx+1; - continue; - } - - idx++; - } - - return Optional.of(mgu); - } -} + prev = next; + } + + // Start with the identity unifier. Substitutions will be added later. + Unifier mgu = Unifier.identity(); + + // Apply rules while possible + int idx = 0; + while(idx < termsList.size()) { + UnifyPair pair = termsList.get(idx); + UnifyType rhsType = pair.getRhsType(); + UnifyType lhsType = pair.getLhsType(); + TypeParams rhsTypeParams = rhsType.getTypeParams(); + TypeParams lhsTypeParams = lhsType.getTypeParams(); + + // REDUCE - Rule + if(!(rhsType instanceof PlaceholderType) && !(lhsType instanceof PlaceholderType)) { + Set result = new HashSet<>(); + + // f<...> = g<...> with f != g are not unifiable + if(!rhsType.getName().equals(lhsType.getName())) + return Optional.empty(); // conflict + // f = f are not unifiable + if(rhsTypeParams.size() != lhsTypeParams.size()) + return Optional.empty(); // conflict + // f = g is not unifiable (cannot be f = f because erase rule would have been applied) + //if(rhsTypeParams.size() == 0) + //return Optional.empty(); + + // Unpack the arguments + for(int i = 0; i < rhsTypeParams.size(); i++) + result.add(new UnifyPair(rhsTypeParams.get(i), lhsTypeParams.get(i), PairOperator.EQUALSDOT)); + + termsList.remove(idx); + termsList.addAll(result); + continue; + } + + // DELETE - Rule + if(pair.getRhsType().equals(pair.getLhsType())) { + termsList.remove(idx); + continue; + } + + // SWAP - Rule + if(!(lhsType instanceof PlaceholderType) && (rhsType instanceof PlaceholderType)) { + termsList.remove(idx); + termsList.add(new UnifyPair(rhsType, lhsType, PairOperator.EQUALSDOT)); + continue; + } + + // OCCURS-CHECK + if(pair.getLhsType() instanceof PlaceholderType + && pair.getRhsType().getTypeParams().occurs((PlaceholderType) pair.getLhsType())) + return Optional.empty(); + + // SUBST - Rule + if(lhsType instanceof PlaceholderType) { + mgu.add((PlaceholderType) lhsType, rhsType); + //PL 2018-04-01 nach checken, ob es richtig ist, dass keine Substitutionen uebergeben werden muessen. + termsList = termsList.stream().map(x -> mgu.apply(x)).collect(Collectors.toCollection(ArrayList::new)); + idx = idx+1 == termsList.size() ? 0 : idx+1; + continue; + } + + idx++; + } + + return Optional.of(mgu); + } +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/Match.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/Match.java index 3e9956075..75469f642 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/Match.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/Match.java @@ -1,91 +1,91 @@ -package de.dhbwstuttgart.typeinference.unify; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -import de.dhbwstuttgart.typeinference.unify.interfaces.IMatch; -import de.dhbwstuttgart.typeinference.unify.model.PairOperator; -import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; -import de.dhbwstuttgart.typeinference.unify.model.TypeParams; -import de.dhbwstuttgart.typeinference.unify.model.Unifier; -import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; -import de.dhbwstuttgart.typeinference.unify.model.UnifyType; - -/** - * Implementation of match derived from unification algorithm. - * @author Martin Pluemicke - */ -public class Match implements IMatch { - - @Override - //A =. A ==> True - //A =. A ==> False - public Optional match(ArrayList termsList) { - - // Start with the identity unifier. Substitutions will be added later. - Unifier mgu = Unifier.identity(); - - // Apply rules while possible - int idx = 0; - while(idx < termsList.size()) { - UnifyPair pair = termsList.get(idx); - UnifyType rhsType = pair.getRhsType(); - UnifyType lhsType = pair.getLhsType(); - TypeParams rhsTypeParams = rhsType.getTypeParams(); - TypeParams lhsTypeParams = lhsType.getTypeParams(); - - // REDUCE - Rule - if(!(rhsType instanceof PlaceholderType) && !(lhsType instanceof PlaceholderType)) { - Set result = new HashSet<>(); - - // f<...> = g<...> with f != g are not unifiable - if(!rhsType.getName().equals(lhsType.getName())) - return Optional.empty(); // conflict - // f = f are not unifiable - if(rhsTypeParams.size() != lhsTypeParams.size()) - return Optional.empty(); // conflict - // f = g is not unifiable (cannot be f = f because erase rule would have been applied) - //if(rhsTypeParams.size() == 0) - //return Optional.empty(); - - // Unpack the arguments - for(int i = 0; i < rhsTypeParams.size(); i++) - result.add(new UnifyPair(lhsTypeParams.get(i), rhsTypeParams.get(i), PairOperator.EQUALSDOT)); - - termsList.remove(idx); - termsList.addAll(result); - continue; - } - - // DELETE - Rule - if(pair.getRhsType().equals(pair.getLhsType())) { - termsList.remove(idx); - continue; - } - - // SWAP - Rule - if(!(lhsType instanceof PlaceholderType) && (rhsType instanceof PlaceholderType)) { - return Optional.empty(); // conflict - } - - // OCCURS-CHECK - //deleted - - // SUBST - Rule - if(lhsType instanceof PlaceholderType) { - mgu.add((PlaceholderType) lhsType, rhsType); - termsList = termsList.stream().map(mgu::applyleft).collect(Collectors.toCollection(ArrayList::new)); - idx = idx+1 == termsList.size() ? 0 : idx+1; - continue; - } - - idx++; - } - - return Optional.of(mgu); - } -} +package de.dhbwstuttgart.typeinference.unify; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +import de.dhbwstuttgart.typeinference.unify.interfaces.IMatch; +import de.dhbwstuttgart.typeinference.unify.model.PairOperator; +import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; +import de.dhbwstuttgart.typeinference.unify.model.TypeParams; +import de.dhbwstuttgart.typeinference.unify.model.Unifier; +import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; +import de.dhbwstuttgart.typeinference.unify.model.UnifyType; + +/** + * Implementation of match derived from unification algorithm. + * @author Martin Pluemicke + */ +public class Match implements IMatch { + + @Override + //A =. A ==> True + //A =. A ==> False + public Optional match(ArrayList termsList) { + + // Start with the identity unifier. Substitutions will be added later. + Unifier mgu = Unifier.identity(); + + // Apply rules while possible + int idx = 0; + while(idx < termsList.size()) { + UnifyPair pair = termsList.get(idx); + UnifyType rhsType = pair.getRhsType(); + UnifyType lhsType = pair.getLhsType(); + TypeParams rhsTypeParams = rhsType.getTypeParams(); + TypeParams lhsTypeParams = lhsType.getTypeParams(); + + // REDUCE - Rule + if(!(rhsType instanceof PlaceholderType) && !(lhsType instanceof PlaceholderType)) { + Set result = new HashSet<>(); + + // f<...> = g<...> with f != g are not unifiable + if(!rhsType.getName().equals(lhsType.getName())) + return Optional.empty(); // conflict + // f = f are not unifiable + if(rhsTypeParams.size() != lhsTypeParams.size()) + return Optional.empty(); // conflict + // f = g is not unifiable (cannot be f = f because erase rule would have been applied) + //if(rhsTypeParams.size() == 0) + //return Optional.empty(); + + // Unpack the arguments + for(int i = 0; i < rhsTypeParams.size(); i++) + result.add(new UnifyPair(lhsTypeParams.get(i), rhsTypeParams.get(i), PairOperator.EQUALSDOT)); + + termsList.remove(idx); + termsList.addAll(result); + continue; + } + + // DELETE - Rule + if(pair.getRhsType().equals(pair.getLhsType())) { + termsList.remove(idx); + continue; + } + + // SWAP - Rule + if(!(lhsType instanceof PlaceholderType) && (rhsType instanceof PlaceholderType)) { + return Optional.empty(); // conflict + } + + // OCCURS-CHECK + //deleted + + // SUBST - Rule + if(lhsType instanceof PlaceholderType) { + mgu.add((PlaceholderType) lhsType, rhsType); + termsList = termsList.stream().map(mgu::applyleft).collect(Collectors.toCollection(ArrayList::new)); + idx = idx+1 == termsList.size() ? 0 : idx+1; + continue; + } + + idx++; + } + + return Optional.of(mgu); + } +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java index da8998d28..a392a2fa2 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -1,1022 +1,1022 @@ -package de.dhbwstuttgart.typeinference.unify; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; -import java.util.Queue; -import java.util.Set; -import java.util.Stack; -import java.util.function.Function; -import java.util.stream.Collectors; - -import de.dhbwstuttgart.exceptions.DebugException; -import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; -import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet; -import de.dhbwstuttgart.typeinference.unify.model.ExtendsType; -import de.dhbwstuttgart.typeinference.unify.model.FunNType; -import de.dhbwstuttgart.typeinference.unify.model.PairOperator; -import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; -import de.dhbwstuttgart.typeinference.unify.model.ReferenceType; -import de.dhbwstuttgart.typeinference.unify.model.SuperType; -import de.dhbwstuttgart.typeinference.unify.model.TypeParams; -import de.dhbwstuttgart.typeinference.unify.model.Unifier; -import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; -import de.dhbwstuttgart.typeinference.unify.model.UnifyType; -import de.dhbwstuttgart.typeinference.unify.model.WildcardType; -import de.dhbwstuttgart.typeinference.unify.distributeVariance; - -import java.io.FileWriter; -import java.io.IOException; -import java.io.Writer; - -/** - * Implementation of the type inference rules. - * @author Florian Steurer - * - */ -public class RuleSet implements IRuleSet{ - - Writer logFile; - - public RuleSet() { - super(); - } - - RuleSet(Writer logFile) { - this.logFile = logFile; - } - - @Override - public Optional reduceUp(UnifyPair pair) { - // Check if reduce up is applicable - if(pair.getPairOp() != PairOperator.SMALLERDOT) - return Optional.empty(); - - UnifyType rhsType = pair.getRhsType(); - if(!(rhsType instanceof SuperType)) - return Optional.empty(); - - UnifyType lhsType = pair.getLhsType(); - if(!(lhsType instanceof ReferenceType) && !(lhsType instanceof PlaceholderType)) - return Optional.empty(); - - // Rule is applicable, unpack the SuperType - return Optional.of(new UnifyPair(lhsType, ((SuperType) rhsType).getSuperedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); - } - - @Override - public Optional reduceLow(UnifyPair pair) { - // Check if rule is applicable - if(pair.getPairOp() != PairOperator.SMALLERDOT) - return Optional.empty(); - - UnifyType lhsType = pair.getLhsType(); - if(!(lhsType instanceof ExtendsType)) - return Optional.empty(); - - UnifyType rhsType = pair.getRhsType(); - if(!(rhsType instanceof ReferenceType) && !(rhsType instanceof PlaceholderType)) - return Optional.empty(); - - // Rule is applicable, unpack the ExtendsType - return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(), rhsType, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); - } - - @Override - public Optional reduceUpLow(UnifyPair pair) { - // Check if rule is applicable - if(pair.getPairOp() != PairOperator.SMALLERDOT) - return Optional.empty(); - - UnifyType lhsType = pair.getLhsType(); - if(!(lhsType instanceof ExtendsType)) - return Optional.empty(); - - UnifyType rhsType = pair.getRhsType(); - if(!(rhsType instanceof SuperType)) - return Optional.empty(); - - // Rule is applicable, unpack both sides - return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(),((SuperType) rhsType).getSuperedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); - } - - @Override - public Optional> reduceExt(UnifyPair pair, IFiniteClosure fc) { - if(pair.getPairOp() != PairOperator.SMALLERDOTWC) - return Optional.empty(); - - UnifyType x = pair.getLhsType(); - UnifyType sTypeX; - - if(x instanceof ReferenceType) - sTypeX = x; - else if(x instanceof ExtendsType) - sTypeX = ((ExtendsType) x).getExtendedType(); - else - return Optional.empty(); - - UnifyType extY = pair.getRhsType(); - - if(!(extY instanceof ExtendsType)) - return Optional.empty(); - - if(x.getTypeParams().empty() || extY.getTypeParams().size() != x.getTypeParams().size()) - return Optional.empty(); - - UnifyType xFromFc = fc.getLeftHandedType(sTypeX.getName()).orElse(null); - - if(xFromFc == null || !xFromFc.getTypeParams().arePlaceholders()) - return Optional.empty(); - - if(x instanceof ExtendsType) - xFromFc = new ExtendsType(xFromFc); - - UnifyType extYFromFc = fc.grArg(xFromFc, new HashSet<>()).stream().filter(t -> t.getName().equals(extY.getName())).filter(t -> t.getTypeParams().arePlaceholders()).findAny().orElse(null); - - if(extYFromFc == null || extYFromFc.getTypeParams() != xFromFc.getTypeParams()) - return Optional.empty(); - - TypeParams extYParams = extY.getTypeParams(); - TypeParams xParams = x.getTypeParams(); - - int[] pi = pi(xParams, extYParams); - - if(pi.length == 0) - return Optional.empty(); - - Set result = new HashSet<>(); - - for(int rhsIdx = 0; rhsIdx < extYParams.size(); rhsIdx++) - result.add(new UnifyPair(xParams.get(pi[rhsIdx]), extYParams.get(rhsIdx), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); - - return Optional.of(result); - } - - @Override - public Optional> reduceSup(UnifyPair pair, IFiniteClosure fc) { - if(pair.getPairOp() != PairOperator.SMALLERDOTWC) - return Optional.empty(); - - UnifyType x = pair.getLhsType(); - UnifyType sTypeX; - - if(x instanceof ReferenceType) - sTypeX = x; - else if(x instanceof SuperType) - sTypeX = ((SuperType) x).getSuperedType(); - else - return Optional.empty(); - - UnifyType supY = pair.getRhsType(); - - if(!(supY instanceof SuperType)) - return Optional.empty(); - - if(x.getTypeParams().empty() || supY.getTypeParams().size() != x.getTypeParams().size()) - return Optional.empty(); - - UnifyType xFromFc = fc.getLeftHandedType(sTypeX.getName()).orElse(null); - - if(xFromFc == null || !xFromFc.getTypeParams().arePlaceholders()) - return Optional.empty(); - - if(x instanceof SuperType) - xFromFc = new SuperType(xFromFc); - - UnifyType supYFromFc = fc.grArg(xFromFc, new HashSet<>()).stream().filter(t -> t.getName().equals(supY.getName())).filter(t -> t.getTypeParams().arePlaceholders()).findAny().orElse(null); - - if(supYFromFc == null || supYFromFc.getTypeParams() != xFromFc.getTypeParams()) - return Optional.empty(); - - TypeParams supYParams = supY.getTypeParams(); - TypeParams xParams = x.getTypeParams(); - Set result = new HashSet<>(); - - int[] pi = pi(xParams, supYParams); - - if(pi.length == 0) - return Optional.empty(); - - for(int rhsIdx = 0; rhsIdx < supYParams.size(); rhsIdx++) - result.add(new UnifyPair(supYParams.get(rhsIdx), xParams.get(pi[rhsIdx]), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); - - return Optional.of(result); - } - - @Override - public Optional> reduceEq(UnifyPair pair) { - if(pair.getPairOp() != PairOperator.SMALLERDOTWC) - return Optional.empty(); - - UnifyType lhsType = pair.getLhsType(); - if(lhsType instanceof PlaceholderType || lhsType.getTypeParams().empty()) - return Optional.empty(); - - UnifyType rhsType = pair.getRhsType(); - - if(!rhsType.getName().equals(lhsType.getName())) - return Optional.empty(); - - if(rhsType instanceof PlaceholderType || lhsType instanceof PlaceholderType || rhsType.getTypeParams().empty()) - return Optional.empty(); - - if(rhsType.getTypeParams().size() != lhsType.getTypeParams().size()) - return Optional.empty(); - - // Keine Permutation wie im Paper nötig - Set result = new HashSet<>(); - TypeParams lhsTypeParams = lhsType.getTypeParams(); - TypeParams rhsTypeParams = rhsType.getTypeParams(); - - for(int i = 0; i < lhsTypeParams.size(); i++) - result.add(new UnifyPair(lhsTypeParams.get(i), rhsTypeParams.get(i), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); - - return Optional.of(result); - } - - @Override - public Optional> reduce1(UnifyPair pair, IFiniteClosure fc) { - if(pair.getPairOp() != PairOperator.SMALLERDOT) - return Optional.empty(); - - UnifyType c = pair.getLhsType(); - if(!(c instanceof ReferenceType)) - return Optional.empty(); - - UnifyType d = pair.getRhsType(); - if(!(d instanceof ReferenceType)) - return Optional.empty(); - - ReferenceType lhsSType = (ReferenceType) c; - ReferenceType rhsSType = (ReferenceType) d; - - //try { - // logFile.write("PAIR Rules: " + pair + "\n"); - // logFile.flush(); - //} - //catch (IOException e) { } - - if(lhsSType.getTypeParams().empty() || lhsSType.getTypeParams().size() != rhsSType.getTypeParams().size()) - return Optional.empty(); - - UnifyType cFromFc = fc.getLeftHandedType(c.getName()).orElse(null); - //2018-02-23: liefert Vector>: Das kann nicht sein. - - //NOCHMAL UEBERPRUEFEN - //PL 18-02-09 Eingfuegt Anfang - //C und D koennen auch gleich sein. - if (c.getName().equals(d.getName())) { - Set result = new HashSet<>(); - TypeParams rhsTypeParams = d.getTypeParams(); - TypeParams lhsTypeParams = c.getTypeParams(); - for(int rhsIdx = 0; rhsIdx < c.getTypeParams().size(); rhsIdx++) - result.add(new UnifyPair(lhsTypeParams.get(rhsIdx), rhsTypeParams.get(rhsIdx), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); - - return Optional.of(result); - } - //PL 18-02-09 Eingfuegt ENDE - - //try { - // logFile.write("cFromFc: " + cFromFc); - // logFile.flush(); - //} - //catch (IOException e) { } - - if(cFromFc == null || !cFromFc.getTypeParams().arePlaceholders()) - return Optional.empty(); - - UnifyType dFromFc = fc.getAncestors(cFromFc).stream().filter(x -> x.getName().equals(d.getName())).findAny().orElse(null); - - //try { - // logFile.write("cFromFc: " + cFromFc); - // logFile.flush(); - //} - //catch (IOException e) { } - - if(dFromFc == null || !dFromFc.getTypeParams().arePlaceholders() || dFromFc.getTypeParams().size() != cFromFc.getTypeParams().size()) - return Optional.empty(); - //System.out.println("cFromFc: " + cFromFc); - //System.out.println("dFromFc: " + dFromFc); - int[] pi = pi(cFromFc.getTypeParams(), dFromFc.getTypeParams()); - - if(pi.length == 0) - return Optional.empty(); - - TypeParams rhsTypeParams = d.getTypeParams(); - TypeParams lhsTypeParams = c.getTypeParams(); - Set result = new HashSet<>(); - - for(int rhsIdx = 0; rhsIdx < rhsTypeParams.size(); rhsIdx++) - result.add(new UnifyPair(lhsTypeParams.get(pi[rhsIdx]), rhsTypeParams.get(rhsIdx), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); - - return Optional.of(result); - } - - @Override - public Optional> reduce2(UnifyPair pair) { - if(pair.getPairOp() != PairOperator.EQUALSDOT) - return Optional.empty(); - - UnifyType lhsType = pair.getLhsType(); - ReferenceType lhsSType; - UnifyType rhsType = pair.getRhsType(); - ReferenceType rhsSType; - - if ((lhsType instanceof ReferenceType) && (rhsType instanceof ReferenceType)) { - lhsSType = (ReferenceType) lhsType; - rhsSType = (ReferenceType) rhsType; - } - else if (((lhsType instanceof ExtendsType) && (rhsType instanceof ExtendsType)) - || ((lhsType instanceof SuperType) && (rhsType instanceof SuperType))) { - UnifyType lhsSTypeRaw = ((WildcardType) lhsType).getWildcardedType(); - UnifyType rhsSTypeRaw = ((WildcardType) rhsType).getWildcardedType(); - if ((lhsSTypeRaw instanceof ReferenceType) && (rhsSTypeRaw instanceof ReferenceType)) { - lhsSType = (ReferenceType) lhsSTypeRaw; - rhsSType = (ReferenceType) rhsSTypeRaw; - } - else - return Optional.empty(); - } - else - return Optional.empty(); - - if(lhsSType.getTypeParams().empty()) - return Optional.empty(); - - /* PL 2018-01-22 in obere Teil integriert - UnifyType rhsType = pair.getRhsType(); - ReferenceType rhsSType; - - if(rhsType instanceof ReferenceType) - rhsSType = (ReferenceType) rhsType; - else if(rhsType instanceof WildcardType) { - UnifyType rhsSTypeRaw = ((WildcardType) rhsType).getWildcardedType(); - if(rhsSTypeRaw instanceof ReferenceType) - rhsSType = (ReferenceType) rhsSTypeRaw; - else - return Optional.empty(); - } - else - return Optional.empty(); - */ - - if(!rhsSType.getName().equals(lhsSType.getName())) - return Optional.empty(); - - if(!(lhsSType.getTypeParams().size()==rhsSType.getTypeParams().size()))throw new DebugException("Fehler in Unifizierung"+ " " + lhsSType.toString() + " " + rhsSType.toString()); - //if(rhsSType.getTypeParams().size() != lhsSType.getTypeParams().size()) - // return Optional.empty(); - - Set result = new HashSet<>(); - - TypeParams rhsTypeParams = rhsSType.getTypeParams(); - TypeParams lhsTypeParams = lhsSType.getTypeParams(); - for(int i = 0; i < rhsTypeParams.size(); i++) - result.add(new UnifyPair(lhsTypeParams.get(i), rhsTypeParams.get(i), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); - - return Optional.of(result); - } - - @Override - public boolean erase1(UnifyPair pair, IFiniteClosure fc) { - if((pair.getPairOp() != PairOperator.SMALLERDOT) && (pair.getPairOp() != PairOperator.SMALLERNEQDOT)) - return false; - - if (pair.getPairOp() == PairOperator.SMALLERNEQDOT) { - UnifyType lhs = pair.getLhsType(); - UnifyType rhs = pair.getRhsType(); - if (lhs instanceof WildcardType) { - lhs = ((WildcardType)lhs).getWildcardedType(); - } - if (rhs instanceof WildcardType) { - rhs = ((WildcardType)rhs).getWildcardedType(); - } - - if (lhs.equals(rhs)){ - return false; - } - } - - UnifyType lhsType = pair.getLhsType(); - if(!(lhsType instanceof ReferenceType) && !(lhsType instanceof PlaceholderType)) - return false; - - UnifyType rhsType = pair.getRhsType(); - if(!(rhsType instanceof ReferenceType) && !(rhsType instanceof PlaceholderType)) - return false; - - return fc.greater(lhsType, new HashSet<>()).contains(rhsType); - } - - @Override - public boolean erase2(UnifyPair pair, IFiniteClosure fc) { - if(pair.getPairOp() != PairOperator.SMALLERDOTWC) - return false; - - UnifyType lhsType = pair.getLhsType(); - UnifyType rhsType = pair.getRhsType(); - - return fc.grArg(lhsType, new HashSet<>()).contains(rhsType); - } - - @Override - public boolean erase3(UnifyPair pair) { - if(pair.getPairOp() != PairOperator.EQUALSDOT) - return false; - - return pair.getLhsType().equals(pair.getRhsType()); - } - - @Override - public Optional swap(UnifyPair pair) { - if(pair.getPairOp() != PairOperator.EQUALSDOT) - return Optional.empty(); - - if(pair.getLhsType() instanceof PlaceholderType) - return Optional.empty(); - - if(!(pair.getRhsType() instanceof PlaceholderType)) - return Optional.empty(); - - return Optional.of(new UnifyPair(pair.getRhsType(), pair.getLhsType(), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); - } - - @Override - public Optional adapt(UnifyPair pair, IFiniteClosure fc) { - if(pair.getPairOp() != PairOperator.SMALLERDOT) - return Optional.empty(); - - UnifyType typeD = pair.getLhsType(); - if(!(typeD instanceof ReferenceType)) - return Optional.empty(); - - UnifyType typeDs = pair.getRhsType(); - if(!(typeDs instanceof ReferenceType)) - return Optional.empty(); - - /*if(typeD.getTypeParams().size() == 0 || typeDs.getTypeParams().size() == 0) - return Optional.empty();*/ - - if(typeD.getName().equals(typeDs.getName())) - return Optional.empty(); - - - Optional opt = fc.getLeftHandedType(typeD.getName()); - if(!opt.isPresent()) - return Optional.empty(); - - // The generic Version of Type D (D) - UnifyType typeDgen = opt.get(); - - // Actually greater+ because the types are ensured to have different names - Set greater = fc.getAncestors(typeDgen); - opt = greater.stream().filter(x -> x.getName().equals(typeDs.getName())).findAny(); - - if(!opt.isPresent()) - return Optional.empty(); - - UnifyType newLhs = opt.get(); - - TypeParams typeDParams = typeD.getTypeParams(); - TypeParams typeDgenParams = typeDgen.getTypeParams(); - - //System.out.println("Pair: " +pair); - //System.out.println("typeD: " +typeD); - //System.out.println("typeDParams: " +typeDParams); - //System.out.println("typeDgen: " +typeD); - //System.out.println("typeDgenParams: " +typeDgenParams); - Unifier unif = Unifier.identity(); - for(int i = 0; i < typeDParams.size(); i++) { - //System.out.println("ADAPT" +typeDgenParams); - if (typeDgenParams.get(i) instanceof PlaceholderType) - unif.add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i)); - else System.out.println("ERROR"); - } - return Optional.of(new UnifyPair(unif.apply(newLhs), typeDs, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); - } - - @Override - public Optional adaptExt(UnifyPair pair, IFiniteClosure fc) { - if(pair.getPairOp() != PairOperator.SMALLERDOTWC) - return Optional.empty(); - - UnifyType typeD = pair.getLhsType(); - if(!(typeD instanceof ReferenceType) && !(typeD instanceof ExtendsType)) - return Optional.empty(); - - UnifyType typeExtDs = pair.getRhsType(); - if(!(typeExtDs instanceof ExtendsType)) - return Optional.empty(); - - if(typeD.getTypeParams().size() == 0 || typeExtDs.getTypeParams().size() == 0) - return Optional.empty(); - - UnifyType typeDgen; - if(typeD instanceof ReferenceType) - typeDgen = fc.getLeftHandedType(typeD.getName()).orElse(null); - else { - Optional opt = fc.getLeftHandedType(((ExtendsType) typeD).getExtendedType().getName()); - typeDgen = opt.isPresent() ? new ExtendsType(opt.get()) : null; - } - - if(typeDgen == null) - return Optional.empty(); - - Set grArg = fc.grArg(typeDgen, new HashSet<>()); - - Optional opt = grArg.stream().filter(x -> x.getName().equals(typeExtDs.getName())).findAny(); - - if(!opt.isPresent()) - return Optional.empty(); - - UnifyType newLhs = ((ExtendsType) opt.get()).getExtendedType(); - - TypeParams typeDParams = typeD.getTypeParams(); - TypeParams typeDgenParams = typeDgen.getTypeParams(); - - Unifier unif = new Unifier((PlaceholderType) typeDgenParams.get(0), typeDParams.get(0)); - for(int i = 1; i < typeDParams.size(); i++) - unif.add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i)); - - return Optional.of(new UnifyPair(unif.apply(newLhs), typeExtDs, PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); - } - - @Override - public Optional adaptSup(UnifyPair pair, IFiniteClosure fc) { - if(pair.getPairOp() != PairOperator.SMALLERDOTWC) - return Optional.empty(); - - UnifyType typeDs = pair.getLhsType(); - if(!(typeDs instanceof ReferenceType) && !(typeDs instanceof SuperType)) - return Optional.empty(); - - UnifyType typeSupD = pair.getRhsType(); - if(!(typeSupD instanceof SuperType)) - return Optional.empty(); - - if(typeDs.getTypeParams().size() == 0 || typeSupD.getTypeParams().size() == 0) - return Optional.empty(); - - - Optional opt = fc.getLeftHandedType(((SuperType) typeSupD).getSuperedType().getName()); - - if(!opt.isPresent()) - return Optional.empty(); - - UnifyType typeDgen = opt.get(); - UnifyType typeSupDgen = new SuperType(typeDgen); - - // Use of smArg instead of grArg because - // a in grArg(b) => b in smArg(a) - Set smArg = fc.smArg(typeSupDgen, new HashSet<>()); - opt = smArg.stream().filter(x -> x.getName().equals(typeDs.getName())).findAny(); - - if(!opt.isPresent()) - return Optional.empty(); - - // New RHS - UnifyType newRhs = null; - if(typeDs instanceof ReferenceType) - newRhs = new ExtendsType(typeDs); - else - newRhs = new ExtendsType(((SuperType) typeDs).getSuperedType()); - - // New LHS - UnifyType newLhs = opt.get(); - TypeParams typeDParams = typeSupD.getTypeParams(); - TypeParams typeSupDsgenParams = typeSupDgen.getTypeParams(); - - Unifier unif = new Unifier((PlaceholderType) typeSupDsgenParams.get(0), typeDParams.get(0)); - for(int i = 1; i < typeDParams.size(); i++) - unif.add((PlaceholderType) typeSupDsgenParams.get(i), typeDParams.get(i)); - - return Optional.of(new UnifyPair(unif.apply(newLhs), newRhs, PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); - } - - /** - * Finds the permutation pi of the type arguments of two types based on the finite closure - * @param cArgs The type which arguments are permuted - * @param dArgs The other type - * @return An array containing the values of pi for every type argument of C or an empty array if the search failed. - */ - private int[] pi(TypeParams cArgs, TypeParams dArgs) { - if(!(cArgs.size()==dArgs.size()))throw new DebugException("Fehler in Unifizierung"); - - int[] permutation = new int[dArgs.size()]; - - boolean succ = true; - for (int dArgIdx = 0; dArgIdx < dArgs.size() && succ; dArgIdx++) { - UnifyType dArg = dArgs.get(dArgIdx); - succ = false; - for (int pi = 0; pi < cArgs.size(); pi++) - if (cArgs.get(pi).getName().equals(dArg.getName())) { - permutation[dArgIdx] = pi; - succ = true; - break; - } - } - - return succ ? permutation : new int[0]; - } - - public Optional> subst(Set pairs) { - return subst(pairs, new ArrayList<>()); - } - - @Override - public Optional> subst(Set pairs, List>> oderConstraints) { - HashMap typeMap = new HashMap<>(); - - Stack occuringTypes = new Stack<>(); - - for(UnifyPair pair : pairs) { - occuringTypes.push(pair.getLhsType()); - occuringTypes.push(pair.getRhsType()); - } - - while(!occuringTypes.isEmpty()) { - UnifyType t1 = occuringTypes.pop(); - if(!typeMap.containsKey(t1)) - typeMap.put(t1, 0); - typeMap.put(t1, typeMap.get(t1)+1); - - if(t1 instanceof ExtendsType) - occuringTypes.push(((ExtendsType) t1).getExtendedType()); - if(t1 instanceof SuperType) - occuringTypes.push(((SuperType) t1).getSuperedType()); - else - t1.getTypeParams().forEach(x -> occuringTypes.push(x)); - } - - Queue result1 = new LinkedList(pairs); - ArrayList result = new ArrayList(); - boolean applied = false; - - while(!result1.isEmpty()) { - UnifyPair pair = result1.poll(); - PlaceholderType lhsType = null; - UnifyType rhsType; - - if(pair.getPairOp() == PairOperator.EQUALSDOT - && pair.getLhsType() instanceof PlaceholderType) - lhsType = (PlaceholderType) pair.getLhsType(); - rhsType = pair.getRhsType(); //PL eingefuegt 2017-09-29 statt !((rhsType = pair.getRhsType()) instanceof PlaceholderType) - if(lhsType != null - //&& !((rhsType = pair.getRhsType()) instanceof PlaceholderType) //PL geloescht am 2017-09-29 Begründung: auch Typvariablen muessen ersetzt werden. - && typeMap.get(lhsType) > 1 // The type occurs in more pairs in the set than just the recent pair. - && !rhsType.getTypeParams().occurs(lhsType) - && !((rhsType instanceof WildcardType) && ((WildcardType)rhsType).getWildcardedType().equals(lhsType))) //PL eigefuegt 2018-02-18 - { - Unifier uni = new Unifier(lhsType, rhsType); - result = result.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(ArrayList::new)); - result1 = result1.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(LinkedList::new)); - - Function,? extends HashSet> applyUni = b -> b.stream().map( - x -> uni.apply(pair,x)).collect(Collectors.toCollection(HashSet::new)); - List>> oderConstraintsRet = new ArrayList<>(); - for(Set> oc : oderConstraints) { - //Set> ocRet = new HashSet<>(); - //for(Set cs : oc) { - Set> csRet = oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new)); - oderConstraintsRet.add(csRet); - //} - } - oderConstraints.replaceAll(oc -> oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new))); - /* - oderConstraints = oderConstraints.stream().map( - a -> a.stream().map(applyUni - //b -> b.stream().map( - // x -> uni.apply(pair,x)).collect(Collectors.toCollection(HashSet::new) ) - ).collect(Collectors.toCollection(HashSet::new)) - ).collect(Collectors.toList(ArrayList::new)); - } - */ - applied = true; - } - result.add(pair); - } - - return applied ? Optional.of(new HashSet<>(result)) : Optional.empty(); - } - - @Override - public Optional reduceWildcardLow(UnifyPair pair) { - if(pair.getPairOp() != PairOperator.SMALLERDOTWC) - return Optional.empty(); - - UnifyType lhsType = pair.getLhsType(); - UnifyType rhsType = pair.getRhsType(); - if(!(lhsType instanceof ExtendsType) || !(rhsType instanceof ExtendsType)) - return Optional.empty(); - - return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(), ((ExtendsType) rhsType).getExtendedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); - } - - @Override - public Optional reduceWildcardLowRight(UnifyPair pair) { - if(pair.getPairOp() != PairOperator.SMALLERDOTWC) - return Optional.empty(); - - UnifyType lhsType = pair.getLhsType(); - UnifyType rhsType = pair.getRhsType(); - if(!(lhsType instanceof ReferenceType) || !(rhsType instanceof ExtendsType)) - return Optional.empty(); - - return Optional.of(new UnifyPair(lhsType, ((ExtendsType) rhsType).getExtendedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); - } - - @Override - public Optional reduceWildcardUp(UnifyPair pair) { - if(pair.getPairOp() != PairOperator.SMALLERDOTWC) - return Optional.empty(); - - UnifyType lhsType = pair.getLhsType(); - UnifyType rhsType = pair.getRhsType(); - if(!(lhsType instanceof SuperType) || !(rhsType instanceof SuperType)) - return Optional.empty(); - - return Optional.of(new UnifyPair(((SuperType) rhsType).getSuperedType(), ((SuperType) lhsType).getSuperedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); - } - - @Override - public Optional reduceWildcardUpRight(UnifyPair pair) { - if(pair.getPairOp() != PairOperator.SMALLERDOTWC) - return Optional.empty(); - - UnifyType lhsType = pair.getLhsType(); - UnifyType rhsType = pair.getRhsType(); - if(!(lhsType instanceof ReferenceType) || !(rhsType instanceof SuperType)) - return Optional.empty(); - - return Optional.of(new UnifyPair(((SuperType) rhsType).getSuperedType(), lhsType, PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); - } - - /* PL 2018-03-06 auskommentiert sind mutmaßlich falsch - * vgl. JAVA_BSP/Wildcard6.java - @Override - public Optional reduceWildcardLowUp(UnifyPair pair) { - if(pair.getPairOp() != PairOperator.SMALLERDOTWC) - return Optional.empty(); - - UnifyType lhsType = pair.getLhsType(); - UnifyType rhsType = pair.getRhsType(); - if(!(lhsType instanceof ExtendsType) || !(rhsType instanceof SuperType)) - return Optional.empty(); - - return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(), ((SuperType) rhsType).getSuperedType(), PairOperator.EQUALSDOT)); - } - - @Override - public Optional reduceWildcardUpLow(UnifyPair pair) { - if(pair.getPairOp() != PairOperator.SMALLERDOTWC) - return Optional.empty(); - - UnifyType lhsType = pair.getLhsType(); - UnifyType rhsType = pair.getRhsType(); - if(!(lhsType instanceof SuperType) || !(rhsType instanceof ExtendsType)) - return Optional.empty(); - - return Optional.of(new UnifyPair(((SuperType) lhsType).getSuperedType(), ((ExtendsType) rhsType).getExtendedType(), PairOperator.EQUALSDOT)); - } - - - @Override - public Optional reduceWildcardLeft(UnifyPair pair) { - if(pair.getPairOp() != PairOperator.SMALLERDOTWC) - return Optional.empty(); - - UnifyType rhsType = pair.getRhsType(); - if(!(rhsType instanceof ReferenceType)) - return Optional.empty(); - - UnifyType lhsType = pair.getLhsType(); - - if(lhsType instanceof WildcardType) - return Optional.of(new UnifyPair(((WildcardType) lhsType).getWildcardedType(), rhsType, PairOperator.EQUALSDOT)); - - return Optional.empty(); - } - */ - @Override - public Optional> reduceFunN(UnifyPair pair) { - if((pair.getPairOp() != PairOperator.SMALLERDOT) - && (pair.getPairOp() != PairOperator.EQUALSDOT)) //PL 2017-10-03 hinzugefuegt - //da Regel auch fuer EQUALSDOT anwendbar - //TODO: fuer allen anderen Relationen noch pruefen - return Optional.empty(); - - UnifyType lhsType = pair.getLhsType(); - UnifyType rhsType = pair.getRhsType(); - - if(!(lhsType instanceof FunNType) || !(rhsType instanceof FunNType)) - return Optional.empty(); - - FunNType funNLhsType = (FunNType) lhsType; - FunNType funNRhsType = (FunNType) rhsType; - - if(funNLhsType.getN() != funNRhsType.getN()) - return Optional.empty(); - - Set result = new HashSet(); - if (pair.getPairOp() == PairOperator.SMALLERDOT) { - result.add(new UnifyPair(funNLhsType.getTypeParams().get(funNLhsType.getTypeParams().size()-1), funNRhsType.getTypeParams().get(funNRhsType.getTypeParams().size()-1), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); - for(int i = 0; i < funNLhsType.getTypeParams().size()-1; i++) { - result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), funNLhsType.getTypeParams().get(i), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); - } - } - else {// pair.getPairOp() == PairOperator.EQUALDOT - result.add(new UnifyPair(funNLhsType.getTypeParams().get(funNLhsType.getTypeParams().size()-1), funNRhsType.getTypeParams().get(funNRhsType.getTypeParams().size()-1), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); - for(int i = 0; i < funNLhsType.getTypeParams().size()-1; i++) { - result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), funNLhsType.getTypeParams().get(i), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); - } - } - result.stream().forEach(x -> { UnifyType l = x.getLhsType(); - if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); } - UnifyType r = x.getRhsType(); - if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); } - } ); - try { - logFile.write("FUNgreater: " + pair + "\n"); - logFile.write("FUNred: " + result + "\n"); - logFile.flush(); - } - catch (IOException e) { - System.out.println("logFile-Error"); - } - return Optional.of(result); - } - - - @Override - public Optional> greaterFunN(UnifyPair pair) { - if(pair.getPairOp() != PairOperator.SMALLERDOT) - return Optional.empty(); - - UnifyType lhsType = pair.getLhsType(); - UnifyType rhsType = pair.getRhsType(); - - if(!(lhsType instanceof FunNType) || !(rhsType instanceof PlaceholderType)) - return Optional.empty(); - - FunNType funNLhsType = (FunNType) lhsType; - - Set result = new HashSet(); - - Integer variance = ((PlaceholderType)rhsType).getVariance(); - Integer inversVariance = distributeVariance.inverseVariance(variance); - - UnifyType[] freshPlaceholders = new UnifyType[funNLhsType.getTypeParams().size()]; - for(int i = 0; i < freshPlaceholders.length-1; i++) { - freshPlaceholders[i] = PlaceholderType.freshPlaceholder(); - ((PlaceholderType)freshPlaceholders[i]).setVariance(inversVariance); - } - freshPlaceholders[freshPlaceholders.length-1] = PlaceholderType.freshPlaceholder(); - ((PlaceholderType)freshPlaceholders[freshPlaceholders.length-1]).setVariance(variance); - result.add(new UnifyPair(funNLhsType.getTypeParams().get(funNLhsType.getTypeParams().size()-1), freshPlaceholders[funNLhsType.getTypeParams().size()-1], PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); - - for(int i = 0; i < funNLhsType.getTypeParams().size()-1; i++) { - result.add(new UnifyPair(freshPlaceholders[i], funNLhsType.getTypeParams().get(i), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); - } - - result.add(new UnifyPair(rhsType, funNLhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); - - result.stream().forEach(x -> { UnifyType l = x.getLhsType(); - if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); } - UnifyType r = x.getRhsType(); - if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); } - } ); - try { - logFile.write("FUNgreater: " + pair + "\n"); - logFile.write("FUNgreater: " + result + "\n"); - logFile.flush(); - } - catch (IOException e) { - System.out.println("lofFile-Error"); - } - return Optional.of(result); - } - - @Override - public Optional> smallerFunN(UnifyPair pair) { - if(pair.getPairOp() != PairOperator.SMALLERDOT) - return Optional.empty(); - - UnifyType lhsType = pair.getLhsType(); - UnifyType rhsType = pair.getRhsType(); - - if(!(lhsType instanceof PlaceholderType) || !(rhsType instanceof FunNType)) - return Optional.empty(); - - FunNType funNRhsType = (FunNType) rhsType; - - Set result = new HashSet(); - - Integer variance = ((PlaceholderType)lhsType).getVariance(); - Integer inversVariance = distributeVariance.inverseVariance(variance); - - UnifyType[] freshPlaceholders = new UnifyType[funNRhsType.getTypeParams().size()]; - for(int i = 0; i < freshPlaceholders.length-1; i++) { - freshPlaceholders[i] = PlaceholderType.freshPlaceholder(); - ((PlaceholderType)freshPlaceholders[i]).setVariance(inversVariance); - } - freshPlaceholders[freshPlaceholders.length-1] = PlaceholderType.freshPlaceholder(); - ((PlaceholderType)freshPlaceholders[freshPlaceholders.length-1]).setVariance(variance); - - result.add(new UnifyPair(freshPlaceholders[funNRhsType.getTypeParams().size()-1], funNRhsType.getTypeParams().get(funNRhsType.getTypeParams().size()-1), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); - - for(int i = 0; i < funNRhsType.getTypeParams().size()-1; i++) { - result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), freshPlaceholders[i], PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); - } - - result.add(new UnifyPair(lhsType, funNRhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); - - result.stream().forEach(x -> { UnifyType l = x.getLhsType(); - if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); } - UnifyType r = x.getRhsType(); - if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); } - } ); - try { - logFile.write("FUNgreater: " + pair + "\n"); - logFile.write("FUNsmaller: " + result + "\n"); - logFile.flush(); - } - catch (IOException e) { - System.out.println("lofFile-Error"); - } - return Optional.of(result); - } - - @Override - public Optional reduceTph(UnifyPair pair) { - if(pair.getPairOp() != PairOperator.SMALLERDOTWC) - return Optional.empty(); - - UnifyType lhsType = pair.getLhsType(); - UnifyType rhsType = pair.getRhsType(); - if(!(lhsType instanceof PlaceholderType) || !(rhsType instanceof ReferenceType)) - return Optional.empty(); - - return Optional.of(new UnifyPair(lhsType, rhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); - } - - @Override - public Optional> reduceTphExt(UnifyPair pair) { - if(pair.getPairOp() != PairOperator.SMALLERDOTWC) - return Optional.empty(); - - UnifyType lhsType = pair.getLhsType(); - UnifyType rhsType = pair.getRhsType(); - if(!(lhsType instanceof ExtendsType) || !(rhsType instanceof PlaceholderType)) - return Optional.empty(); - - UnifyType extendedType = ((ExtendsType)lhsType).getExtendedType(); - - if (extendedType.equals(rhsType)) return Optional.empty(); //PL 2019-02-18 eingefügt ? extends a <.? a - - boolean isGen = extendedType instanceof PlaceholderType && !((PlaceholderType) extendedType).isGenerated(); - - Set result = new HashSet<>(); - if(isGen) - result.add(new UnifyPair(rhsType, lhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); - else { - UnifyType freshTph = PlaceholderType.freshPlaceholder(); - result.add(new UnifyPair(rhsType, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); - result.add(new UnifyPair(extendedType, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); - } - - return Optional.of(result); - } - - @Override - public Optional> reduceTphSup(UnifyPair pair) { - if(pair.getPairOp() != PairOperator.SMALLERDOTWC) - return Optional.empty(); - - UnifyType lhsType = pair.getLhsType(); - UnifyType rhsType = pair.getRhsType(); - if(!(lhsType instanceof SuperType) || !(rhsType instanceof PlaceholderType)) - return Optional.empty(); - - UnifyType superedType = ((SuperType)lhsType).getSuperedType(); - - if (superedType.equals(rhsType)) return Optional.empty(); //PL 2019-02-18 eingefügt ? super a <.? a - - boolean isGen = superedType instanceof PlaceholderType && !((PlaceholderType) superedType).isGenerated(); - - Set result = new HashSet<>(); - if(isGen) - result.add(new UnifyPair(rhsType, lhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); - else { - UnifyType freshTph = PlaceholderType.freshPlaceholder(); - result.add(new UnifyPair(rhsType, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); - Set fBounded = pair.getfBounded(); - fBounded.add(lhsType); - result.add(new UnifyPair(freshTph, superedType, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair(), fBounded)); - } - - return Optional.of(result); - } -} +package de.dhbwstuttgart.typeinference.unify; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; +import java.util.Queue; +import java.util.Set; +import java.util.Stack; +import java.util.function.Function; +import java.util.stream.Collectors; + +import de.dhbwstuttgart.exceptions.DebugException; +import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet; +import de.dhbwstuttgart.typeinference.unify.model.ExtendsType; +import de.dhbwstuttgart.typeinference.unify.model.FunNType; +import de.dhbwstuttgart.typeinference.unify.model.PairOperator; +import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; +import de.dhbwstuttgart.typeinference.unify.model.ReferenceType; +import de.dhbwstuttgart.typeinference.unify.model.SuperType; +import de.dhbwstuttgart.typeinference.unify.model.TypeParams; +import de.dhbwstuttgart.typeinference.unify.model.Unifier; +import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; +import de.dhbwstuttgart.typeinference.unify.model.UnifyType; +import de.dhbwstuttgart.typeinference.unify.model.WildcardType; +import de.dhbwstuttgart.typeinference.unify.distributeVariance; + +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; + +/** + * Implementation of the type inference rules. + * @author Florian Steurer + * + */ +public class RuleSet implements IRuleSet{ + + Writer logFile; + + public RuleSet() { + super(); + } + + RuleSet(Writer logFile) { + this.logFile = logFile; + } + + @Override + public Optional reduceUp(UnifyPair pair) { + // Check if reduce up is applicable + if(pair.getPairOp() != PairOperator.SMALLERDOT) + return Optional.empty(); + + UnifyType rhsType = pair.getRhsType(); + if(!(rhsType instanceof SuperType)) + return Optional.empty(); + + UnifyType lhsType = pair.getLhsType(); + if(!(lhsType instanceof ReferenceType) && !(lhsType instanceof PlaceholderType)) + return Optional.empty(); + + // Rule is applicable, unpack the SuperType + return Optional.of(new UnifyPair(lhsType, ((SuperType) rhsType).getSuperedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + } + + @Override + public Optional reduceLow(UnifyPair pair) { + // Check if rule is applicable + if(pair.getPairOp() != PairOperator.SMALLERDOT) + return Optional.empty(); + + UnifyType lhsType = pair.getLhsType(); + if(!(lhsType instanceof ExtendsType)) + return Optional.empty(); + + UnifyType rhsType = pair.getRhsType(); + if(!(rhsType instanceof ReferenceType) && !(rhsType instanceof PlaceholderType)) + return Optional.empty(); + + // Rule is applicable, unpack the ExtendsType + return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(), rhsType, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + } + + @Override + public Optional reduceUpLow(UnifyPair pair) { + // Check if rule is applicable + if(pair.getPairOp() != PairOperator.SMALLERDOT) + return Optional.empty(); + + UnifyType lhsType = pair.getLhsType(); + if(!(lhsType instanceof ExtendsType)) + return Optional.empty(); + + UnifyType rhsType = pair.getRhsType(); + if(!(rhsType instanceof SuperType)) + return Optional.empty(); + + // Rule is applicable, unpack both sides + return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(),((SuperType) rhsType).getSuperedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + } + + @Override + public Optional> reduceExt(UnifyPair pair, IFiniteClosure fc) { + if(pair.getPairOp() != PairOperator.SMALLERDOTWC) + return Optional.empty(); + + UnifyType x = pair.getLhsType(); + UnifyType sTypeX; + + if(x instanceof ReferenceType) + sTypeX = x; + else if(x instanceof ExtendsType) + sTypeX = ((ExtendsType) x).getExtendedType(); + else + return Optional.empty(); + + UnifyType extY = pair.getRhsType(); + + if(!(extY instanceof ExtendsType)) + return Optional.empty(); + + if(x.getTypeParams().empty() || extY.getTypeParams().size() != x.getTypeParams().size()) + return Optional.empty(); + + UnifyType xFromFc = fc.getLeftHandedType(sTypeX.getName()).orElse(null); + + if(xFromFc == null || !xFromFc.getTypeParams().arePlaceholders()) + return Optional.empty(); + + if(x instanceof ExtendsType) + xFromFc = new ExtendsType(xFromFc); + + UnifyType extYFromFc = fc.grArg(xFromFc, new HashSet<>()).stream().filter(t -> t.getName().equals(extY.getName())).filter(t -> t.getTypeParams().arePlaceholders()).findAny().orElse(null); + + if(extYFromFc == null || extYFromFc.getTypeParams() != xFromFc.getTypeParams()) + return Optional.empty(); + + TypeParams extYParams = extY.getTypeParams(); + TypeParams xParams = x.getTypeParams(); + + int[] pi = pi(xParams, extYParams); + + if(pi.length == 0) + return Optional.empty(); + + Set result = new HashSet<>(); + + for(int rhsIdx = 0; rhsIdx < extYParams.size(); rhsIdx++) + result.add(new UnifyPair(xParams.get(pi[rhsIdx]), extYParams.get(rhsIdx), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); + + return Optional.of(result); + } + + @Override + public Optional> reduceSup(UnifyPair pair, IFiniteClosure fc) { + if(pair.getPairOp() != PairOperator.SMALLERDOTWC) + return Optional.empty(); + + UnifyType x = pair.getLhsType(); + UnifyType sTypeX; + + if(x instanceof ReferenceType) + sTypeX = x; + else if(x instanceof SuperType) + sTypeX = ((SuperType) x).getSuperedType(); + else + return Optional.empty(); + + UnifyType supY = pair.getRhsType(); + + if(!(supY instanceof SuperType)) + return Optional.empty(); + + if(x.getTypeParams().empty() || supY.getTypeParams().size() != x.getTypeParams().size()) + return Optional.empty(); + + UnifyType xFromFc = fc.getLeftHandedType(sTypeX.getName()).orElse(null); + + if(xFromFc == null || !xFromFc.getTypeParams().arePlaceholders()) + return Optional.empty(); + + if(x instanceof SuperType) + xFromFc = new SuperType(xFromFc); + + UnifyType supYFromFc = fc.grArg(xFromFc, new HashSet<>()).stream().filter(t -> t.getName().equals(supY.getName())).filter(t -> t.getTypeParams().arePlaceholders()).findAny().orElse(null); + + if(supYFromFc == null || supYFromFc.getTypeParams() != xFromFc.getTypeParams()) + return Optional.empty(); + + TypeParams supYParams = supY.getTypeParams(); + TypeParams xParams = x.getTypeParams(); + Set result = new HashSet<>(); + + int[] pi = pi(xParams, supYParams); + + if(pi.length == 0) + return Optional.empty(); + + for(int rhsIdx = 0; rhsIdx < supYParams.size(); rhsIdx++) + result.add(new UnifyPair(supYParams.get(rhsIdx), xParams.get(pi[rhsIdx]), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); + + return Optional.of(result); + } + + @Override + public Optional> reduceEq(UnifyPair pair) { + if(pair.getPairOp() != PairOperator.SMALLERDOTWC) + return Optional.empty(); + + UnifyType lhsType = pair.getLhsType(); + if(lhsType instanceof PlaceholderType || lhsType.getTypeParams().empty()) + return Optional.empty(); + + UnifyType rhsType = pair.getRhsType(); + + if(!rhsType.getName().equals(lhsType.getName())) + return Optional.empty(); + + if(rhsType instanceof PlaceholderType || lhsType instanceof PlaceholderType || rhsType.getTypeParams().empty()) + return Optional.empty(); + + if(rhsType.getTypeParams().size() != lhsType.getTypeParams().size()) + return Optional.empty(); + + // Keine Permutation wie im Paper nötig + Set result = new HashSet<>(); + TypeParams lhsTypeParams = lhsType.getTypeParams(); + TypeParams rhsTypeParams = rhsType.getTypeParams(); + + for(int i = 0; i < lhsTypeParams.size(); i++) + result.add(new UnifyPair(lhsTypeParams.get(i), rhsTypeParams.get(i), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); + + return Optional.of(result); + } + + @Override + public Optional> reduce1(UnifyPair pair, IFiniteClosure fc) { + if(pair.getPairOp() != PairOperator.SMALLERDOT) + return Optional.empty(); + + UnifyType c = pair.getLhsType(); + if(!(c instanceof ReferenceType)) + return Optional.empty(); + + UnifyType d = pair.getRhsType(); + if(!(d instanceof ReferenceType)) + return Optional.empty(); + + ReferenceType lhsSType = (ReferenceType) c; + ReferenceType rhsSType = (ReferenceType) d; + + //try { + // logFile.write("PAIR Rules: " + pair + "\n"); + // logFile.flush(); + //} + //catch (IOException e) { } + + if(lhsSType.getTypeParams().empty() || lhsSType.getTypeParams().size() != rhsSType.getTypeParams().size()) + return Optional.empty(); + + UnifyType cFromFc = fc.getLeftHandedType(c.getName()).orElse(null); + //2018-02-23: liefert Vector>: Das kann nicht sein. + + //NOCHMAL UEBERPRUEFEN + //PL 18-02-09 Eingfuegt Anfang + //C und D koennen auch gleich sein. + if (c.getName().equals(d.getName())) { + Set result = new HashSet<>(); + TypeParams rhsTypeParams = d.getTypeParams(); + TypeParams lhsTypeParams = c.getTypeParams(); + for(int rhsIdx = 0; rhsIdx < c.getTypeParams().size(); rhsIdx++) + result.add(new UnifyPair(lhsTypeParams.get(rhsIdx), rhsTypeParams.get(rhsIdx), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); + + return Optional.of(result); + } + //PL 18-02-09 Eingfuegt ENDE + + //try { + // logFile.write("cFromFc: " + cFromFc); + // logFile.flush(); + //} + //catch (IOException e) { } + + if(cFromFc == null || !cFromFc.getTypeParams().arePlaceholders()) + return Optional.empty(); + + UnifyType dFromFc = fc.getAncestors(cFromFc).stream().filter(x -> x.getName().equals(d.getName())).findAny().orElse(null); + + //try { + // logFile.write("cFromFc: " + cFromFc); + // logFile.flush(); + //} + //catch (IOException e) { } + + if(dFromFc == null || !dFromFc.getTypeParams().arePlaceholders() || dFromFc.getTypeParams().size() != cFromFc.getTypeParams().size()) + return Optional.empty(); + //System.out.println("cFromFc: " + cFromFc); + //System.out.println("dFromFc: " + dFromFc); + int[] pi = pi(cFromFc.getTypeParams(), dFromFc.getTypeParams()); + + if(pi.length == 0) + return Optional.empty(); + + TypeParams rhsTypeParams = d.getTypeParams(); + TypeParams lhsTypeParams = c.getTypeParams(); + Set result = new HashSet<>(); + + for(int rhsIdx = 0; rhsIdx < rhsTypeParams.size(); rhsIdx++) + result.add(new UnifyPair(lhsTypeParams.get(pi[rhsIdx]), rhsTypeParams.get(rhsIdx), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); + + return Optional.of(result); + } + + @Override + public Optional> reduce2(UnifyPair pair) { + if(pair.getPairOp() != PairOperator.EQUALSDOT) + return Optional.empty(); + + UnifyType lhsType = pair.getLhsType(); + ReferenceType lhsSType; + UnifyType rhsType = pair.getRhsType(); + ReferenceType rhsSType; + + if ((lhsType instanceof ReferenceType) && (rhsType instanceof ReferenceType)) { + lhsSType = (ReferenceType) lhsType; + rhsSType = (ReferenceType) rhsType; + } + else if (((lhsType instanceof ExtendsType) && (rhsType instanceof ExtendsType)) + || ((lhsType instanceof SuperType) && (rhsType instanceof SuperType))) { + UnifyType lhsSTypeRaw = ((WildcardType) lhsType).getWildcardedType(); + UnifyType rhsSTypeRaw = ((WildcardType) rhsType).getWildcardedType(); + if ((lhsSTypeRaw instanceof ReferenceType) && (rhsSTypeRaw instanceof ReferenceType)) { + lhsSType = (ReferenceType) lhsSTypeRaw; + rhsSType = (ReferenceType) rhsSTypeRaw; + } + else + return Optional.empty(); + } + else + return Optional.empty(); + + if(lhsSType.getTypeParams().empty()) + return Optional.empty(); + + /* PL 2018-01-22 in obere Teil integriert + UnifyType rhsType = pair.getRhsType(); + ReferenceType rhsSType; + + if(rhsType instanceof ReferenceType) + rhsSType = (ReferenceType) rhsType; + else if(rhsType instanceof WildcardType) { + UnifyType rhsSTypeRaw = ((WildcardType) rhsType).getWildcardedType(); + if(rhsSTypeRaw instanceof ReferenceType) + rhsSType = (ReferenceType) rhsSTypeRaw; + else + return Optional.empty(); + } + else + return Optional.empty(); + */ + + if(!rhsSType.getName().equals(lhsSType.getName())) + return Optional.empty(); + + if(!(lhsSType.getTypeParams().size()==rhsSType.getTypeParams().size()))throw new DebugException("Fehler in Unifizierung"+ " " + lhsSType.toString() + " " + rhsSType.toString()); + //if(rhsSType.getTypeParams().size() != lhsSType.getTypeParams().size()) + // return Optional.empty(); + + Set result = new HashSet<>(); + + TypeParams rhsTypeParams = rhsSType.getTypeParams(); + TypeParams lhsTypeParams = lhsSType.getTypeParams(); + for(int i = 0; i < rhsTypeParams.size(); i++) + result.add(new UnifyPair(lhsTypeParams.get(i), rhsTypeParams.get(i), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); + + return Optional.of(result); + } + + @Override + public boolean erase1(UnifyPair pair, IFiniteClosure fc) { + if((pair.getPairOp() != PairOperator.SMALLERDOT) && (pair.getPairOp() != PairOperator.SMALLERNEQDOT)) + return false; + + if (pair.getPairOp() == PairOperator.SMALLERNEQDOT) { + UnifyType lhs = pair.getLhsType(); + UnifyType rhs = pair.getRhsType(); + if (lhs instanceof WildcardType) { + lhs = ((WildcardType)lhs).getWildcardedType(); + } + if (rhs instanceof WildcardType) { + rhs = ((WildcardType)rhs).getWildcardedType(); + } + + if (lhs.equals(rhs)){ + return false; + } + } + + UnifyType lhsType = pair.getLhsType(); + if(!(lhsType instanceof ReferenceType) && !(lhsType instanceof PlaceholderType)) + return false; + + UnifyType rhsType = pair.getRhsType(); + if(!(rhsType instanceof ReferenceType) && !(rhsType instanceof PlaceholderType)) + return false; + + return fc.greater(lhsType, new HashSet<>()).contains(rhsType); + } + + @Override + public boolean erase2(UnifyPair pair, IFiniteClosure fc) { + if(pair.getPairOp() != PairOperator.SMALLERDOTWC) + return false; + + UnifyType lhsType = pair.getLhsType(); + UnifyType rhsType = pair.getRhsType(); + + return fc.grArg(lhsType, new HashSet<>()).contains(rhsType); + } + + @Override + public boolean erase3(UnifyPair pair) { + if(pair.getPairOp() != PairOperator.EQUALSDOT) + return false; + + return pair.getLhsType().equals(pair.getRhsType()); + } + + @Override + public Optional swap(UnifyPair pair) { + if(pair.getPairOp() != PairOperator.EQUALSDOT) + return Optional.empty(); + + if(pair.getLhsType() instanceof PlaceholderType) + return Optional.empty(); + + if(!(pair.getRhsType() instanceof PlaceholderType)) + return Optional.empty(); + + return Optional.of(new UnifyPair(pair.getRhsType(), pair.getLhsType(), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); + } + + @Override + public Optional adapt(UnifyPair pair, IFiniteClosure fc) { + if(pair.getPairOp() != PairOperator.SMALLERDOT) + return Optional.empty(); + + UnifyType typeD = pair.getLhsType(); + if(!(typeD instanceof ReferenceType)) + return Optional.empty(); + + UnifyType typeDs = pair.getRhsType(); + if(!(typeDs instanceof ReferenceType)) + return Optional.empty(); + + /*if(typeD.getTypeParams().size() == 0 || typeDs.getTypeParams().size() == 0) + return Optional.empty();*/ + + if(typeD.getName().equals(typeDs.getName())) + return Optional.empty(); + + + Optional opt = fc.getLeftHandedType(typeD.getName()); + if(!opt.isPresent()) + return Optional.empty(); + + // The generic Version of Type D (D) + UnifyType typeDgen = opt.get(); + + // Actually greater+ because the types are ensured to have different names + Set greater = fc.getAncestors(typeDgen); + opt = greater.stream().filter(x -> x.getName().equals(typeDs.getName())).findAny(); + + if(!opt.isPresent()) + return Optional.empty(); + + UnifyType newLhs = opt.get(); + + TypeParams typeDParams = typeD.getTypeParams(); + TypeParams typeDgenParams = typeDgen.getTypeParams(); + + //System.out.println("Pair: " +pair); + //System.out.println("typeD: " +typeD); + //System.out.println("typeDParams: " +typeDParams); + //System.out.println("typeDgen: " +typeD); + //System.out.println("typeDgenParams: " +typeDgenParams); + Unifier unif = Unifier.identity(); + for(int i = 0; i < typeDParams.size(); i++) { + //System.out.println("ADAPT" +typeDgenParams); + if (typeDgenParams.get(i) instanceof PlaceholderType) + unif.add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i)); + else System.out.println("ERROR"); + } + return Optional.of(new UnifyPair(unif.apply(newLhs), typeDs, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + } + + @Override + public Optional adaptExt(UnifyPair pair, IFiniteClosure fc) { + if(pair.getPairOp() != PairOperator.SMALLERDOTWC) + return Optional.empty(); + + UnifyType typeD = pair.getLhsType(); + if(!(typeD instanceof ReferenceType) && !(typeD instanceof ExtendsType)) + return Optional.empty(); + + UnifyType typeExtDs = pair.getRhsType(); + if(!(typeExtDs instanceof ExtendsType)) + return Optional.empty(); + + if(typeD.getTypeParams().size() == 0 || typeExtDs.getTypeParams().size() == 0) + return Optional.empty(); + + UnifyType typeDgen; + if(typeD instanceof ReferenceType) + typeDgen = fc.getLeftHandedType(typeD.getName()).orElse(null); + else { + Optional opt = fc.getLeftHandedType(((ExtendsType) typeD).getExtendedType().getName()); + typeDgen = opt.isPresent() ? new ExtendsType(opt.get()) : null; + } + + if(typeDgen == null) + return Optional.empty(); + + Set grArg = fc.grArg(typeDgen, new HashSet<>()); + + Optional opt = grArg.stream().filter(x -> x.getName().equals(typeExtDs.getName())).findAny(); + + if(!opt.isPresent()) + return Optional.empty(); + + UnifyType newLhs = ((ExtendsType) opt.get()).getExtendedType(); + + TypeParams typeDParams = typeD.getTypeParams(); + TypeParams typeDgenParams = typeDgen.getTypeParams(); + + Unifier unif = new Unifier((PlaceholderType) typeDgenParams.get(0), typeDParams.get(0)); + for(int i = 1; i < typeDParams.size(); i++) + unif.add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i)); + + return Optional.of(new UnifyPair(unif.apply(newLhs), typeExtDs, PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); + } + + @Override + public Optional adaptSup(UnifyPair pair, IFiniteClosure fc) { + if(pair.getPairOp() != PairOperator.SMALLERDOTWC) + return Optional.empty(); + + UnifyType typeDs = pair.getLhsType(); + if(!(typeDs instanceof ReferenceType) && !(typeDs instanceof SuperType)) + return Optional.empty(); + + UnifyType typeSupD = pair.getRhsType(); + if(!(typeSupD instanceof SuperType)) + return Optional.empty(); + + if(typeDs.getTypeParams().size() == 0 || typeSupD.getTypeParams().size() == 0) + return Optional.empty(); + + + Optional opt = fc.getLeftHandedType(((SuperType) typeSupD).getSuperedType().getName()); + + if(!opt.isPresent()) + return Optional.empty(); + + UnifyType typeDgen = opt.get(); + UnifyType typeSupDgen = new SuperType(typeDgen); + + // Use of smArg instead of grArg because + // a in grArg(b) => b in smArg(a) + Set smArg = fc.smArg(typeSupDgen, new HashSet<>()); + opt = smArg.stream().filter(x -> x.getName().equals(typeDs.getName())).findAny(); + + if(!opt.isPresent()) + return Optional.empty(); + + // New RHS + UnifyType newRhs = null; + if(typeDs instanceof ReferenceType) + newRhs = new ExtendsType(typeDs); + else + newRhs = new ExtendsType(((SuperType) typeDs).getSuperedType()); + + // New LHS + UnifyType newLhs = opt.get(); + TypeParams typeDParams = typeSupD.getTypeParams(); + TypeParams typeSupDsgenParams = typeSupDgen.getTypeParams(); + + Unifier unif = new Unifier((PlaceholderType) typeSupDsgenParams.get(0), typeDParams.get(0)); + for(int i = 1; i < typeDParams.size(); i++) + unif.add((PlaceholderType) typeSupDsgenParams.get(i), typeDParams.get(i)); + + return Optional.of(new UnifyPair(unif.apply(newLhs), newRhs, PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); + } + + /** + * Finds the permutation pi of the type arguments of two types based on the finite closure + * @param cArgs The type which arguments are permuted + * @param dArgs The other type + * @return An array containing the values of pi for every type argument of C or an empty array if the search failed. + */ + private int[] pi(TypeParams cArgs, TypeParams dArgs) { + if(!(cArgs.size()==dArgs.size()))throw new DebugException("Fehler in Unifizierung"); + + int[] permutation = new int[dArgs.size()]; + + boolean succ = true; + for (int dArgIdx = 0; dArgIdx < dArgs.size() && succ; dArgIdx++) { + UnifyType dArg = dArgs.get(dArgIdx); + succ = false; + for (int pi = 0; pi < cArgs.size(); pi++) + if (cArgs.get(pi).getName().equals(dArg.getName())) { + permutation[dArgIdx] = pi; + succ = true; + break; + } + } + + return succ ? permutation : new int[0]; + } + + public Optional> subst(Set pairs) { + return subst(pairs, new ArrayList<>()); + } + + @Override + public Optional> subst(Set pairs, List>> oderConstraints) { + HashMap typeMap = new HashMap<>(); + + Stack occuringTypes = new Stack<>(); + + for(UnifyPair pair : pairs) { + occuringTypes.push(pair.getLhsType()); + occuringTypes.push(pair.getRhsType()); + } + + while(!occuringTypes.isEmpty()) { + UnifyType t1 = occuringTypes.pop(); + if(!typeMap.containsKey(t1)) + typeMap.put(t1, 0); + typeMap.put(t1, typeMap.get(t1)+1); + + if(t1 instanceof ExtendsType) + occuringTypes.push(((ExtendsType) t1).getExtendedType()); + if(t1 instanceof SuperType) + occuringTypes.push(((SuperType) t1).getSuperedType()); + else + t1.getTypeParams().forEach(x -> occuringTypes.push(x)); + } + + Queue result1 = new LinkedList(pairs); + ArrayList result = new ArrayList(); + boolean applied = false; + + while(!result1.isEmpty()) { + UnifyPair pair = result1.poll(); + PlaceholderType lhsType = null; + UnifyType rhsType; + + if(pair.getPairOp() == PairOperator.EQUALSDOT + && pair.getLhsType() instanceof PlaceholderType) + lhsType = (PlaceholderType) pair.getLhsType(); + rhsType = pair.getRhsType(); //PL eingefuegt 2017-09-29 statt !((rhsType = pair.getRhsType()) instanceof PlaceholderType) + if(lhsType != null + //&& !((rhsType = pair.getRhsType()) instanceof PlaceholderType) //PL geloescht am 2017-09-29 Begründung: auch Typvariablen muessen ersetzt werden. + && typeMap.get(lhsType) > 1 // The type occurs in more pairs in the set than just the recent pair. + && !rhsType.getTypeParams().occurs(lhsType) + && !((rhsType instanceof WildcardType) && ((WildcardType)rhsType).getWildcardedType().equals(lhsType))) //PL eigefuegt 2018-02-18 + { + Unifier uni = new Unifier(lhsType, rhsType); + result = result.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(ArrayList::new)); + result1 = result1.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(LinkedList::new)); + + Function,? extends HashSet> applyUni = b -> b.stream().map( + x -> uni.apply(pair,x)).collect(Collectors.toCollection(HashSet::new)); + List>> oderConstraintsRet = new ArrayList<>(); + for(Set> oc : oderConstraints) { + //Set> ocRet = new HashSet<>(); + //for(Set cs : oc) { + Set> csRet = oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new)); + oderConstraintsRet.add(csRet); + //} + } + oderConstraints.replaceAll(oc -> oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new))); + /* + oderConstraints = oderConstraints.stream().map( + a -> a.stream().map(applyUni + //b -> b.stream().map( + // x -> uni.apply(pair,x)).collect(Collectors.toCollection(HashSet::new) ) + ).collect(Collectors.toCollection(HashSet::new)) + ).collect(Collectors.toList(ArrayList::new)); + } + */ + applied = true; + } + result.add(pair); + } + + return applied ? Optional.of(new HashSet<>(result)) : Optional.empty(); + } + + @Override + public Optional reduceWildcardLow(UnifyPair pair) { + if(pair.getPairOp() != PairOperator.SMALLERDOTWC) + return Optional.empty(); + + UnifyType lhsType = pair.getLhsType(); + UnifyType rhsType = pair.getRhsType(); + if(!(lhsType instanceof ExtendsType) || !(rhsType instanceof ExtendsType)) + return Optional.empty(); + + return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(), ((ExtendsType) rhsType).getExtendedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + } + + @Override + public Optional reduceWildcardLowRight(UnifyPair pair) { + if(pair.getPairOp() != PairOperator.SMALLERDOTWC) + return Optional.empty(); + + UnifyType lhsType = pair.getLhsType(); + UnifyType rhsType = pair.getRhsType(); + if(!(lhsType instanceof ReferenceType) || !(rhsType instanceof ExtendsType)) + return Optional.empty(); + + return Optional.of(new UnifyPair(lhsType, ((ExtendsType) rhsType).getExtendedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + } + + @Override + public Optional reduceWildcardUp(UnifyPair pair) { + if(pair.getPairOp() != PairOperator.SMALLERDOTWC) + return Optional.empty(); + + UnifyType lhsType = pair.getLhsType(); + UnifyType rhsType = pair.getRhsType(); + if(!(lhsType instanceof SuperType) || !(rhsType instanceof SuperType)) + return Optional.empty(); + + return Optional.of(new UnifyPair(((SuperType) rhsType).getSuperedType(), ((SuperType) lhsType).getSuperedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + } + + @Override + public Optional reduceWildcardUpRight(UnifyPair pair) { + if(pair.getPairOp() != PairOperator.SMALLERDOTWC) + return Optional.empty(); + + UnifyType lhsType = pair.getLhsType(); + UnifyType rhsType = pair.getRhsType(); + if(!(lhsType instanceof ReferenceType) || !(rhsType instanceof SuperType)) + return Optional.empty(); + + return Optional.of(new UnifyPair(((SuperType) rhsType).getSuperedType(), lhsType, PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); + } + + /* PL 2018-03-06 auskommentiert sind mutmaßlich falsch + * vgl. JAVA_BSP/Wildcard6.java + @Override + public Optional reduceWildcardLowUp(UnifyPair pair) { + if(pair.getPairOp() != PairOperator.SMALLERDOTWC) + return Optional.empty(); + + UnifyType lhsType = pair.getLhsType(); + UnifyType rhsType = pair.getRhsType(); + if(!(lhsType instanceof ExtendsType) || !(rhsType instanceof SuperType)) + return Optional.empty(); + + return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(), ((SuperType) rhsType).getSuperedType(), PairOperator.EQUALSDOT)); + } + + @Override + public Optional reduceWildcardUpLow(UnifyPair pair) { + if(pair.getPairOp() != PairOperator.SMALLERDOTWC) + return Optional.empty(); + + UnifyType lhsType = pair.getLhsType(); + UnifyType rhsType = pair.getRhsType(); + if(!(lhsType instanceof SuperType) || !(rhsType instanceof ExtendsType)) + return Optional.empty(); + + return Optional.of(new UnifyPair(((SuperType) lhsType).getSuperedType(), ((ExtendsType) rhsType).getExtendedType(), PairOperator.EQUALSDOT)); + } + + + @Override + public Optional reduceWildcardLeft(UnifyPair pair) { + if(pair.getPairOp() != PairOperator.SMALLERDOTWC) + return Optional.empty(); + + UnifyType rhsType = pair.getRhsType(); + if(!(rhsType instanceof ReferenceType)) + return Optional.empty(); + + UnifyType lhsType = pair.getLhsType(); + + if(lhsType instanceof WildcardType) + return Optional.of(new UnifyPair(((WildcardType) lhsType).getWildcardedType(), rhsType, PairOperator.EQUALSDOT)); + + return Optional.empty(); + } + */ + @Override + public Optional> reduceFunN(UnifyPair pair) { + if((pair.getPairOp() != PairOperator.SMALLERDOT) + && (pair.getPairOp() != PairOperator.EQUALSDOT)) //PL 2017-10-03 hinzugefuegt + //da Regel auch fuer EQUALSDOT anwendbar + //TODO: fuer allen anderen Relationen noch pruefen + return Optional.empty(); + + UnifyType lhsType = pair.getLhsType(); + UnifyType rhsType = pair.getRhsType(); + + if(!(lhsType instanceof FunNType) || !(rhsType instanceof FunNType)) + return Optional.empty(); + + FunNType funNLhsType = (FunNType) lhsType; + FunNType funNRhsType = (FunNType) rhsType; + + if(funNLhsType.getN() != funNRhsType.getN()) + return Optional.empty(); + + Set result = new HashSet(); + if (pair.getPairOp() == PairOperator.SMALLERDOT) { + result.add(new UnifyPair(funNLhsType.getTypeParams().get(funNLhsType.getTypeParams().size()-1), funNRhsType.getTypeParams().get(funNRhsType.getTypeParams().size()-1), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + for(int i = 0; i < funNLhsType.getTypeParams().size()-1; i++) { + result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), funNLhsType.getTypeParams().get(i), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + } + } + else {// pair.getPairOp() == PairOperator.EQUALDOT + result.add(new UnifyPair(funNLhsType.getTypeParams().get(funNLhsType.getTypeParams().size()-1), funNRhsType.getTypeParams().get(funNRhsType.getTypeParams().size()-1), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); + for(int i = 0; i < funNLhsType.getTypeParams().size()-1; i++) { + result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), funNLhsType.getTypeParams().get(i), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); + } + } + result.stream().forEach(x -> { UnifyType l = x.getLhsType(); + if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); } + UnifyType r = x.getRhsType(); + if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); } + } ); + try { + logFile.write("FUNgreater: " + pair + "\n"); + logFile.write("FUNred: " + result + "\n"); + logFile.flush(); + } + catch (IOException e) { + System.out.println("logFile-Error"); + } + return Optional.of(result); + } + + + @Override + public Optional> greaterFunN(UnifyPair pair) { + if(pair.getPairOp() != PairOperator.SMALLERDOT) + return Optional.empty(); + + UnifyType lhsType = pair.getLhsType(); + UnifyType rhsType = pair.getRhsType(); + + if(!(lhsType instanceof FunNType) || !(rhsType instanceof PlaceholderType)) + return Optional.empty(); + + FunNType funNLhsType = (FunNType) lhsType; + + Set result = new HashSet(); + + Integer variance = ((PlaceholderType)rhsType).getVariance(); + Integer inversVariance = distributeVariance.inverseVariance(variance); + + UnifyType[] freshPlaceholders = new UnifyType[funNLhsType.getTypeParams().size()]; + for(int i = 0; i < freshPlaceholders.length-1; i++) { + freshPlaceholders[i] = PlaceholderType.freshPlaceholder(); + ((PlaceholderType)freshPlaceholders[i]).setVariance(inversVariance); + } + freshPlaceholders[freshPlaceholders.length-1] = PlaceholderType.freshPlaceholder(); + ((PlaceholderType)freshPlaceholders[freshPlaceholders.length-1]).setVariance(variance); + result.add(new UnifyPair(funNLhsType.getTypeParams().get(funNLhsType.getTypeParams().size()-1), freshPlaceholders[funNLhsType.getTypeParams().size()-1], PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + + for(int i = 0; i < funNLhsType.getTypeParams().size()-1; i++) { + result.add(new UnifyPair(freshPlaceholders[i], funNLhsType.getTypeParams().get(i), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + } + + result.add(new UnifyPair(rhsType, funNLhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); + + result.stream().forEach(x -> { UnifyType l = x.getLhsType(); + if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); } + UnifyType r = x.getRhsType(); + if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); } + } ); + try { + logFile.write("FUNgreater: " + pair + "\n"); + logFile.write("FUNgreater: " + result + "\n"); + logFile.flush(); + } + catch (IOException e) { + System.out.println("lofFile-Error"); + } + return Optional.of(result); + } + + @Override + public Optional> smallerFunN(UnifyPair pair) { + if(pair.getPairOp() != PairOperator.SMALLERDOT) + return Optional.empty(); + + UnifyType lhsType = pair.getLhsType(); + UnifyType rhsType = pair.getRhsType(); + + if(!(lhsType instanceof PlaceholderType) || !(rhsType instanceof FunNType)) + return Optional.empty(); + + FunNType funNRhsType = (FunNType) rhsType; + + Set result = new HashSet(); + + Integer variance = ((PlaceholderType)lhsType).getVariance(); + Integer inversVariance = distributeVariance.inverseVariance(variance); + + UnifyType[] freshPlaceholders = new UnifyType[funNRhsType.getTypeParams().size()]; + for(int i = 0; i < freshPlaceholders.length-1; i++) { + freshPlaceholders[i] = PlaceholderType.freshPlaceholder(); + ((PlaceholderType)freshPlaceholders[i]).setVariance(inversVariance); + } + freshPlaceholders[freshPlaceholders.length-1] = PlaceholderType.freshPlaceholder(); + ((PlaceholderType)freshPlaceholders[freshPlaceholders.length-1]).setVariance(variance); + + result.add(new UnifyPair(freshPlaceholders[funNRhsType.getTypeParams().size()-1], funNRhsType.getTypeParams().get(funNRhsType.getTypeParams().size()-1), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + + for(int i = 0; i < funNRhsType.getTypeParams().size()-1; i++) { + result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), freshPlaceholders[i], PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + } + + result.add(new UnifyPair(lhsType, funNRhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); + + result.stream().forEach(x -> { UnifyType l = x.getLhsType(); + if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); } + UnifyType r = x.getRhsType(); + if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); } + } ); + try { + logFile.write("FUNgreater: " + pair + "\n"); + logFile.write("FUNsmaller: " + result + "\n"); + logFile.flush(); + } + catch (IOException e) { + System.out.println("lofFile-Error"); + } + return Optional.of(result); + } + + @Override + public Optional reduceTph(UnifyPair pair) { + if(pair.getPairOp() != PairOperator.SMALLERDOTWC) + return Optional.empty(); + + UnifyType lhsType = pair.getLhsType(); + UnifyType rhsType = pair.getRhsType(); + if(!(lhsType instanceof PlaceholderType) || !(rhsType instanceof ReferenceType)) + return Optional.empty(); + + return Optional.of(new UnifyPair(lhsType, rhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); + } + + @Override + public Optional> reduceTphExt(UnifyPair pair) { + if(pair.getPairOp() != PairOperator.SMALLERDOTWC) + return Optional.empty(); + + UnifyType lhsType = pair.getLhsType(); + UnifyType rhsType = pair.getRhsType(); + if(!(lhsType instanceof ExtendsType) || !(rhsType instanceof PlaceholderType)) + return Optional.empty(); + + UnifyType extendedType = ((ExtendsType)lhsType).getExtendedType(); + + if (extendedType.equals(rhsType)) return Optional.empty(); //PL 2019-02-18 eingefügt ? extends a <.? a + + boolean isGen = extendedType instanceof PlaceholderType && !((PlaceholderType) extendedType).isGenerated(); + + Set result = new HashSet<>(); + if(isGen) + result.add(new UnifyPair(rhsType, lhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); + else { + UnifyType freshTph = PlaceholderType.freshPlaceholder(); + result.add(new UnifyPair(rhsType, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); + result.add(new UnifyPair(extendedType, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + } + + return Optional.of(result); + } + + @Override + public Optional> reduceTphSup(UnifyPair pair) { + if(pair.getPairOp() != PairOperator.SMALLERDOTWC) + return Optional.empty(); + + UnifyType lhsType = pair.getLhsType(); + UnifyType rhsType = pair.getRhsType(); + if(!(lhsType instanceof SuperType) || !(rhsType instanceof PlaceholderType)) + return Optional.empty(); + + UnifyType superedType = ((SuperType)lhsType).getSuperedType(); + + if (superedType.equals(rhsType)) return Optional.empty(); //PL 2019-02-18 eingefügt ? super a <.? a + + boolean isGen = superedType instanceof PlaceholderType && !((PlaceholderType) superedType).isGenerated(); + + Set result = new HashSet<>(); + if(isGen) + result.add(new UnifyPair(rhsType, lhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); + else { + UnifyType freshTph = PlaceholderType.freshPlaceholder(); + result.add(new UnifyPair(rhsType, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); + Set fBounded = pair.getfBounded(); + fBounded.add(lhsType); + result.add(new UnifyPair(freshTph, superedType, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair(), fBounded)); + } + + return Optional.of(result); + } +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index 62404b302..6b0455479 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -1,121 +1,121 @@ -package de.dhbwstuttgart.typeinference.unify; - -import java.io.FileWriter; -import java.io.IOException; -import java.io.Writer; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.concurrent.ForkJoinPool; - -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.typeinference.constraints.Constraint; -import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; -import de.dhbwstuttgart.typeinference.constraints.Pair; -import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; -import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; -import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; - -public class TypeUnify { - - /** - * unify parallel ohne result modell - * @param undConstrains - * @param oderConstraints - * @param fc - * @param logFile - * @param log - * @param cons - * @return - */ - public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); - ForkJoinPool pool = new ForkJoinPool(); - pool.invoke(unifyTask); - Set> res = unifyTask.join(); - try { - logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements + "\n"); - logFile.flush(); - } - catch (IOException e) { - System.err.println("no log-File"); - } - return res; - } - - /** - * unify asynchron mit Rückgabe UnifyResultModel ohne dass alle results gesammelt sind - * @param undConstrains - * @param oderConstraints - * @param fc - * @param logFile - * @param log - * @param cons - * @param ret - * @return - */ - public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); - ForkJoinPool pool = new ForkJoinPool(); - pool.invoke(unifyTask); - return ret; - } - - /** - * unify parallel mit Rückgabe UnifyResultModel nachdem alle results gesammelt sind - * @param undConstrains - * @param oderConstraints - * @param fc - * @param logFile - * @param log - * @param cons - * @param ret - * @return - */ - public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); - ForkJoinPool pool = new ForkJoinPool(); - pool.invoke(unifyTask); - Set> res = unifyTask.join(); - try { - logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements +"\n"); - logFile.flush(); - } - catch (IOException e) { - System.err.println("no log-File"); - } - return ret; - } - - /* - public Set> unifySequential(Set eq, IFiniteClosure fc, FileWriter logFile, Boolean log) { - TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false, logFile, log); - Set> res = unifyTask.compute(); - return res; - } - */ - - /** - * unify sequentiell mit oderconstraints - * @param undConstrains - * @param oderConstraints - * @param fc - * @param logFile - * @param log - * @param cons - * @return - */ - public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret, usedTasks); - Set> res = unifyTask.compute(); - try { - logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements +"\n"); - logFile.flush(); - } - catch (IOException e) { - System.err.println("no log-File"); - } - return res; - } - -} +package de.dhbwstuttgart.typeinference.unify; + +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.concurrent.ForkJoinPool; + +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.typeinference.constraints.Constraint; +import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; +import de.dhbwstuttgart.typeinference.constraints.Pair; +import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; +import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; + +public class TypeUnify { + + /** + * unify parallel ohne result modell + * @param undConstrains + * @param oderConstraints + * @param fc + * @param logFile + * @param log + * @param cons + * @return + */ + public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); + ForkJoinPool pool = new ForkJoinPool(); + pool.invoke(unifyTask); + Set> res = unifyTask.join(); + try { + logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements + "\n"); + logFile.flush(); + } + catch (IOException e) { + System.err.println("no log-File"); + } + return res; + } + + /** + * unify asynchron mit Rückgabe UnifyResultModel ohne dass alle results gesammelt sind + * @param undConstrains + * @param oderConstraints + * @param fc + * @param logFile + * @param log + * @param cons + * @param ret + * @return + */ + public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); + ForkJoinPool pool = new ForkJoinPool(); + pool.invoke(unifyTask); + return ret; + } + + /** + * unify parallel mit Rückgabe UnifyResultModel nachdem alle results gesammelt sind + * @param undConstrains + * @param oderConstraints + * @param fc + * @param logFile + * @param log + * @param cons + * @param ret + * @return + */ + public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); + ForkJoinPool pool = new ForkJoinPool(); + pool.invoke(unifyTask); + Set> res = unifyTask.join(); + try { + logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements +"\n"); + logFile.flush(); + } + catch (IOException e) { + System.err.println("no log-File"); + } + return ret; + } + + /* + public Set> unifySequential(Set eq, IFiniteClosure fc, FileWriter logFile, Boolean log) { + TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false, logFile, log); + Set> res = unifyTask.compute(); + return res; + } + */ + + /** + * unify sequentiell mit oderconstraints + * @param undConstrains + * @param oderConstraints + * @param fc + * @param logFile + * @param log + * @param cons + * @return + */ + public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret, usedTasks); + Set> res = unifyTask.compute(); + try { + logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements +"\n"); + logFile.flush(); + } + catch (IOException e) { + System.err.println("no log-File"); + } + return res; + } + +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 2c1d70fe1..39f551848 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -1,2386 +1,2386 @@ -//PL 2018-12-19: Merge checken -package de.dhbwstuttgart.typeinference.unify; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map.Entry; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.RecursiveTask; -import java.util.function.BiFunction; -import java.util.function.BinaryOperator; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.apache.commons.io.output.NullOutputStream; - -import de.dhbwstuttgart.exceptions.TypeinferenceException; -import de.dhbwstuttgart.parser.NullToken; -import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; -import de.dhbwstuttgart.typeinference.constraints.Constraint; -import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; -import de.dhbwstuttgart.typeinference.result.ResultSet; -import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; -import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet; -import de.dhbwstuttgart.typeinference.unify.interfaces.ISetOperations; -import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify; -import de.dhbwstuttgart.typeinference.unify.model.ExtendsType; -import de.dhbwstuttgart.typeinference.unify.model.FunNType; -import de.dhbwstuttgart.typeinference.unify.model.PairOperator; -import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; -import de.dhbwstuttgart.typeinference.unify.model.ReferenceType; -import de.dhbwstuttgart.typeinference.unify.model.SuperType; -import de.dhbwstuttgart.typeinference.unify.model.TypeParams; -import de.dhbwstuttgart.typeinference.unify.model.Unifier; -import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; -import de.dhbwstuttgart.typeinference.unify.model.UnifyType; -import de.dhbwstuttgart.typeinference.unify.model.WildcardType; -import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair; -import de.dhbwstuttgart.typeinference.unify.model.Pair; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.Writer; - -import com.google.common.collect.Ordering; - - -/** - * Implementation of the type unification algorithm - * @author Florian Steurer - */ -public class TypeUnifyTask extends RecursiveTask>> { - - private static final long serialVersionUID = 1L; - private static int i = 0; - private boolean printtag = false; - Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll? - - /** - * Element, das aus dem nextSet den Gleichunen dieses Threads hinzugefuegt wurde - */ - Set nextSetElement; - - /** - * Fuer die Threads - */ - UnifyResultModel urm; - protected static int noOfThread = 0; - private static int totalnoOfThread = 0; - int thNo; - protected boolean one = false; - Integer MaxNoOfThreads = 8; - - public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/"; - Writer logFile; - - /** - * The implementation of setOps that will be used during the unification - */ - protected ISetOperations setOps = new GuavaSetOperations(); - - /** - * The implementation of the standard unify that will be used during the unification - */ - protected IUnify stdUnify = new MartelliMontanariUnify(); - - /** - * The implementation of the rules that will be used during the unification. - */ - protected IRuleSet rules; - - protected Set eq; //und-constraints - - protected List>> oderConstraintsField; - - protected IFiniteClosure fc; - - protected Ordering> oup; - - protected boolean parallel; - - int rekTiefeField; - - Integer nOfUnify = 0; - - Integer noUndefPair = 0; - - Integer noAllErasedElements = 0; - - static Integer noou = 0; - - static int noBacktracking; - - static Integer noShortendElements = 0; - - Boolean myIsCanceled = false; - - volatile UnifyTaskModel usedTasks; - - public TypeUnifyTask() { - rules = new RuleSet(); - } - - /* - public TypeUnifyTask(Set eq, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log) { - this.eq = eq; - this.fc = fc; - this.oup = new OrderingUnifyPair(fc); - this.parallel = parallel; - this.logFile = logFile; - this.log = log; - rules = new RuleSet(logFile); - noOfThread++; - thNo = noOfThread; - } - */ - - - public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) { - synchronized (this) { - this.eq = eq; - //this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new)); - this.oderConstraintsField = oderConstraints; /*.stream().map(x -> { - Set> ret = new HashSet<>(); - for (Constraint y : x) { - ret.add(new HashSet<>(y)); - } - return ret; - }).collect(Collectors.toCollection(ArrayList::new)); - */ - - //x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new)); - this.nextSetElement = nextSetElement; - this.fc = fc; - this.oup = new OrderingUnifyPair(fc); - this.parallel = parallel; - this.logFile = logFile; - this.log = log; - - noOfThread++; - totalnoOfThread++; - //writeLog("thNo1 " + thNo); - thNo = totalnoOfThread; - writeLog("thNo2 " + thNo); - try { - this.logFile = //new OutputStreamWriter(new NullOutputStream()); - //new FileWriter(new File(System.getProperty("user.dir")+"/src/test/resources/logFiles/"+"Thread_"+thNo)); - new FileWriter(new File(System.getProperty("user.dir")+"/logFiles/"+"Thread_"+thNo)); - logFile.write(""); - } - catch (IOException e) { - System.err.println("log-File nicht vorhanden"); - } - /*Abbruchtest - if (thNo > 10) { - System.out.println("cancel"); - usedTasks.cancel(); - writeLog(nOfUnify.toString() + "cancel"); - System.out.println("cancel"); - } - */ - rules = new RuleSet(logFile); - this.rekTiefeField = rekTiefe; - this.urm = urm; - this.usedTasks = usedTasks; - this.usedTasks.add(this); - } - } - - /** - * Vererbt alle Variancen - * @param eq The set of constraints - */ - /* PL 2018-05- 17 verschoben nach JavaTXCompiler - private void varianceInheritance(Set eq) { - Set usedTPH = new HashSet<>(); - Set phSet = eq.stream().map(x -> { - Set pair = new HashSet<>(); - if (x.getLhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getLhsType()); - if (x.getRhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getRhsType()); - return pair; - }).reduce(new HashSet<>(), (a,b) -> { a.addAll(b); return a;} , (c,d) -> { c.addAll(d); return c;}); - - ArrayList phSetVariance = new ArrayList<>(phSet); - phSetVariance.removeIf(x -> (x.getVariance() == 0)); - while(!phSetVariance.isEmpty()) { - PlaceholderType a = phSetVariance.remove(0); - usedTPH.add(a); - //HashMap ht = new HashMap<>(); - //ht.put(a, a.getVariance()); - Set eq1 = new HashSet<>(eq); - eq1.removeIf(x -> !(x.getLhsType() instanceof PlaceholderType && ((PlaceholderType)x.getLhsType()).equals(a))); - eq1.stream().forEach(x -> { x.getRhsType().accept(new distributeVariance(), a.getVariance());}); - eq1 = new HashSet<>(eq); - eq1.removeIf(x -> !(x.getRhsType() instanceof PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a))); - eq1.stream().forEach(x -> { x.getLhsType().accept(new distributeVariance(), a.getVariance());}); - phSetVariance = new ArrayList<>(phSet); - phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x))); - } -} -*/ - void myCancel(Boolean b) { - myIsCanceled = true; - } - - public boolean myIsCancelled() { - return myIsCanceled; - } - - protected Set> compute() { - if (one) { - System.out.println("two"); - } - one = true; - Set neweq = new HashSet<>(eq); - /* 1-elementige Oder-Constraints werden in und-Constraints umgewandelt */ - oderConstraintsField.stream() - .filter(x -> x.size()==1) - .map(y -> y.stream().findFirst().get()).forEach(x -> neweq.addAll(x)); - ArrayList>> remainingOderconstraints = oderConstraintsField.stream() - .filter(x -> x.size()>1) - .collect(Collectors.toCollection(ArrayList::new)); - Set> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField, true); - noOfThread--; - try { - logFile.close(); - } - catch (IOException ioE) { - System.err.println("no log-File"); - } - if (isUndefinedPairSetSet(res)) { - throw new TypeinferenceException("Unresolved constraints: " + res.toString(), new NullToken()); //return new HashSet<>(); - } - else { - synchronized (usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - else { - return res; - } - } - } - } -/* - @Override - protected Set> compute() { - Set> fstElems = new HashSet<>(); - fstElems.add(eq); - Set> res = computeCartesianRecursiveOderConstraints(fstElems, oderConstraints, fc, parallel); - if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } - else return res; - } -*/ - - - - - /** - * Computes all principal type unifiers for a set of constraints. - * @param eq The set of constraints - * @param fc The finite closure - * @return The set of all principal type unifiers - */ - protected Set> unify(final Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) { - //Set aas = eq.stream().filter(x -> x.getLhsType().getName().equals("AA") //&& x.getPairOp().equals(PairOperator.SMALLERDOT) - // ).collect(Collectors.toCollection(HashSet::new)); - //writeLog(nOfUnify.toString() + " AA: " + aas.toString()); - //if (aas.isEmpty()) { - // System.out.println(""); - //} - - //.collect(Collectors.toCollection(HashSet::new))); - /* - * Step 1: Repeated application of reduce, adapt, erase, swap - */ - - rekTiefe++; - nOfUnify++; - writeLog(nOfUnify.toString() + " Unifikation: " + eq.toString()); - writeLog(nOfUnify.toString() + " Oderconstraints: " + oderConstraints.toString()); - //eq = eq.stream().map(x -> {x.setVariance((byte)-1); return x;}).collect(Collectors.toCollection(HashSet::new)); - - /* - * Variancen auf alle Gleichungen vererben - */ - //PL 2018-05-17 nach JavaTXCompiler verschoben - //varianceInheritance(eq); - - /* - * ? extends ? extends Theta rausfiltern - */ - Set doubleExt = eq.stream().filter(x -> (x.wrongWildcard())).map(x -> { x.setUndefinedPair(); return x;}) - .collect(Collectors.toCollection(HashSet::new)); - if (doubleExt.size() > 0) { - Set> ret = new HashSet<>(); - ret.add(doubleExt); - return ret; - } - - Set eq0; - Set eq0Prime; - Optional> eqSubst = Optional.of(eq); - do { - eq0Prime = eqSubst.get(); - eq0 = applyTypeUnificationRules(eq0Prime, fc); - eqSubst = rules.subst(eq0, oderConstraints); - } while (eqSubst.isPresent()); - - eq0.forEach(x -> x.disableCondWildcards()); - - writeLog(nOfUnify.toString() + " Unifikation nach applyTypeUnificationRules: " + eq.toString()); - writeLog(nOfUnify.toString() + " Oderconstraints nach applyTypeUnificationRules: " + oderConstraints.toString()); - - /* - * Step 2 and 3: Create a subset eq1s of pairs where both sides are TPH and eq2s of the other pairs - */ - Set eq1s = new HashSet<>(); - Set eq2s = new HashSet<>(); - splitEq(eq0, eq1s, eq2s); - - /* - * Step 4: Create possible typings - * - * "Manche Autoren identifizieren die Paare (a, (b,c)) und ((a,b),c) - * mit dem geordneten Tripel (a,b,c), wodurch das kartesische Produkt auch assoziativ wird." - Wikipedia - */ - - // There are up to 10 toplevel set. 8 of 10 are the result of the - // cartesian product of the sets created by pattern matching. - List>> topLevelSets = new ArrayList<>(); - - //System.out.println(eq2s); - - if(eq1s.size() != 0) { // Do not add empty sets or the cartesian product will always be empty. - Set> wrap = new HashSet<>(); - wrap.add(eq1s); - topLevelSets.add(wrap); // Add Eq1' - } - - // Add the set of [a =. Theta | (a=. Theta) in Eq2'] - //TODO: Occurscheck anwenden als Fehler identifizieren - Set bufferSet = eq2s.stream() - .filter(x -> x.getPairOp() == PairOperator.EQUALSDOT && x.getLhsType() instanceof PlaceholderType) - .collect(Collectors.toSet()); - - if(bufferSet.size() != 0) { // Do not add empty sets or the cartesian product will always be empty. - Set> wrap = new HashSet<>(); - wrap.add(bufferSet); - topLevelSets.add(wrap); - eq2s.removeAll(bufferSet); - } - - // Sets that originate from pair pattern matching - // Sets of the "second level" - Set undefinedPairs = new HashSet<>(); - if (printtag) System.out.println("eq2s " + eq2s); - //writeLog("BufferSet: " + bufferSet.toString()+"\n"); - List>> oderConstraintsOutput = new ArrayList<>();//new ArrayList<>(oderConstraints); - Set>>> secondLevelSets = calculatePairSets(eq2s, oderConstraints, fc, undefinedPairs, oderConstraintsOutput); - //PL 2017-09-20: Im calculatePairSets wird möglicherweise O .< java.lang.Integer - //nicht ausgewertet Faculty Beispiel im 1. Schritt - //PL 2017-10-03 geloest, muesste noch mit FCs mit kleineren - //Typen getestet werden. - writeLog(nOfUnify.toString() + " Oderconstraints2: " + oderConstraintsOutput.toString()); - if (printtag) System.out.println("secondLevelSets:" +secondLevelSets); - // If pairs occured that did not match one of the cartesian product cases, - // those pairs are contradictory and the unification is impossible. - if(!undefinedPairs.isEmpty()) { - noUndefPair++; - for (UnifyPair up : undefinedPairs) { - writeLog(noUndefPair.toString() + " UndefinedPairs; " + up); - writeLog("BasePair; " + up.getBasePair()); - } - Set> error = new HashSet<>(); - undefinedPairs = undefinedPairs.stream().map(x -> { x.setUndefinedPair(); return x;}).collect(Collectors.toCollection(HashSet::new)); - error.add(undefinedPairs); - undefinedPairs.forEach(x -> writeLog("AllSubst: " +x.getAllSubstitutions().toString())); - return error; - } - - /* Up to here, no cartesian products are calculated. - * filters for pairs and sets can be applied here */ - - // Alternative: Sub cartesian products of the second level (pattern matched) sets - // "the big (x)" - /* for(Set>> secondLevelSet : secondLevelSets) { - //System.out.println("secondLevelSet "+secondLevelSet.size()); - List>> secondLevelSetList = new ArrayList<>(secondLevelSet); - Set>> cartResult = setOps.cartesianProduct(secondLevelSetList); - //System.out.println("CardResult: "+cartResult.size()); - // Flatten and add to top level sets - Set> flat = new HashSet<>(); - int j = 0; - for(List> s : cartResult) { - j++; - //System.out.println("s from CardResult: "+cartResult.size() + " " + j); - Set flat1 = new HashSet<>(); - for(Set s1 : s) - flat1.addAll(s1); - flat.add(flat1); - } - //topLevelSets.add(flat); - } - */ - - //Alternative KEIN KARTESISCHES PRODUKT der secondlevel Ebene bilden - for(Set>> secondLevelSet : secondLevelSets) { - for (Set> secondlevelelem : secondLevelSet) { - topLevelSets.add(secondlevelelem); - } - } - //System.out.println(topLevelSets); - //System.out.println(); - - - //Aufruf von computeCartesianRecursive ANFANG - //writeLog("topLevelSets: " + topLevelSets.toString()); - return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe, finalresult); - - } - - - Set> unify2(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) { - //Aufruf von computeCartesianRecursive ENDE - - //keine Ahnung woher das kommt - //Set> setToFlatten = topLevelSets.stream().map(x -> x.iterator().next()).collect(Collectors.toCollection(HashSet::new)); - - //Muss auskommentiert werden, wenn computeCartesianRecursive ANFANG - // Cartesian product over all (up to 10) top level sets - //Set>> eqPrimeSet = setOps.cartesianProduct(topLevelSets) - // .stream().map(x -> new HashSet<>(x)) - // .collect(Collectors.toCollection(HashSet::new)); - //Muss auskommentiert werden, wenn computeCartesianRecursive ENDE - - - - Set> eqPrimePrimeSet = new HashSet<>(); - - Set forks = new HashSet<>(); - - //Muss auskommentiert werden, wenn computeCartesianRecursive ANFANG - //for(Set> setToFlatten : eqPrimeSet) { - // Flatten the cartesian product - //Muss auskommentiert werden, wenn computeCartesianRecursive ENDE - Set eqPrime = new HashSet<>(); - setToFlatten.stream().forEach(x -> eqPrime.addAll(x)); - - /* - * Step 5: Substitution - */ - //writeLog("vor Subst: " + eqPrime); - writeLog("vor Subst: " + oderConstraints); - String ocString = oderConstraints.toString(); - List>> newOderConstraints = new ArrayList<>(oderConstraints); - Optional> eqPrimePrime = rules.subst(eqPrime, newOderConstraints); - Set> unifyres1 = null; - Set> unifyres2 = null; - if (!ocString.equals(newOderConstraints.toString())) writeLog("nach Subst: " + newOderConstraints); - //writeLog("nach Subst: " + eqPrimePrime); - /* - * Step 6 a) Restart (fork) for pairs where subst was applied - */ - /* - if(parallel) { - if (eqPrime.equals(eq) && !eqPrimePrime.isPresent() - && oderConstraints.isEmpty()) //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch - //PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent()) - //PL 2018-05-18 beide Bedingungen muessen gelten, da eqPrime Veränderungen in allem ausser subst - //eqPrimePrime Veraenderungen in subst repraesentieren. - eqPrimePrimeSet.add(eqPrime); - else if(eqPrimePrime.isPresent()) { - //System.out.println("nextStep: " + eqPrimePrime.get()); - TypeUnifyTask fork = new TypeUnifyTask(eqPrimePrime.get(), fc, true, logFile, log); - forks.add(fork); - fork.fork(); - } - else { - //System.out.println("nextStep: " + eqPrime); - TypeUnifyTask fork = new TypeUnifyTask(eqPrime, fc, true, logFile, log); - forks.add(fork); - fork.fork(); - } - } - else */ - {// sequentiell (Step 6b is included) - if (printtag) System.out.println("nextStep: " + eqPrimePrime); - if (eqPrime.equals(eq) && !eqPrimePrime.isPresent() - && oderConstraints.isEmpty()) { //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch - //PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent()) - //PL 2018-05-18 beide Bedingungen muessen gelten, da eqPrime Veränderungen in allem ausser subst - //eqPrimePrime Veraenderungen in subst repraesentieren. - //try { - //if (isSolvedForm(eqPrime)) { - // writeLog("eqPrime:" + eqPrime.toString()+"\n"); - //} - //} - //catch (IOException e) { - // System.err.println("log-File nicht vorhanden"); - //} - eqPrimePrimeSet.add(eqPrime); - if (finalresult && isSolvedForm(eqPrime)) { - writeLog("eqPrime:" + eqPrime.toString()+"\n"); - urm.notify(eqPrimePrimeSet); - } - } - else if(eqPrimePrime.isPresent()) { - Set> unifyres = unifyres1 = unify(eqPrimePrime.get(), newOderConstraints, fc, parallel, rekTiefe, finalresult); - - eqPrimePrimeSet.addAll(unifyres); - } - else { - Set> unifyres = unifyres2 = unify(eqPrime, newOderConstraints, fc, parallel, rekTiefe, finalresult); - - - eqPrimePrimeSet.addAll(unifyres); - } - } - //Muss auskommentiert werden, wenn computeCartesianRecursive ANFANG - //} - //Muss auskommentiert werden, wenn computeCartesianRecursive ENDE - - /* - * Step 6 b) Build the union over everything. - */ - /* - * PL 2019-01-22: geloescht - - if(parallel) - for(TypeUnifyTask fork : forks) - eqPrimePrimeSet.addAll(fork.join()); - */ - /* - * Step 7: Filter empty sets; - */ - eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new)); - if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet)) { - writeLog("Result1 " + eqPrimePrimeSet.toString()); - } - return eqPrimePrimeSet; - } - - - - Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) { - //ArrayList>> remainingSets = new ArrayList<>(topLevelSets); - - fstElems.addAll(topLevelSets.stream() - .filter(x -> x.size()==1) - .map(y -> y.stream().findFirst().get()) - .collect(Collectors.toCollection(HashSet::new))); - ArrayList>> remainingSets = topLevelSets.stream() - .filter(x -> x.size()>1) - .collect(Collectors.toCollection(ArrayList::new)); - if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig - Set> result = unify2(fstElems, eq, oderConstraints, fc, parallel, rekTiefe, finalresult); - return result; - } - Set> nextSet = remainingSets.remove(0); - writeLog("nextSet: " + nextSet.toString()); - List> nextSetasList =new ArrayList<>(nextSet); - try { - //List> - //nextSetasList = oup.sortedCopy(nextSet);//new ArrayList<>(nextSet); - } - catch (java.lang.IllegalArgumentException e) { - System.out.print(""); - } - Set> result = new HashSet<>(); - int variance = 0; - - ArrayList zeroNextElem = new ArrayList<>(nextSetasList.get(0)); - UnifyPair fstBasePair = zeroNextElem.remove(0).getBasePair(); - - if (fstBasePair != null) { - Boolean sameBase = true; - for (UnifyPair ele : nextSetasList.get(0)) {//check ob a <. ty base oder ob Ueberladung - sameBase = sameBase && ele.getBasePair() != null && ele.getBasePair().equals(fstBasePair); - } - if (sameBase) { - Optional xi = nextSetasList.stream().map(x -> x.stream().filter(y -> y.getLhsType() instanceof PlaceholderType) - .filter(z -> ((PlaceholderType)z.getLhsType()).getVariance() != 0) - .map(c -> ((PlaceholderType)c.getLhsType()).getVariance()) - .reduce((a,b)-> {if (a==b) return a; else return 0; })) //2 kommt insbesondere bei Oder-Constraints vor - .filter(d -> d.isPresent()) - .map(e -> e.get()) - .findAny(); - if (xi.isPresent()) { - variance = xi.get(); - } - } - else { - variance = 2; - } - - } - else { - variance = 2; - } - //if (variance == 1 && nextSetasList.size() > 1) { - // List> al = new ArrayList<>(nextSetasList.size()); - // for (int ii = 0; ii < nextSetasList.size();ii++) { - // al.add(0,nextSetasList.get(ii)); - // } - // nextSetasList = al; - //} - //Set a = nextSetasListIt.next(); - /*if (nextSetasList.size()>1) {zu loeschen - if (nextSetasList.iterator().next().iterator().next().getLhsType().getName().equals("D")) - System.out.print(""); - if (variance == 1) { - a_next = oup.max(nextSetasList.iterator()); - } - else if (variance == -1) { - a_next = oup.min(nextSetasList.iterator()); - } - else if (variance == 0) { - a_next = nextSetasList.iterator().next(); - } - } - else { - a_next = nextSetasList.iterator().next(); - } - */ - if (!nextSetasList.iterator().hasNext()) - System.out.print(""); - if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1) - System.out.print(""); - writeLog("nextSetasList: " + nextSetasList.toString()); - Set nextSetElem = nextSetasList.get(0); - writeLog("BasePair1: " + nextSetElem + " " + nextSetElem.iterator().next().getBasePair()); - - /* sameEqSet-Bestimmung: Wenn a = ty \in nextSet dann enthaelt sameEqSet alle Paare a < ty1 oder ty2 < a aus fstElems */ - Set sameEqSet = new HashSet<>(); - if (variance != 2) { - Optional optOrigPair = nextSetElem.stream().filter(x -> ( - //x.getBasePair() != null && ist gegeben wenn variance != 2 - //x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && - (x.getPairOp().equals(PairOperator.EQUALSDOT) - /* - (x.getBasePair().getLhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getLhsType())) - || (x.getBasePair().getRhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getRhsType()) - */ - ))).filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist - x.getLhsType().equals(x.getBasePair().getLhsType()) || - x.getLhsType().equals(x.getBasePair().getRhsType()) - ).findFirst(); - writeLog("optOrigPair: " + optOrigPair); - if (optOrigPair.isPresent()) { - UnifyPair origPair = optOrigPair.get(); - UnifyType tyVar; - if (!((tyVar = origPair.getLhsType()) instanceof PlaceholderType)) { - tyVar = origPair.getRhsType(); - } - UnifyType tyVarEF = tyVar; - sameEqSet = fstElems.stream().map(xx -> xx.iterator().next()) - .filter(x -> (((x.getLhsType().equals(tyVarEF) && !(x.getRhsType() instanceof PlaceholderType)) - || (x.getRhsType().equals(tyVarEF) && !(x.getLhsType() instanceof PlaceholderType))))) - .collect(Collectors.toCollection(HashSet::new)); - } - } - /* sameEqSet-Bestimmung Ende */ - - Set a = null; - while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) { - Set a_last = a; - List> nextSetasListRest = new ArrayList<>(); - //List> nextSetasListRestMin = new ArrayList<>(); - //List> nextSetasListRestOder = new ArrayList<>(); - if (variance == 1) { - a = oup.max(nextSetasList.iterator()); - nextSetasList.remove(a); - nextSetasListRest = new ArrayList<>(nextSetasList); - Iterator> nextSetasListItRest = new ArrayList>(nextSetasListRest).iterator(); - while (nextSetasListItRest.hasNext()) { - Set a_next = nextSetasListItRest.next(); - if (//a.equals(a_next) || - (oup.compare(a, a_next) == 1)) { - nextSetasListRest.remove(a_next); - } - } - //Alle maximale Elemente in nextSetasListRest bestimmen - List> nextSetasListRestTest; - do { - nextSetasListRestTest = new ArrayList>(nextSetasListRest); - if (!nextSetasListRest.isEmpty()) { - Set max = oup.max(nextSetasListRest.iterator()); - Iterator> nextSetasListItRest2 = new ArrayList>(nextSetasListRest).iterator(); - while (nextSetasListItRest2.hasNext()) { - Set a_nextRest = nextSetasListItRest2.next(); - if (//a.equals(a_next) || - (oup.compare(max, a_nextRest) == 1)) { - nextSetasListRest.remove(a_nextRest); - } - - }} - } while(!nextSetasListRestTest.equals(nextSetasListRest)); - - } - else if (variance == -1) { - a = oup.min(nextSetasList.iterator()); - nextSetasList.remove(a); - nextSetasListRest = new ArrayList<>(nextSetasList); - Iterator> nextSetasListItRest = new ArrayList>(nextSetasListRest).iterator(); - while (nextSetasListItRest.hasNext()) { - Set a_next = nextSetasListItRest.next(); - if (//a.equals(a_next) || - (oup.compare(a, a_next) == -1)) { - nextSetasListRest.remove(a_next); - } - } - //Alle minimalen Elemente in nextSetasListRest bestimmen - - List> nextSetasListRestTest; - do { - nextSetasListRestTest = new ArrayList>(nextSetasListRest); - if (!nextSetasListRest.isEmpty()) { - Set min = oup.min(nextSetasListRest.iterator()); - Iterator> nextSetasListItRest2 = new ArrayList>(nextSetasListRest).iterator(); - while (nextSetasListItRest2.hasNext()) { - Set a_nextRest = nextSetasListItRest2.next(); - if (//a.equals(a_next) || - (oup.compare(min, a_nextRest) == -1)) { - nextSetasListRest.remove(a_nextRest); - } - - }} - } while(!nextSetasListRestTest.equals(nextSetasListRest)); - } - else if (variance == 2) { - a = nextSetasList.remove(0); - nextSetasListRest = new ArrayList<>(nextSetasList); - } - else if (variance == 0) { - a = nextSetasList.remove(0); - } - //writeLog("nextSet: " + nextSetasList.toString()+ "\n"); - //nextSetasList.remove(a); - /* zu loeschen - if (nextSetasList.size() > 0) { - if (nextSetasList.size()>1) { - if (variance == 1) { - a_next = oup.max(nextSetasList.iterator()); - } - else if (variance == -1) { - a_next = oup.min(nextSetasList.iterator()); - } - else { - a_next = nextSetasList.iterator().next(); - } - } - else { - a_next = nextSetasList.iterator().next(); - } - } - */ - //PL 2018-03-01 - //TODO: 1. Maximum und Minimum unterscheiden - //TODO: 2. compare noch für alle Elmemente die nicht X =. ty sind erweitern - //for(Set a : newSet) { - i++; - Set> elems = new HashSet>(fstElems); - writeLog("a1: " + rekTiefe + " "+ "variance: "+ variance + " " + a.toString()+ "\n"); - //elems.add(a); PL 2019-01-20 Muss weg, weil das in jeweiligen Thread erfolgen muss. Fuer den sequentiellen Fall - //im else-Zweig - //if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt - //writeLog("Vor unify2 Aufruf: " + elems.toString()); - Set> res = new HashSet<>(); - Set>> add_res = new HashSet<>(); - Set> aParDef = new HashSet<>(); - - /* PL 2019-03-11 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - if (variance != 2 && !sameEqSet.isEmpty()) { - Optional optAPair = a.stream().filter(x -> ( - //x.getBasePair() != null && ist gegeben wenn variance != 2 - //x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && - (x.getPairOp().equals(PairOperator.EQUALSDOT) - /* - (x.getBasePair().getLhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getLhsType())) - || (x.getBasePair().getRhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getRhsType()) - */ - ))).filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist - x.getLhsType().equals(x.getBasePair().getLhsType()) || - x.getLhsType().equals(x.getBasePair().getRhsType()) - ).findFirst(); - - if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a - UnifyPair aPair = optAPair.get(); - //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); - writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet); - if (!checkA(aPair, sameEqSet, elems, result)) { - a = null; - noShortendElements++; - continue; - } - } - } - /* PL 2019-03-11 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - - if(parallel && (variance == 1) && noOfThread <= MaxNoOfThreads) { - Set forks = new HashSet<>(); - Set newEqOrig = new HashSet<>(eq); - Set> newElemsOrig = new HashSet<>(elems); - List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); - newElemsOrig.add(a); - - /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); - //forks.add(forkOrig); - synchronized(usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - forkOrig.fork(); - } - /* FORK ENDE */ - - synchronized (this) { - writeLog("a in " + variance + " "+ a); - writeLog("nextSetasListRest: " + nextSetasListRest.toString()); - } - while (!nextSetasListRest.isEmpty()) { - Set nSaL = nextSetasListRest.remove(0); - synchronized (this) { nextSetasList.remove(nSaL); - writeLog("1 RM" + nSaL.toString()); - } - - /* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - Optional optAPair = nSaL.stream().filter(x -> ( - //x.getBasePair() != null && ist gegeben wenn variance != 2 - //x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && - (x.getPairOp().equals(PairOperator.EQUALSDOT) - /* - (x.getBasePair().getLhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getLhsType())) - || (x.getBasePair().getRhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getRhsType()) - */ - ))).filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist - x.getLhsType().equals(x.getBasePair().getLhsType()) || - x.getLhsType().equals(x.getBasePair().getRhsType()) - ).findFirst(); - - if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a - UnifyPair aPair = optAPair.get(); - //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); - writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet); - if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) { - nSaL = null; - noShortendElements++; - continue; - } - } - /* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - - Set newEq = new HashSet<>(eq); - Set> newElems = new HashSet<>(elems); - List>> newOderConstraints = new ArrayList<>(oderConstraints); - newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); - forks.add(fork); - synchronized(usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - fork.fork(); - } - } - //res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); - - /* FORK ANFANG */ - synchronized (this) { - noOfThread--; - writeLog("wait "+ forkOrig.thNo); - res = forkOrig.join(); - forkOrig.writeLog("final Orig 1"); - forkOrig.closeLogFile(); - //Set> fork_res = forkOrig.join(); - writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); - //noOfThread--; an das Ende von compute verschoben - //add_res.add(fork_res); - }; - /* FORK ENDE */ - - forks.forEach(x -> writeLog("wait: " + x.thNo)); - for(TypeUnify2Task fork : forks) { - synchronized (this) { - Set> fork_res = fork.join(); - writeLog("Join " + new Integer(fork.thNo).toString()); - //noOfThread--; an das Ende von compute verschoben - writeLog("fork_res: " + fork_res.toString()); - writeLog(new Boolean((isUndefinedPairSetSet(fork_res))).toString()); - add_res.add(fork_res); - if (!isUndefinedPairSetSet(fork_res)) { - aParDef.add(fork.getNextSetElement()); - } - fork.writeLog("final 1"); - fork.closeLogFile(); - }; - } - noOfThread++; - } else { - if(parallel && (variance == -1) && noOfThread <= MaxNoOfThreads) { - Set forks = new HashSet<>(); - Set newEqOrig = new HashSet<>(eq); - Set> newElemsOrig = new HashSet<>(elems); - List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); - newElemsOrig.add(a); - - /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); - //forks.add(forkOrig); - synchronized(usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - forkOrig.fork(); - } - /* FORK ENDE */ - - synchronized (this) { - writeLog("a in " + variance + " "+ a); - writeLog("nextSetasListRest: " + nextSetasListRest.toString()); - } - while (!nextSetasListRest.isEmpty()) { - Set nSaL = nextSetasListRest.remove(0); - synchronized (this) { nextSetasList.remove(nSaL); - writeLog("-1 RM" + nSaL.toString()); - } - - /* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - Optional optAPair = nSaL.stream().filter(x -> ( - //x.getBasePair() != null && ist gegeben wenn variance != 2 - //x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && - (x.getPairOp().equals(PairOperator.EQUALSDOT) - /* - (x.getBasePair().getLhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getLhsType())) - || (x.getBasePair().getRhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getRhsType()) - */ - ))).filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist - x.getLhsType().equals(x.getBasePair().getLhsType()) || - x.getLhsType().equals(x.getBasePair().getRhsType()) - ).findFirst(); - - if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a - UnifyPair aPair = optAPair.get(); - //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); - writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet); - if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) { - nSaL = null; - noShortendElements++; - continue; - } - } - /* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - - Set newEq = new HashSet<>(eq); - Set> newElems = new HashSet<>(elems); - List>> newOderConstraints = new ArrayList<>(oderConstraints); - newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); - forks.add(fork); - synchronized(usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - fork.fork(); - } - } - //res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); - - /* FORK ANFANG */ - synchronized (this) { - noOfThread--; - writeLog("wait "+ forkOrig.thNo); - res = forkOrig.join(); - forkOrig.writeLog("final Orig -1"); - forkOrig.closeLogFile(); - //Set> fork_res = forkOrig.join(); - writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); - //noOfThread--; an das Ende von compute verschoben - //add_res.add(fork_res); - }; - /* FORK ENDE */ - - forks.forEach(x -> writeLog("wait: " + x.thNo)); - for(TypeUnify2Task fork : forks) { - synchronized (this) { - Set> fork_res = fork.join(); - writeLog("Join " + new Integer(fork.thNo).toString()); - //noOfThread--; an das Ende von compute verschoben - writeLog("fork_res: " + fork_res.toString()); - writeLog(new Boolean((isUndefinedPairSetSet(fork_res))).toString()); - add_res.add(fork_res); - if (!isUndefinedPairSetSet(fork_res)) { - aParDef.add(fork.getNextSetElement()); - } - fork.writeLog("final -1"); - fork.closeLogFile(); - }; - } - noOfThread++; - } else { - if(parallel && (variance == 2) && noOfThread <= MaxNoOfThreads) { - writeLog("var2einstieg"); - Set forks = new HashSet<>(); - Set newEqOrig = new HashSet<>(eq); - Set> newElemsOrig = new HashSet<>(elems); - List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); - newElemsOrig.add(a); - - /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); - //forks.add(forkOrig); - synchronized(usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - forkOrig.fork(); - } - /* FORK ENDE */ - - synchronized (this) { - writeLog("a in " + variance + " "+ a); - writeLog("nextSetasListRest: " + nextSetasListRest.toString()); - } - while (!nextSetasListRest.isEmpty()) { - Set nSaL = nextSetasListRest.remove(0); - //nextSetasList.remove(nSaL); - Set newEq = new HashSet<>(eq); - Set> newElems = new HashSet<>(elems); - List>> newOderConstraints = new ArrayList<>(oderConstraints); - newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); - forks.add(fork); - synchronized(usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - fork.fork(); - } - } - //res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); - - /* FORK ANFANG */ - synchronized (this) { - noOfThread--; - writeLog("wait "+ forkOrig.thNo); - res = forkOrig.join(); - forkOrig.writeLog("final Orig 2"); - forkOrig.closeLogFile(); - //Set> fork_res = forkOrig.join(); - writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); - //noOfThread--; an das Ende von compute verschoben - //add_res.add(fork_res); //vermutlich falsch - }; - /* FORK ENDE */ - forks.forEach(x -> writeLog("wait: " + x.thNo)); - for(TypeUnify2Task fork : forks) { - synchronized (this) { - Set> fork_res = fork.join(); - writeLog("Join " + new Integer(fork.thNo).toString()); - //noOfThread--; an das Ende von compute verschoben - add_res.add(fork_res); - fork.writeLog("final 2"); - fork.closeLogFile(); - }; - } - noOfThread++; - } else { - //parallel = false; //Wenn MaxNoOfThreads erreicht ist, sequentiell weiterarbeiten - elems.add(a); //PL 2019-01-16 muss das wirklich hin steht schon in Zeile 859 ja braucht man siehe Zeile 859 - res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe, finalresult); - }}} - if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { - //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen - result = res; - } - else { - if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) - || (!isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) - || result.isEmpty()) { - - if ((!result.isEmpty() && !res.isEmpty() && !isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) //korrekte Loesungen aus und-constraints - && (a.stream().map(x-> (x.getBasePair() != null)).reduce(true, (x, y) -> (x && y)))) //bei oder-Constraints nicht ausfuehren - { - //TODO: PL 2019-01-15: Bug 129: Im Moment wird nur das Maximum und das Minimum des aktuellen Elements betrachtet. - //Die zu vereinigenden Mengen können mehrere Elemente enthalten. Das ist bisher nicht berücksichtigt - - //Alle Variablen bestimmen die nicht hinzugefügt wurden in a - //PL 2018-12-28: Hier gab es eine ClassCastException, war nicht reproduzierbar - System.out.println(""); - List vars_a = - a.stream().filter(x -> ((x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) - && (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getLhsType() instanceof PlaceholderType)) - || ((x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName())) - && (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getRhsType() instanceof PlaceholderType))) - ) - .map(y -> (PlaceholderType)y.getLhsType()).collect(Collectors.toCollection(ArrayList::new)); - Set fstElemRes = res.iterator().next(); - Set compRes = fstElemRes.stream().filter(x -> vars_a.contains(((PlaceholderType)x.getLhsType()))).collect(Collectors.toCollection(HashSet::new)); - - //Alle Variablen bestimmen die nicht hinzugefügt wurden in a_last - //System.out.println(a_last); - - try {//PL eingefuegt 2019-03-06 da bei map mmer wieder Nullpointer kamen - a_last.forEach(x -> {writeLog("a_last_elem:" + x + " basepair: " + x.getBasePair());});//PL 2019-05-13 ins try hinzugefuegt Nullpointer-Exception ist in der Zeile aufgetaucht. - List varsLast_a = - a_last.stream().filter(x -> ((x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) - && (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getLhsType() instanceof PlaceholderType)) - || ((x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName()))) - && (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getRhsType() instanceof PlaceholderType))) - .map(y -> (PlaceholderType)y.getLhsType()).collect(Collectors.toCollection(ArrayList::new)); - //[(java.util.Vector <. gen_aq, , 1), (CEK =. ? extends gen_aq, 1)] KANN VORKOMMEN - //erstes Element genügt, da vars immer auf die gleichen Elemente zugeordnet werden muessen - Set fstElemResult = result.iterator().next(); - Set compResult = fstElemResult.stream().filter(x -> varsLast_a.contains(((PlaceholderType)x.getLhsType()))).collect(Collectors.toCollection(HashSet::new));; - if (variance == 1) { - writeLog("a_last:" + a_last + " a: " + a); - writeLog("varsLast_a:" + varsLast_a + " vars_a: " + vars_a); - writeLog("compResult:" + compResult + " compRes: " + compRes); - int resOfCompare = oup.compare(compResult, compRes); - if (resOfCompare == -1) { - writeLog("Geloescht result: " + result); - result = res; - } else { - if (resOfCompare == 0) { - result.addAll(res); - } //else { - if (resOfCompare == 1) { - writeLog("Geloescht res: " + res); - //result = result; - }}} - else { if (variance == -1) { - writeLog("a_last:" + a_last + " a: " + a); - writeLog("varsLast_a:" + varsLast_a + " vars_a: " + vars_a); - writeLog("compResult:" + compResult + " compRes: " + compRes); - int resOfCompare = oup.compare(compResult, compRes); - if (resOfCompare == 1) { - writeLog("Geloescht result: " + result); - result = res; - } else { - if (resOfCompare == 0) { - result.addAll(res); - } else { - if (resOfCompare == -1) { - writeLog("Geloescht res: " + res); - //result = result; - }}}} - else { if (variance == 0) { - writeLog("RES var=1 ADD:" + result.toString() + " " + res.toString()); - result.addAll(res); - }}} - } - catch (NullPointerException e) { - writeLog("NullPointerException: " + a_last.toString()); - } - } - else { - //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden - writeLog("RES Fst: reuslt: " + result.toString() + " res: " + res.toString()); - result.addAll(res); - } - } - //else { - //wenn Korrekte Ergebnisse da und Feherfälle dazukommen Fehlerfälle ignorieren - // if (isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) { - // result = result; - // } - //} - } - - //} - //else {//duerfte gar nicht mehr vorkommen PL 2018-04-03 - //result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); - //} - if (parallel) { - for (Set> par_res : add_res) { - if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { - //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen - result = par_res; - if (par_res.iterator().next() instanceof WildcardType) { - System.out.println(""); - } - } - else { - if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) - || (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result)) - || result.isEmpty()) { - //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden - writeLog("RES var1 ADD:" + result.toString() + " " + par_res.toString()); - result.addAll(par_res); - } - } - } - //break; - } - - /* auskommentiert um alle Max und min Betrachtung auszuschalten ANFANG */ - if (!result.isEmpty() && (!isUndefinedPairSetSet(res) || !aParDef.isEmpty())) { - if (nextSetasList.iterator().hasNext() && nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("B")).findFirst().isPresent() && nextSetasList.size()>1) - System.out.print(""); - Iterator> nextSetasListIt = new ArrayList>(nextSetasList).iterator(); - if (variance == 1) { - /* vorgezogen vor das if - if (parallel) { - for (Set> par_res : add_res) { - if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { - //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen - result = par_res; - if (par_res.iterator().next() instanceof WildcardType) { - System.out.println(""); - } - } - else { - if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) - || (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result)) - || result.isEmpty()) { - //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden - writeLog("RES var1 ADD:" + result.toString() + " " + par_res.toString()); - result.addAll(par_res); - } - } - } - //break; - */ - - /* nextSetasList = nextSetasListRest; */ - /* wird bereits vor den unify2-Aufruf durchgefuehrt und nextSetasListRest zugeordnet - */ - - System.out.println(""); - writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); - writeLog("aParDef: " + aParDef.toString()); - aParDef.add(a); - Iterator> aParDefIt = aParDef.iterator(); - while(aParDefIt.hasNext()) { - Set a_new = aParDefIt.next(); - while (nextSetasListIt.hasNext()) { - Set a_next = nextSetasListIt.next(); - if (a_new.equals(a_next) || - (oup.compare(a_new, a_next) == 1)) { - writeLog("Removed: " + a_next.toString()); - nextSetasList.remove(a_next); - } - else { - writeLog("Not Removed: " + a_next.toString()); - System.out.println(""); - } - } - } - } - else { if (variance == -1) { - /* vorgezogen vor das if - if (parallel) { - for (Set> par_res : add_res) { - if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { - //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen - result = par_res; - if (par_res.iterator().next() instanceof WildcardType) { - System.out.println(""); - } - } - else { - if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) - || (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result)) - || result.isEmpty()) { - //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden - writeLog("RES var-1 ADD:" + result.toString() + " " + par_res.toString()); - result.addAll(par_res); - } - } - } - //break; - } - - } - */ - - System.out.println(""); - writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); - writeLog("aParDef: " + aParDef.toString()); - aParDef.add(a); - Iterator> aParDefIt = aParDef.iterator(); - while(aParDefIt.hasNext()) { - Set a_new = aParDefIt.next(); - while (nextSetasListIt.hasNext()) { - Set a_next = nextSetasListIt.next(); - if (a_new.equals(a_next) || - (oup.compare(a_new, a_next) == -1)) { - writeLog("Removed: " + a_next.toString()); - nextSetasList.remove(a_next); //PL geaendert 2019-01-09 - } - else { - System.out.println(""); - writeLog("Not Removed: " + a_next.toString()); - } - } - } - } - else { if (variance == 0) { - writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); - break; } - else { if (variance == 2) { - /* vorgezogen vor das if - if (parallel) { - for (Set> par_res : add_res) { - if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { - //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen - result = par_res; - if (par_res.iterator().next() instanceof WildcardType) { - System.out.println(""); - } - } - else { - if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) - || (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result)) - || result.isEmpty()) { - //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden - writeLog("RES var2 ADD:" + result.toString() + " " + par_res.toString()); - result.addAll(par_res); - } - } - } - //break; - } - */ - }}} - writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); - } - } - /* auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */ - - if (isUndefinedPairSetSet(res) && aParDef.isEmpty()) { - int nofstred= 0; - Set abhSubst = res.stream() - .map(b -> - b.stream() - .map(x -> x.getAllSubstitutions()) - .reduce((y,z) -> { y.addAll(z); return y;}).get()) - .reduce((y,z) -> { y.addAll(z); return y;}).get(); - abhSubst.addAll( - res.stream() - .map(b -> - b.stream() - .map(x -> x.getAllBases()) - .reduce((y,z) -> { y.addAll(z); return y;}).get()) - .reduce((y,z) -> { y.addAll(z); return y;}).get() - ); - Set b = a;//effective final a - Set durchschnitt = abhSubst.stream() - .filter(x -> b.contains(x)) - //.filter(y -> abhSubst.contains(y)) - .collect(Collectors.toCollection(HashSet::new)); - //Set vars = durchschnitt.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); - int len = nextSetasList.size(); - Set undefRes = res.stream().reduce((y,z) -> { y.addAll(z); return y;}).get(); //flatten aller undef results - Set, UnifyPair>> reducedUndefResSubstGroundedBasePair = undefRes.stream() - .map(x -> { Set su = x.getAllSubstitutions(); //alle benutzten Substitutionen - su.add(x.getGroundBasePair()); // urspruengliches Paar - su.removeAll(durchschnitt); //alle aktuell genänderten Paare entfernen - return new Pair<>(su, x.getGroundBasePair());}) - .collect(Collectors.toCollection(HashSet::new)); - if (res.size() > 1) { - System.out.println(); - } - nextSetasList = nextSetasList.stream().filter(x -> { - //Boolean ret = false; - //for (PlaceholderType var : vars) { - // ret = ret || x.stream().map(b -> b.getLhsType().equals(var)).reduce((c,d) -> c || d).get(); - //} - return (!x.containsAll(durchschnitt)); - })//.filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y)) //fuer testzwecke auskommentiert um nofstred zu bestimmen PL 2018-10-10 - .collect(Collectors.toCollection(ArrayList::new)); - nofstred = nextSetasList.size(); - //NOCH NICHT korrekt PL 2018-10-12 - //nextSetasList = nextSetasList.stream().filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y)) - // .collect(Collectors.toCollection(ArrayList::new)); - writeLog("res (undef): " + res.toString()); - writeLog("abhSubst: " + abhSubst.toString()); - writeLog("a2: " + rekTiefe + " " + a.toString()); - writeLog("Durchschnitt: " + durchschnitt.toString()); - writeLog("nextSet: " + nextSet.toString()); - writeLog("nextSetasList: " + nextSetasList.toString()); - writeLog("Number first erased Elements (undef): " + (len - nofstred)); - writeLog("Number second erased Elements (undef): " + (nofstred- nextSetasList.size())); - writeLog("Number erased Elements (undef): " + (len - nextSetasList.size())); - noAllErasedElements = noAllErasedElements + (len - nextSetasList.size()); - writeLog("Number of all erased Elements (undef): " + noAllErasedElements.toString()); - noBacktracking++; - writeLog("Number of Backtracking: " + noBacktracking); - System.out.println(""); - } - //if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) { - // return result; - //} - //else { - // result.removeIf(y -> isUndefinedPairSet(y)); - //} - //else result.stream().filter(y -> !isUndefinedPairSet(y)); - writeLog("res: " + res.toString()); - } - - writeLog("Return computeCR: " + result.toString()); - return result; - } - - protected Boolean checkA (UnifyPair aPair, Set sameEqSet, Set> elems, Set> result) { - writeLog("checkA: " + aPair + "sameEqSet: " + sameEqSet); - for (UnifyPair sameEq : sameEqSet) { - if (sameEq.getLhsType() instanceof PlaceholderType) { - Set localEq = new HashSet<>(); - Set unitedSubst = new HashSet<>(aPair.getAllSubstitutions()); - unitedSubst.addAll(aPair.getAllBases()); - unitedSubst.addAll(sameEq.getAllSubstitutions()); - unitedSubst.addAll(sameEq.getAllBases()); - localEq.add(new UnifyPair(aPair.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); - Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); - if (isUndefinedPairSetSet(localRes)) { - if (result.isEmpty() || isUndefinedPairSetSet(result)) { - result.addAll(localRes); - } - //writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet); - return false; - } - } - else { - Set localEq = new HashSet<>(); - Set unitedSubst = new HashSet<>(aPair.getAllSubstitutions()); - unitedSubst.addAll(aPair.getAllBases()); - unitedSubst.addAll(sameEq.getAllSubstitutions()); - unitedSubst.addAll(sameEq.getAllBases()); - localEq.add(new UnifyPair(sameEq.getLhsType(), aPair.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); - Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); - if (isUndefinedPairSetSet(localRes)) { - if (result.isEmpty() || isUndefinedPairSetSet(result)) { - result.addAll(localRes); - } - //writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet); - return false; - } - } - } - //writeLog("TRUE: " + aPair + "sameEqSet: " + sameEqSet); - return true; - } - - protected boolean couldBecorrect(Set, UnifyPair>> reducedUndefResSubstGroundedBasePair, Set nextElem) { - return reducedUndefResSubstGroundedBasePair.stream() - .map(pair -> { - Set reducedAbhSubst = pair.getKey(); - reducedAbhSubst.addAll(nextElem); - Optional> substRes = rules.subst(reducedAbhSubst); - if (!substRes.isPresent()) { - return true; - } - //PL 2018-10-12 - //Evtl. zurest applyTypeUnification aufrufen - //evtl auch unify aufrufen - else { - UnifyPair checkPair = substRes.get().stream() - .filter(x -> x.getGroundBasePair().equals(pair.getValue().get())).findFirst().get(); - if (((checkPair.getLhsType() instanceof PlaceholderType) || (checkPair.getRhsType() instanceof PlaceholderType)) - && (checkPair.getPairOp() == PairOperator.SMALLERDOT || checkPair.getPairOp() == PairOperator.SMALLERDOTWC)) - { - /* - Set setCheckPair = new HashSet<>(); - setCheckPair.add(checkPair); - Set setReturnCheckPair = applyTypeUnificationRules(setCheckPair, fc); - UnifyPair checkPair1 = setReturnCheckPair.iterator().next(); - Set up = new HashSet<>(); - up.add(checkPair1); - Set undef = new HashSet<>(); - */ - PairOperator pairOp = checkPair.getPairOp(); - UnifyType lhsType = checkPair.getLhsType(); - UnifyType rhsType = checkPair.getRhsType(); - ///* Case 1: (a <. Theta') - if ((((pairOp == PairOperator.SMALLERDOT) || (pairOp == PairOperator.SMALLERNEQDOT)) && lhsType instanceof PlaceholderType) - // Case 2: (a <.? ? ext Theta') - || (pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType) - // Case 3: (a <.? ? sup Theta') - || (pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof SuperType) - - // Case 4 was replaced by an inference rule - // Case 4: (a <.? Theta') - || (pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType) - // Case 5: (Theta <. a) - || ((pairOp == PairOperator.SMALLERDOT) && rhsType instanceof PlaceholderType) - // Case 6 was replaced by an inference rule. - // Case 6: (? ext Theta <.? a) - || (pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof ExtendsType && rhsType instanceof PlaceholderType) - // Case 7 was replaced by an inference rule - // Case 7: (? sup Theta <.? a) - || (pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof SuperType && rhsType instanceof PlaceholderType) - // Case 8: (Theta <.? a) - || (pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType) - //reduceWildcardLow - || (pairOp == PairOperator.SMALLERDOTWC && (lhsType instanceof ExtendsType) && (rhsType instanceof ExtendsType)) - //reduceWildcardLowRight - || ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof ReferenceType) && (rhsType instanceof ExtendsType)) - //reduceWildcardUp - || ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof SuperType) && (rhsType instanceof SuperType)) - //reduceWildcardUpRight - || ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof ReferenceType) && (rhsType instanceof SuperType)) - //reduceFunN - || (((pairOp == PairOperator.SMALLERDOT) || (pairOp == PairOperator.EQUALSDOT)) - //PL 2017-10-03 hinzugefuegt - //da Regel auch fuer EQUALSDOT anwendbar - && (lhsType instanceof FunNType) && (rhsType instanceof FunNType)) - //greaterFunN - || ((pairOp== PairOperator.SMALLERDOT) && (lhsType instanceof FunNType) && (rhsType instanceof PlaceholderType)) - //smallerFunN - || ((pairOp == PairOperator.SMALLERDOT) && (lhsType instanceof PlaceholderType && rhsType instanceof FunNType)) - //reduceTph - || ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof PlaceholderType && rhsType instanceof ReferenceType)) - //reduceTphExt - || ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof ExtendsType) && rhsType instanceof PlaceholderType) - //reduceTphSup - || ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof SuperType) && rhsType instanceof PlaceholderType)) { - return true; - } - // Case unknown: If a pair fits no other case, then the type unification has failed. - // Through application of the rules, every pair should have one of the above forms. - // Pairs that do not have one of the aboves form are contradictory. - else { - writeLog("Second erase:" +checkPair.toString()); - return false; - } - //*/ - } else { - //Pair type <. ? extends ? extends type betrachten TODO PL 2018-10-09 - }} - return true;}).reduce((xx, yy) -> xx || yy).get(); - } - - protected boolean isUndefinedPairSet(Set s) { - if (s.size() >= 1 ) { - Boolean ret = s.stream().map(x -> x.isUndefinedPair()).reduce(true, (x,y)-> (x && y)); - return ret; - } - else { - return false; - } - } - - protected boolean isUndefinedPairSetSet(Set> s) { - if (s.size() >= 1) { - Boolean ret = s.stream(). map(x -> isUndefinedPairSet(x)).reduce(true, (x,y)-> (x && y)); - return ret; - } - return false; - - } - /** - * Checks whether a set of pairs is in solved form. - * @param eqPrimePrime The set of pair - * @return True if in solved form, false otherwise. - */ - protected boolean isSolvedForm(Set eqPrimePrime) { - for(UnifyPair pair : eqPrimePrime) { - UnifyType lhsType = pair.getLhsType(); - UnifyType rhsType = pair.getRhsType(); - - if(!(lhsType instanceof PlaceholderType)) - return false; - - // If operator is not equals, both sides must be placeholders - if(pair.getPairOp() != PairOperator.EQUALSDOT && !(rhsType instanceof PlaceholderType)) - return false; - } - return true; - } - - /** - * Repeatedly applies type unification rules to a set of equations. - * This is step one of the unification algorithm. - * @return The set of pairs that results from repeated application of the inference rules. - */ - public Set applyTypeUnificationRules(Set eq, IFiniteClosure fc) { - - /* - * Rule Application Strategy: - * - * 1. Swap all pairs and erase all erasable pairs - * 2. Apply all possible rules to a single pair, then move it to the result set. - * Iterating over pairs first, then iterating over rules prevents the application - * of rules to a "finished" pair over and over. - * 2.1 Apply all rules repeatedly except for erase rules. If - * the application of a rule creates new pairs, check immediately - * against the erase rules. - */ - - - LinkedHashSet targetSet = new LinkedHashSet(); - LinkedList eqQueue = new LinkedList<>(); - - /* - * Swap all pairs and erase all erasable pairs - */ - eq.forEach(x -> swapAddOrErase(x, fc, eqQueue)); - - /* - * Apply rules until the queue is empty - */ - while(!eqQueue.isEmpty()) { - UnifyPair pair = eqQueue.pollFirst(); - - // ReduceUp, ReduceLow, ReduceUpLow - Optional opt = rules.reduceUpLow(pair); - opt = opt.isPresent() ? opt : rules.reduceLow(pair); - opt = opt.isPresent() ? opt : rules.reduceUp(pair); - opt = opt.isPresent() ? opt : rules.reduceWildcardLow(pair); - opt = opt.isPresent() ? opt : rules.reduceWildcardLowRight(pair); - opt = opt.isPresent() ? opt : rules.reduceWildcardUp(pair); - opt = opt.isPresent() ? opt : rules.reduceWildcardUpRight(pair); - //PL 2018-03-06 auskommentiert muesste falsch sein vgl. JAVA_BSP/Wildcard6.java - //opt = opt.isPresent() ? opt : rules.reduceWildcardLowUp(pair); - //opt = opt.isPresent() ? opt : rules.reduceWildcardUpLow(pair); - //opt = opt.isPresent() ? opt : rules.reduceWildcardLeft(pair); - - // Reduce TPH - opt = opt.isPresent() ? opt : rules.reduceTph(pair); - - // One of the rules has been applied - if(opt.isPresent()) { - swapAddOrErase(opt.get(), fc, eqQueue); - continue; - } - - // Reduce1, Reduce2, ReduceExt, ReduceSup, ReduceEq - //try { - // logFile.write("PAIR1 " + pair + "\n"); - // logFile.flush(); - //} - //catch (IOException e) { } - - Optional> optSet = rules.reduce1(pair, fc); - optSet = optSet.isPresent() ? optSet : rules.reduce2(pair); - optSet = optSet.isPresent() ? optSet : rules.reduceExt(pair, fc); - optSet = optSet.isPresent() ? optSet : rules.reduceSup(pair, fc); - optSet = optSet.isPresent() ? optSet : rules.reduceEq(pair); - - // ReduceTphExt, ReduceTphSup - optSet = optSet.isPresent() ? optSet : rules.reduceTphExt(pair); - optSet = optSet.isPresent() ? optSet : rules.reduceTphSup(pair); - - - // FunN Rules - optSet = optSet.isPresent() ? optSet : rules.reduceFunN(pair); - optSet = optSet.isPresent() ? optSet : rules.greaterFunN(pair); - optSet = optSet.isPresent() ? optSet : rules.smallerFunN(pair); - - // One of the rules has been applied - if(optSet.isPresent()) { - optSet.get().forEach(x -> swapAddOrErase(x, fc, eqQueue)); - continue; - } - - // Adapt, AdaptExt, AdaptSup - //try { - // logFile.write("PAIR2 " + pair + "\n"); - // logFile.flush(); - //} - //catch (IOException e) { } - opt = rules.adapt(pair, fc); - opt = opt.isPresent() ? opt : rules.adaptExt(pair, fc); - opt = opt.isPresent() ? opt : rules.adaptSup(pair, fc); - - // One of the rules has been applied - if(opt.isPresent()) { - swapAddOrErase(opt.get(), fc, eqQueue); - continue; - } - - // None of the rules has been applied - targetSet.add(pair); - } - - return targetSet; - } - - /** - * Applies the rule swap to a pair if possible. Then adds the pair to the set if no erase rule applies. - * If an erase rule applies, the pair is not added (erased). - * @param pair The pair to swap and add or erase. - * @param collection The collection to which the pairs are added. - */ - protected void swapAddOrErase(UnifyPair pair, IFiniteClosure fc, Collection collection) { - Optional opt = rules.swap(pair); - UnifyPair pair2 = opt.isPresent() ? opt.get() : pair; - - if(rules.erase1(pair2, fc) || rules.erase3(pair2) || rules.erase2(pair2, fc)) - return; - - collection.add(pair2); - } - - /** - * Splits the equation eq into a set eq1s where both terms are type variables, - * and a set eq2s where one of both terms is not a type variable. - * @param eq Set of pairs to be splitted. - * @param eq1s Subset of eq where both terms are type variables. - * @param eq2s eq/eq1s. - */ - protected void splitEq(Set eq, Set eq1s, Set eq2s) { - for(UnifyPair pair : eq) - if(pair.getLhsType() instanceof PlaceholderType && pair.getRhsType() instanceof PlaceholderType) - eq1s.add(pair); - else - eq2s.add(pair); - } - - /** - * Creates sets of pairs specified in the fourth step. Does not calculate cartesian products. - * @param undefined All pairs that did not match one of the 8 cases are added to this set. - * @return The set of the eight cases (without empty sets). Each case is a set, containing sets generated - * from the pairs that matched the case. Each generated set contains singleton sets or sets with few elements - * (as in case 1 where sigma is added to the innermost set). - */ - protected Set>>> calculatePairSets(Set eq2s, List>> oderConstraintsInput, IFiniteClosure fc, Set undefined, List>> oderConstraintsOutput) { - oderConstraintsOutput.addAll(oderConstraintsInput); - List>>> result = new ArrayList<>(9); - - // Init all 8 cases + 9. Case: oderConstraints - for(int i = 0; i < 9; i++) - result.add(new HashSet<>()); - - ArrayList eq2sprime = new ArrayList<>(eq2s); - Iterator eq2sprimeit = eq2sprime.iterator(); - ArrayList eq2sAsList = new ArrayList<>(); - Boolean first = true; - while(eq2sprimeit.hasNext()) {// alle mit Variance != 0 nach vorne schieben - UnifyPair up = eq2sprimeit.next(); - if ((up.getLhsType() instanceof PlaceholderType && ((PlaceholderType)up.getLhsType()).getVariance() != 0) - || (up.getRhsType() instanceof PlaceholderType && ((PlaceholderType)up.getRhsType()).getVariance() != 0)) { - eq2sAsList.add(up); - eq2s.remove(up); - } - } - if (eq2sAsList.isEmpty()) { - List>> oderConstraintsVariance = oderConstraintsOutput.stream() //Alle Elemente rauswerfen, die Variance 0 haben oder keine TPH in LHS oder RHS sind - .filter(x -> x.stream() - .filter(y -> - y.stream().filter(z -> ((z.getLhsType() instanceof PlaceholderType) - && (((PlaceholderType)(z.getLhsType())).getVariance() != 0)) - || ((z.getRhsType() instanceof PlaceholderType) - && (((PlaceholderType)(z.getRhsType())).getVariance() != 0)) - ).findFirst().isPresent() - ).findFirst().isPresent()).collect(Collectors.toList()); - if (!oderConstraintsVariance.isEmpty()) { - Set> ret = oderConstraintsVariance.get(0); - oderConstraintsOutput.remove(ret); - //Set retFlat = new HashSet<>(); - //ret.stream().forEach(x -> retFlat.addAll(x)); - ret.stream().forEach(x -> x.stream().forEach(y -> y.addSubstitutions(x))); - result.get(8).add(ret); - first = false; - } - } - - eq2sAsList.addAll(eq2s); - - if (eq2sAsList.isEmpty() && first) {//Alle eq2s sind empty und alle oderConstraints mit Variance != 0 sind bearbeitet - if (!oderConstraintsOutput.isEmpty()) { - Set> ret = oderConstraintsOutput.remove(0); - //if (ret.iterator().next().iterator().next().getLhsType().getName().equals("M")) - // System.out.println("M"); - //Set retFlat = new HashSet<>(); - //ret.stream().forEach(x -> retFlat.addAll(x)); - ret.stream().forEach(x -> x.stream().forEach(y -> y.addSubstitutions(x))); - result.get(8).add(ret); - first = false; - } - } - /* - Bei allen die Abhaengigkeit der Elemente aus eq2sAsList als evtl. als Substitution - hinzufuegen - */ - Set consideredElements = new HashSet<>(); - for(UnifyPair pair : eq2sAsList) { - if (consideredElements.contains(pair)) { - continue; - } - PairOperator pairOp = pair.getPairOp(); - UnifyType lhsType = pair.getLhsType(); - UnifyType rhsType = pair.getRhsType(); - - // Case 1: (a <. Theta') - if (((pairOp == PairOperator.SMALLERDOT) || (pairOp == PairOperator.SMALLERNEQDOT)) && lhsType instanceof PlaceholderType) { - //System.out.println(pair); - if (first) { //writeLog(pair.toString()+"\n"); - if (((PlaceholderType)(pair.getLhsType())).getName().equals("AR")) { - System.out.println("AR"); - } - Set> x1 = unifyCase1(pair, fc); - if (pairOp == PairOperator.SMALLERNEQDOT) { - Set remElem = new HashSet<>(); - remElem.add(new UnifyPair(pair.getLhsType(), pair.getRhsType(), PairOperator.EQUALSDOT)); - x1.remove(remElem); - remElem = new HashSet<>(); - remElem.add(new UnifyPair(pair.getLhsType(), new ExtendsType(pair.getRhsType()), PairOperator.EQUALSDOT)); - x1.remove(remElem); - remElem = new HashSet<>(); - remElem.add(new UnifyPair(pair.getLhsType(), new SuperType(pair.getRhsType()), PairOperator.EQUALSDOT)); - x1.remove(remElem); - } - /* ZU LOESCHEN ANFANG - //System.out.println(x1); - Set sameEqSet = eq2sAsList.stream() - .filter(x -> ((x.getLhsType().equals(lhsType) || x.getRhsType().equals(lhsType)) && !x.equals(pair))) - .collect(Collectors.toCollection(HashSet::new)); - consideredElements.addAll(sameEqSet); - Set> x2 = x1; - Set> x1Res = new HashSet<>(); - writeLog("pair:\n" + pair.toString()); - writeLog("x1 Start:\n" + x1.toString()); - writeLog("sameEqSet:\n" + sameEqSet.toString()); - for (UnifyPair sameEq : sameEqSet) { - writeLog("x1 Original:\n" + x1.toString()); - if (sameEq.getLhsType() instanceof PlaceholderType) { - x1 = x1.stream().filter(y -> { - UnifyPair type = y.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); - Set localEq = new HashSet<>(); - Set unitedSubst = new HashSet<>(type.getSubstitution()); - unitedSubst.addAll(sameEq.getSubstitution()); - localEq.add(new UnifyPair(type.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); - Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); - Boolean localCorr = !isUndefinedPairSetSet(localRes); - if (!localCorr) { - collectErr.addAll(localRes); - } - else { - localRes.forEach(z -> z.addAll(y)); - x1Res.addAll(localRes); - } - return localCorr; - } - ).collect(Collectors.toCollection(HashSet::new)); - } - else { - x1 = x1.stream().filter(y -> { - UnifyPair type = y.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); - Set localEq = new HashSet<>(); - Set unitedSubst = new HashSet<>(type.getSubstitution()); - unitedSubst.addAll(sameEq.getSubstitution()); - localEq.add(new UnifyPair(sameEq.getLhsType(), type.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); - Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); - Boolean localCorr = !isUndefinedPairSetSet(localRes); - if (!localCorr) { - collectErr.addAll(localRes); - } - else { - localRes.forEach(z -> z.addAll(y)); - x1Res.addAll(localRes); - } - return localCorr; - } - ).collect(Collectors.toCollection(HashSet::new)); - } - writeLog("x1 nach Loeschung von " + sameEq.toString()+" :\n" + x1.toString()); - } - Set> x1ResPrime; - if (sameEqSet.isEmpty()) { - x1ResPrime = x1; - } - else { - x1ResPrime = x1Res; - } - result.get(0).add(x1ResPrime); - ZU LOESCHEN ENDE */ - result.get(0).add(x1); - if (x1.isEmpty()) { - undefined.add(pair); //Theta ist nicht im FC => Abbruch - } - } - else { - Set s1 = new HashSet<>(); - s1.add(pair); - Set> s2 = new HashSet<>(); - s2.add(s1); - result.get(0).add(s2); - } - - } - // Case 2: (a <.? ? ext Theta') - else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType) - if (first) { //writeLog(pair.toString()+"\n"); - Set> x1 = unifyCase2(pair, fc); - result.get(1).add(x1); - if (x1.isEmpty()) { - undefined.add(pair); //Theta ist nicht im FC - } - } - else { - Set s1 = new HashSet<>(); - s1.add(pair); - Set> s2 = new HashSet<>(); - s2.add(s1); - result.get(1).add(s2); - } - - // Case 3: (a <.? ? sup Theta') - else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof SuperType) - if (first) { //writeLog(pair.toString()+"\n"); - Set> x1 = unifyCase3(pair, fc); - result.get(2).add(x1); - if (x1.isEmpty()) { - undefined.add(pair); //Theta ist nicht im FC - } - } - else { - Set s1 = new HashSet<>(); - s1.add(pair); - Set> s2 = new HashSet<>(); - s2.add(s1); - result.get(2).add(s2); - } - - // Case 4 was replaced by an inference rule - // Case 4: (a <.? Theta') - //else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType) - // result.get(3).add(unifyCase4((PlaceholderType) lhsType, rhsType, fc)); - - // Case 5: (Theta <. a) - else if ((pairOp == PairOperator.SMALLERDOT) && rhsType instanceof PlaceholderType) - if (first) { //writeLog(pair.toString()+"\n"); - Set> x1 = unifyCase5(pair, fc); - result.get(4).add(x1); - if (x1.isEmpty()) { - undefined.add(pair); //Theta ist nicht im FC - } - } - else { - Set s1 = new HashSet<>(); - s1.add(pair); - Set> s2 = new HashSet<>(); - s2.add(s1); - result.get(4).add(s2); - } - - // Case 6 was replaced by an inference rule. - // Case 6: (? ext Theta <.? a) - //else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof ExtendsType && rhsType instanceof PlaceholderType) - // result.get(5).add(unifyCase6((ExtendsType) lhsType, (PlaceholderType) rhsType, fc)); - - // Case 7 was replaced by an inference rule - // Case 7: (? sup Theta <.? a) - //else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof SuperType && rhsType instanceof PlaceholderType) - // result.get(6).add(unifyCase7((SuperType) lhsType, (PlaceholderType) rhsType, fc)); - - // Case 8: (Theta <.? a) - else if(pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType) - if (first) { //writeLog(pair.toString()+"\n"); - Set> x1 = unifyCase8(pair, fc); - result.get(7).add(x1); - if (x1.isEmpty()) { - undefined.add(pair); //Theta ist nicht im FC - } - } - else { - Set s1 = new HashSet<>(); - s1.add(pair); - Set> s2 = new HashSet<>(); - s2.add(s1); - result.get(7).add(s2); - } - // Case unknown: If a pair fits no other case, then the type unification has failed. - // Through application of the rules, every pair should have one of the above forms. - // Pairs that do not have one of the aboves form are contradictory. - else { - // If a pair is not defined, the unificiation will fail, so the loop can be stopped here. - undefined.add(pair); - break; - } - first = false; - } - - // Filter empty sets or sets that only contain an empty set. - return result.stream().map(x -> x.stream().filter(y -> y.size() > 0).collect(Collectors.toCollection(HashSet::new))) - .filter(x -> x.size() > 0).collect(Collectors.toCollection(HashSet::new)); - } - - //TODO: Wenn Theta' nicht im FC muss ein Fehler produziert werden PL 18-04-20 - /** - * Cartesian product Case 1: (a <. Theta') - */ - protected Set> unifyCase1(UnifyPair pair, IFiniteClosure fc) { - PlaceholderType a = (PlaceholderType)pair.getLhsType(); - UnifyType thetaPrime = pair.getRhsType(); - byte variance = pair.getVariance(); - - Set> result = new HashSet<>(); - - boolean allGen = thetaPrime.getTypeParams().size() > 0; - for(UnifyType t : thetaPrime.getTypeParams()) - if(!(t instanceof PlaceholderType) || !((PlaceholderType) t).isGenerated()) { - allGen = false; - break; - } - //if (thetaPrime.getName().equals("java.util.Vector") //Fuer Bug 127 - // && thetaPrime instanceof ReferenceType - // && ((ReferenceType)thetaPrime).getTypeParams().iterator().next() instanceof PlaceholderType) //.getName().equals("java.util.Vector")) - // && ((ReferenceType)((ReferenceType)thetaPrime).getTypeParams().iterator().next()).getTypeParams().iterator().next().getName().equals("java.lang.Integer")) { - // { - // System.out.println(""); - //} - Set cs = fc.getAllTypesByName(thetaPrime.getName());//cs= [java.util.Vector, java.util.Vector>, ????java.util.Vector???] - - - //PL 18-02-06 entfernt, kommt durch unify wieder rein - //cs.add(thetaPrime); - //PL 18-02-06 entfernt - - //cs muessen fresh Typvars gesetzt werden PL 2018-03-18 - Set csPHRenamed = cs.stream().map(x -> { - BinaryOperator> combiner = (aa,b) -> { aa.putAll(b); return aa;}; - HashMap hm = x.getInvolvedPlaceholderTypes().stream() - .reduce(new HashMap(), - (aa, b)-> { aa.put(b,PlaceholderType.freshPlaceholder()); return aa; }, combiner); - return x.accept(new freshPlaceholder(), hm); - }).collect(Collectors.toCollection(HashSet::new)); - - - for(UnifyType c : csPHRenamed) { - //PL 18-02-05 getChildren durch smaller ersetzt in getChildren werden die Varianlen nicht ersetzt. - Set thetaQs = new HashSet<>(); - //TODO smaller wieder reinnehmen? - //thetaQs.add(c);// - thetaQs = fc.smaller(c, new HashSet<>()).stream().collect(Collectors.toCollection(HashSet::new)); - //Set thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new)); - //thetaQs.add(thetaPrime); //PL 18-02-05 wieder geloescht - //PL 2017-10-03: War auskommentiert habe ich wieder einkommentiert, - //da children offensichtlich ein echtes kleiner und kein kleinergleich ist - - //PL 18-02-06: eingefuegt, thetaQs der Form V> <. V'> werden entfernt - //TODO PL 19-01-14 wieder reinnehmen kurzfristig auskommentiert - thetaQs = thetaQs.stream().filter(ut -> ut.getTypeParams().arePlaceholders()).collect(Collectors.toCollection(HashSet::new)); - //PL 18-02-06: eingefuegt - - Set thetaQPrimes = new HashSet<>(); - TypeParams cParams = c.getTypeParams(); - if(cParams.size() == 0) - thetaQPrimes.add(c); - else { - ArrayList> candidateParams = new ArrayList<>(); - - for(UnifyType param : cParams) - candidateParams.add(fc.grArg(param, new HashSet<>())); - - for(TypeParams tp : permuteParams(candidateParams)) - thetaQPrimes.add(c.setTypeParams(tp)); - } - - for(UnifyType tqp : thetaQPrimes) { - Collection tphs = tqp.getInvolvedPlaceholderTypes(); - Optional opt = stdUnify.unify(tqp, thetaPrime); - if (!opt.isPresent()) { - continue; - } - Unifier unifier = opt.get(); - unifier.swapPlaceholderSubstitutions(thetaPrime.getTypeParams()); - Set substitutionSet = new HashSet<>(); - for (Entry sigma : unifier) { - if (!tphs.contains(sigma.getKey())) {//eingefuegt PL 2019-02-02 Bug 127 - substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT, - //TODO: nochmals ueberlegen ob hier pair.getSubstitution() korrekt ist, oder ob leere Menge hin müsste - //alle folgenden New UnifyPair ebenfalls ueberpruefen PL 2018-04-19 - pair.getSubstitution(), pair)); - } - } - //List freshTphs = new ArrayList<>(); PL 18-02-06 in die For-Schleife verschoben - for (UnifyType tq : thetaQs) { - Set smaller = fc.smaller(unifier.apply(tq), new HashSet<>()); - //eingefuegt PL 2018-03-29 Anfang ? ext. theta hinzufuegen - if (a.isWildcardable()) { - Set smaller_ext = smaller.stream().filter(x -> !(x instanceof ExtendsType) && !(x instanceof SuperType)) - .map(x -> { - //BinaryOperator> combiner = (aa,b) -> { aa.putAll(b); return aa;}; //Variablenumbenennung rausgenommen - //HashMap hm = x.getInvolvedPlaceholderTypes().stream() //Variablen muessen wahrscheinlich erhalten bleiben - // .reduce(new HashMap(), - // (aa, b)-> { aa.put(b,PlaceholderType.freshPlaceholder()); return aa; }, combiner); - return new ExtendsType (x);})//.accept(new freshPlaceholder(), hm));} - .collect(Collectors.toCollection(HashSet::new)); - smaller.addAll(smaller_ext); - } - //eingefuegt PL 2018-03-29 Ende ? ext. theta hinzufuegen - for(UnifyType theta : smaller) { - List freshTphs = new ArrayList<>(); - Set resultPrime = new HashSet<>(); - - for(int i = 0; !allGen && i < theta.getTypeParams().size(); i++) { - if(freshTphs.size()-1 < i)//IST DAS RICHTIG??? PL 2018-12-12 - freshTphs.add(PlaceholderType.freshPlaceholder()); - freshTphs.forEach(x -> ((PlaceholderType)x).setInnerType(true)); - resultPrime.add(new UnifyPair(freshTphs.get(i), theta.getTypeParams().get(i), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair)); - } - - if(allGen) { - UnifyPair up = new UnifyPair(a, theta, PairOperator.EQUALSDOT, pair.getSubstitution(), pair); - Iterator upit = up.getRhsType().getTypeParams().iterator(); - //TODO PL 2019-01-24: upit.next() ist nicht unbedingt ein PlaceholderType -> Visitor erledigt - while (upit.hasNext()) upit.next().accept(new distributeVariance(), a.getVariance());//((PlaceholderType)upit.next()).setVariance(a.getVariance()); - resultPrime.add(up); - } - else { - UnifyPair up = new UnifyPair(a, theta.setTypeParams(new TypeParams(freshTphs.toArray(new UnifyType[0]))), PairOperator.EQUALSDOT, pair.getSubstitution(), pair); - Iterator upit = up.getRhsType().getTypeParams().iterator(); - distributeVariance dv = new distributeVariance(); - //TODO PL 2019-01-24: upit.next() ist nicht unbedingt ein PlaceholderType -> Visitor erledigt - while (upit.hasNext()) upit.next().accept(new distributeVariance(), a.getVariance()); //((PlaceholderType)upit.next()).setVariance(a.getVariance()); - resultPrime.add(up); - } - resultPrime.addAll(substitutionSet); - //writeLog("Substitution: " + substitutionSet.toString()); - resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); - result.add(resultPrime); - //writeLog("Result: " + resultPrime.toString()); - //writeLog("MAX: " + oup.max(resultPrime.iterator()).toString()); - } - } - - } - } - - return result; - } - - /** - * Cartesian Product Case 2: (a <.? ? ext Theta') - */ - private Set> unifyCase2(UnifyPair pair, IFiniteClosure fc) { - PlaceholderType a = (PlaceholderType) pair.getLhsType(); - ExtendsType extThetaPrime = (ExtendsType) pair.getRhsType(); - byte variance = pair.getVariance(); - Set> result = new HashSet<>(); - - UnifyType aPrime = PlaceholderType.freshPlaceholder(); - ((PlaceholderType)aPrime).setVariance(((PlaceholderType)a).getVariance()); - ((PlaceholderType)aPrime).disableWildcardtable(); - UnifyType extAPrime = new ExtendsType(aPrime); - UnifyType thetaPrime = extThetaPrime.getExtendedType(); - Set resultPrime = new HashSet<>(); - resultPrime.add(new UnifyPair(a, thetaPrime, PairOperator.SMALLERDOT, pair.getSubstitution(), pair)); - result.add(resultPrime); - - resultPrime = new HashSet<>(); - resultPrime.add(new UnifyPair(a, extAPrime, PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); - resultPrime.add(new UnifyPair(aPrime, thetaPrime, PairOperator.SMALLERDOT, pair.getSubstitution(), pair)); - resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); - result.add(resultPrime); - //writeLog("Result: " + resultPrime.toString()); - return result; - } - - /** - * Cartesian Product Case 3: (a <.? ? sup Theta') - */ - private Set> unifyCase3(UnifyPair pair, IFiniteClosure fc) { - PlaceholderType a = (PlaceholderType) pair.getLhsType(); - a.reversVariance(); - SuperType subThetaPrime = (SuperType) pair.getRhsType(); - byte variance = pair.getVariance(); - Set> result = new HashSet<>(); - - UnifyType aPrime = PlaceholderType.freshPlaceholder(); - ((PlaceholderType)aPrime).setVariance(((PlaceholderType)a).getVariance()); - ((PlaceholderType)aPrime).disableWildcardtable(); - UnifyType supAPrime = new SuperType(aPrime); - UnifyType thetaPrime = subThetaPrime.getSuperedType(); - Set resultPrime = new HashSet<>(); - resultPrime.add(new UnifyPair(thetaPrime, a, PairOperator.SMALLERDOT, pair.getSubstitution(), pair, pair.getfBounded())); - result.add(resultPrime); - //writeLog(resultPrime.toString()); - - resultPrime = new HashSet<>(); - resultPrime.add(new UnifyPair(a, supAPrime, PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); - resultPrime.add(new UnifyPair(thetaPrime, aPrime, PairOperator.SMALLERDOT, pair.getSubstitution(), pair)); - resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); - result.add(resultPrime); - //writeLog(resultPrime.toString()); - - return result; - } - - /** - * Cartesian Product Case 5: (Theta <. a) - */ - private Set> unifyCase5(UnifyPair pair, IFiniteClosure fc) { - UnifyType theta = pair.getLhsType(); - PlaceholderType a = (PlaceholderType) pair.getRhsType(); - byte variance = pair.getVariance(); - Set> result = new HashSet<>(); - - boolean allGen = theta.getTypeParams().size() > 0; - for(UnifyType t : theta.getTypeParams()) - if(!(t instanceof PlaceholderType) || !((PlaceholderType) t).isGenerated()) { - allGen = false; - break; - } - - //eingefuegt PL 2019-01-03 ANFANG - //fc.setLogTrue(); - //writeLog("FBOUNDED: " + pair.getfBounded()); - //writeLog("Pair: " + pair); - Set greater = fc.greater(theta, pair.getfBounded()); - //writeLog("GREATER: " + greater + pair + "THETA: " + theta + "FBOUNDED: " + pair.getfBounded() + " "); - if (a.isWildcardable()) { - Set greater_ext = greater.stream().filter(x -> !(x instanceof ExtendsType) && !(x instanceof SuperType)) - .map(x -> { - //BinaryOperator> combiner = (aa,b) -> { aa.putAll(b); return aa;}; //Variablenumbenennung rausgenommen - //HashMap hm = x.getInvolvedPlaceholderTypes().stream() //Variablen muessen wahrscheinlich erhalten bleiben - // .reduce(new HashMap(), - // (aa, b)-> { aa.put(b,PlaceholderType.freshPlaceholder()); return aa; }, combiner); - return new SuperType (x);})//.accept(new freshPlaceholder(), hm));} - .collect(Collectors.toCollection(HashSet::new)); - greater.addAll(greater_ext); - } - //eingefuegt PL 2019-01-03 ENDE - - //for(UnifyType thetaS : fc.greater(theta, pair.getfBounded())) { - for(UnifyType thetaS : greater) { - Set resultPrime = new HashSet<>(); - Match match = new Match(); - - UnifyType[] freshTphs = new UnifyType[thetaS.getTypeParams().size()]; - for(int i = 0; !allGen && i < freshTphs.length; i++) { - freshTphs[i] = PlaceholderType.freshPlaceholder(); - ((PlaceholderType)freshTphs[i]).setVariance(((PlaceholderType)a).getVariance()); - Set fBounded = new HashSet<>(pair.getfBounded()); //PL 2019-01-09 new HashSet eingefuegt - - int i_ef = i; - BiFunction f = (x,y) -> - { - ArrayList termList = new ArrayList(); - termList.add(new UnifyPair(y,thetaS.getTypeParams().get(i_ef), PairOperator.EQUALSDOT)); - return ((match.match(termList).isPresent()) || x); - }; - //if (parai.getName().equals("java.lang.Integer")) { - // System.out.println(""); - //} - BinaryOperator bo = (x,y) -> (x || y); - if (fBounded.stream().reduce(false,f,bo)) { - resultPrime.add(new UnifyPair(freshTphs[i], thetaS.getTypeParams().get(i), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); - } - else { - fBounded.add(thetaS.getTypeParams().get(i)); - resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair, fBounded)); - } - } - - if(allGen) - resultPrime.add(new UnifyPair(a, thetaS, PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); - else - resultPrime.add(new UnifyPair(a, thetaS.setTypeParams(new TypeParams(freshTphs)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); - resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); - result.add(resultPrime); - //writeLog("FBOUNDED2: " + pair.getfBounded()); - //writeLog("resultPrime Theta < a: " + greater + pair + "THETA: " + theta + "FBOUNDED: " + pair.getfBounded() + " " + resultPrime.toString()); - } - - return result; - } - - /** - * Cartesian Product Case 8: (Theta <.? a) - */ - private Set> unifyCase8(UnifyPair pair, IFiniteClosure fc) { - UnifyType theta = pair.getLhsType(); - PlaceholderType a = (PlaceholderType) pair.getRhsType(); - byte variance = pair.getVariance(); - Set> result = new HashSet<>(); - //for(UnifyType thetaS : fc.grArg(theta)) { - Set resultPrime = new HashSet<>(); - resultPrime.add(new UnifyPair(a, theta, PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); - result.add(resultPrime); - //writeLog(resultPrime.toString()); - - UnifyType freshTph = PlaceholderType.freshPlaceholder(); - - ((PlaceholderType)freshTph).setVariance(a.getVariance()); - ((PlaceholderType)freshTph).disableWildcardtable(); - resultPrime = new HashSet<>(); - resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); - resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair, pair.getfBounded())); - result.add(resultPrime); - //writeLog("resultPrime: " + resultPrime.toString()); - - resultPrime = new HashSet<>(); - resultPrime.add(new UnifyPair(a, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); - resultPrime.add(new UnifyPair(freshTph, theta, PairOperator.SMALLERDOT, pair.getSubstitution(), pair)); - resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); - result.add(resultPrime); - //writeLog(resultPrime.toString()); - //} - - return result; - } - - /** - * Takes a set of candidates for each position and computes all possible permutations. - * @param candidates The length of the list determines the number of type params. Each set - * contains the candidates for the corresponding position. - */ - protected Set permuteParams(ArrayList> candidates) { - Set result = new HashSet<>(); - permuteParams(candidates, 0, result, new UnifyType[candidates.size()]); - return result; - } - - /** - * Takes a set of candidates for each position and computes all possible permutations. - * @param candidates The length of the list determines the number of type params. Each set - * contains the candidates for the corresponding position. - * @param idx Idx for the current permutatiton. - * @param result Set of all permutations found so far - * @param current The permutation of type params that is currently explored - */ - private void permuteParams(ArrayList> candidates, int idx, Set result, UnifyType[] current) { - if(candidates.size() == idx) { - result.add(new TypeParams(Arrays.copyOf(current, current.length))); - return; - } - - Set localCandidates = candidates.get(idx); - - for(UnifyType t : localCandidates) { - current[idx] = t; - permuteParams(candidates, idx+1, result, current); - } - } - - void writeLog(String str) { - synchronized ( this ) { - if (log) { - try { - logFile.write("Thread no.:" + thNo + "\n"); - logFile.write("noOfThread:" + noOfThread + "\n"); - logFile.write("parallel:" + parallel + "\n"); - logFile.write(str+"\n\n"); - logFile.flush(); - - } - catch (IOException e) { - System.err.println("kein LogFile"); - } - } - } - } -} +//PL 2018-12-19: Merge checken +package de.dhbwstuttgart.typeinference.unify; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.RecursiveTask; +import java.util.function.BiFunction; +import java.util.function.BinaryOperator; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.apache.commons.io.output.NullOutputStream; + +import de.dhbwstuttgart.exceptions.TypeinferenceException; +import de.dhbwstuttgart.parser.NullToken; +import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; +import de.dhbwstuttgart.typeinference.constraints.Constraint; +import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet; +import de.dhbwstuttgart.typeinference.unify.interfaces.ISetOperations; +import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify; +import de.dhbwstuttgart.typeinference.unify.model.ExtendsType; +import de.dhbwstuttgart.typeinference.unify.model.FunNType; +import de.dhbwstuttgart.typeinference.unify.model.PairOperator; +import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; +import de.dhbwstuttgart.typeinference.unify.model.ReferenceType; +import de.dhbwstuttgart.typeinference.unify.model.SuperType; +import de.dhbwstuttgart.typeinference.unify.model.TypeParams; +import de.dhbwstuttgart.typeinference.unify.model.Unifier; +import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; +import de.dhbwstuttgart.typeinference.unify.model.UnifyType; +import de.dhbwstuttgart.typeinference.unify.model.WildcardType; +import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair; +import de.dhbwstuttgart.typeinference.unify.model.Pair; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Writer; + +import com.google.common.collect.Ordering; + + +/** + * Implementation of the type unification algorithm + * @author Florian Steurer + */ +public class TypeUnifyTask extends RecursiveTask>> { + + private static final long serialVersionUID = 1L; + private static int i = 0; + private boolean printtag = false; + Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll? + + /** + * Element, das aus dem nextSet den Gleichunen dieses Threads hinzugefuegt wurde + */ + Set nextSetElement; + + /** + * Fuer die Threads + */ + UnifyResultModel urm; + protected static int noOfThread = 0; + private static int totalnoOfThread = 0; + int thNo; + protected boolean one = false; + Integer MaxNoOfThreads = 8; + + public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/"; + Writer logFile; + + /** + * The implementation of setOps that will be used during the unification + */ + protected ISetOperations setOps = new GuavaSetOperations(); + + /** + * The implementation of the standard unify that will be used during the unification + */ + protected IUnify stdUnify = new MartelliMontanariUnify(); + + /** + * The implementation of the rules that will be used during the unification. + */ + protected IRuleSet rules; + + protected Set eq; //und-constraints + + protected List>> oderConstraintsField; + + protected IFiniteClosure fc; + + protected Ordering> oup; + + protected boolean parallel; + + int rekTiefeField; + + Integer nOfUnify = 0; + + Integer noUndefPair = 0; + + Integer noAllErasedElements = 0; + + static Integer noou = 0; + + static int noBacktracking; + + static Integer noShortendElements = 0; + + Boolean myIsCanceled = false; + + volatile UnifyTaskModel usedTasks; + + public TypeUnifyTask() { + rules = new RuleSet(); + } + + /* + public TypeUnifyTask(Set eq, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log) { + this.eq = eq; + this.fc = fc; + this.oup = new OrderingUnifyPair(fc); + this.parallel = parallel; + this.logFile = logFile; + this.log = log; + rules = new RuleSet(logFile); + noOfThread++; + thNo = noOfThread; + } + */ + + + public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) { + synchronized (this) { + this.eq = eq; + //this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new)); + this.oderConstraintsField = oderConstraints; /*.stream().map(x -> { + Set> ret = new HashSet<>(); + for (Constraint y : x) { + ret.add(new HashSet<>(y)); + } + return ret; + }).collect(Collectors.toCollection(ArrayList::new)); + */ + + //x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new)); + this.nextSetElement = nextSetElement; + this.fc = fc; + this.oup = new OrderingUnifyPair(fc); + this.parallel = parallel; + this.logFile = logFile; + this.log = log; + + noOfThread++; + totalnoOfThread++; + //writeLog("thNo1 " + thNo); + thNo = totalnoOfThread; + writeLog("thNo2 " + thNo); + try { + this.logFile = //new OutputStreamWriter(new NullOutputStream()); + //new FileWriter(new File(System.getProperty("user.dir")+"/src/test/resources/logFiles/"+"Thread_"+thNo)); + new FileWriter(new File(System.getProperty("user.dir")+"/logFiles/"+"Thread_"+thNo)); + logFile.write(""); + } + catch (IOException e) { + System.err.println("log-File nicht vorhanden"); + } + /*Abbruchtest + if (thNo > 10) { + System.out.println("cancel"); + usedTasks.cancel(); + writeLog(nOfUnify.toString() + "cancel"); + System.out.println("cancel"); + } + */ + rules = new RuleSet(logFile); + this.rekTiefeField = rekTiefe; + this.urm = urm; + this.usedTasks = usedTasks; + this.usedTasks.add(this); + } + } + + /** + * Vererbt alle Variancen + * @param eq The set of constraints + */ + /* PL 2018-05- 17 verschoben nach JavaTXCompiler + private void varianceInheritance(Set eq) { + Set usedTPH = new HashSet<>(); + Set phSet = eq.stream().map(x -> { + Set pair = new HashSet<>(); + if (x.getLhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getLhsType()); + if (x.getRhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getRhsType()); + return pair; + }).reduce(new HashSet<>(), (a,b) -> { a.addAll(b); return a;} , (c,d) -> { c.addAll(d); return c;}); + + ArrayList phSetVariance = new ArrayList<>(phSet); + phSetVariance.removeIf(x -> (x.getVariance() == 0)); + while(!phSetVariance.isEmpty()) { + PlaceholderType a = phSetVariance.remove(0); + usedTPH.add(a); + //HashMap ht = new HashMap<>(); + //ht.put(a, a.getVariance()); + Set eq1 = new HashSet<>(eq); + eq1.removeIf(x -> !(x.getLhsType() instanceof PlaceholderType && ((PlaceholderType)x.getLhsType()).equals(a))); + eq1.stream().forEach(x -> { x.getRhsType().accept(new distributeVariance(), a.getVariance());}); + eq1 = new HashSet<>(eq); + eq1.removeIf(x -> !(x.getRhsType() instanceof PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a))); + eq1.stream().forEach(x -> { x.getLhsType().accept(new distributeVariance(), a.getVariance());}); + phSetVariance = new ArrayList<>(phSet); + phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x))); + } +} +*/ + void myCancel(Boolean b) { + myIsCanceled = true; + } + + public boolean myIsCancelled() { + return myIsCanceled; + } + + protected Set> compute() { + if (one) { + System.out.println("two"); + } + one = true; + Set neweq = new HashSet<>(eq); + /* 1-elementige Oder-Constraints werden in und-Constraints umgewandelt */ + oderConstraintsField.stream() + .filter(x -> x.size()==1) + .map(y -> y.stream().findFirst().get()).forEach(x -> neweq.addAll(x)); + ArrayList>> remainingOderconstraints = oderConstraintsField.stream() + .filter(x -> x.size()>1) + .collect(Collectors.toCollection(ArrayList::new)); + Set> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField, true); + noOfThread--; + try { + logFile.close(); + } + catch (IOException ioE) { + System.err.println("no log-File"); + } + if (isUndefinedPairSetSet(res)) { + throw new TypeinferenceException("Unresolved constraints: " + res.toString(), new NullToken()); //return new HashSet<>(); + } + else { + synchronized (usedTasks) { + if (this.myIsCancelled()) { + return new HashSet<>(); + } + else { + return res; + } + } + } + } +/* + @Override + protected Set> compute() { + Set> fstElems = new HashSet<>(); + fstElems.add(eq); + Set> res = computeCartesianRecursiveOderConstraints(fstElems, oderConstraints, fc, parallel); + if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } + else return res; + } +*/ + + + + + /** + * Computes all principal type unifiers for a set of constraints. + * @param eq The set of constraints + * @param fc The finite closure + * @return The set of all principal type unifiers + */ + protected Set> unify(final Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) { + //Set aas = eq.stream().filter(x -> x.getLhsType().getName().equals("AA") //&& x.getPairOp().equals(PairOperator.SMALLERDOT) + // ).collect(Collectors.toCollection(HashSet::new)); + //writeLog(nOfUnify.toString() + " AA: " + aas.toString()); + //if (aas.isEmpty()) { + // System.out.println(""); + //} + + //.collect(Collectors.toCollection(HashSet::new))); + /* + * Step 1: Repeated application of reduce, adapt, erase, swap + */ + + rekTiefe++; + nOfUnify++; + writeLog(nOfUnify.toString() + " Unifikation: " + eq.toString()); + writeLog(nOfUnify.toString() + " Oderconstraints: " + oderConstraints.toString()); + //eq = eq.stream().map(x -> {x.setVariance((byte)-1); return x;}).collect(Collectors.toCollection(HashSet::new)); + + /* + * Variancen auf alle Gleichungen vererben + */ + //PL 2018-05-17 nach JavaTXCompiler verschoben + //varianceInheritance(eq); + + /* + * ? extends ? extends Theta rausfiltern + */ + Set doubleExt = eq.stream().filter(x -> (x.wrongWildcard())).map(x -> { x.setUndefinedPair(); return x;}) + .collect(Collectors.toCollection(HashSet::new)); + if (doubleExt.size() > 0) { + Set> ret = new HashSet<>(); + ret.add(doubleExt); + return ret; + } + + Set eq0; + Set eq0Prime; + Optional> eqSubst = Optional.of(eq); + do { + eq0Prime = eqSubst.get(); + eq0 = applyTypeUnificationRules(eq0Prime, fc); + eqSubst = rules.subst(eq0, oderConstraints); + } while (eqSubst.isPresent()); + + eq0.forEach(x -> x.disableCondWildcards()); + + writeLog(nOfUnify.toString() + " Unifikation nach applyTypeUnificationRules: " + eq.toString()); + writeLog(nOfUnify.toString() + " Oderconstraints nach applyTypeUnificationRules: " + oderConstraints.toString()); + + /* + * Step 2 and 3: Create a subset eq1s of pairs where both sides are TPH and eq2s of the other pairs + */ + Set eq1s = new HashSet<>(); + Set eq2s = new HashSet<>(); + splitEq(eq0, eq1s, eq2s); + + /* + * Step 4: Create possible typings + * + * "Manche Autoren identifizieren die Paare (a, (b,c)) und ((a,b),c) + * mit dem geordneten Tripel (a,b,c), wodurch das kartesische Produkt auch assoziativ wird." - Wikipedia + */ + + // There are up to 10 toplevel set. 8 of 10 are the result of the + // cartesian product of the sets created by pattern matching. + List>> topLevelSets = new ArrayList<>(); + + //System.out.println(eq2s); + + if(eq1s.size() != 0) { // Do not add empty sets or the cartesian product will always be empty. + Set> wrap = new HashSet<>(); + wrap.add(eq1s); + topLevelSets.add(wrap); // Add Eq1' + } + + // Add the set of [a =. Theta | (a=. Theta) in Eq2'] + //TODO: Occurscheck anwenden als Fehler identifizieren + Set bufferSet = eq2s.stream() + .filter(x -> x.getPairOp() == PairOperator.EQUALSDOT && x.getLhsType() instanceof PlaceholderType) + .collect(Collectors.toSet()); + + if(bufferSet.size() != 0) { // Do not add empty sets or the cartesian product will always be empty. + Set> wrap = new HashSet<>(); + wrap.add(bufferSet); + topLevelSets.add(wrap); + eq2s.removeAll(bufferSet); + } + + // Sets that originate from pair pattern matching + // Sets of the "second level" + Set undefinedPairs = new HashSet<>(); + if (printtag) System.out.println("eq2s " + eq2s); + //writeLog("BufferSet: " + bufferSet.toString()+"\n"); + List>> oderConstraintsOutput = new ArrayList<>();//new ArrayList<>(oderConstraints); + Set>>> secondLevelSets = calculatePairSets(eq2s, oderConstraints, fc, undefinedPairs, oderConstraintsOutput); + //PL 2017-09-20: Im calculatePairSets wird möglicherweise O .< java.lang.Integer + //nicht ausgewertet Faculty Beispiel im 1. Schritt + //PL 2017-10-03 geloest, muesste noch mit FCs mit kleineren + //Typen getestet werden. + writeLog(nOfUnify.toString() + " Oderconstraints2: " + oderConstraintsOutput.toString()); + if (printtag) System.out.println("secondLevelSets:" +secondLevelSets); + // If pairs occured that did not match one of the cartesian product cases, + // those pairs are contradictory and the unification is impossible. + if(!undefinedPairs.isEmpty()) { + noUndefPair++; + for (UnifyPair up : undefinedPairs) { + writeLog(noUndefPair.toString() + " UndefinedPairs; " + up); + writeLog("BasePair; " + up.getBasePair()); + } + Set> error = new HashSet<>(); + undefinedPairs = undefinedPairs.stream().map(x -> { x.setUndefinedPair(); return x;}).collect(Collectors.toCollection(HashSet::new)); + error.add(undefinedPairs); + undefinedPairs.forEach(x -> writeLog("AllSubst: " +x.getAllSubstitutions().toString())); + return error; + } + + /* Up to here, no cartesian products are calculated. + * filters for pairs and sets can be applied here */ + + // Alternative: Sub cartesian products of the second level (pattern matched) sets + // "the big (x)" + /* for(Set>> secondLevelSet : secondLevelSets) { + //System.out.println("secondLevelSet "+secondLevelSet.size()); + List>> secondLevelSetList = new ArrayList<>(secondLevelSet); + Set>> cartResult = setOps.cartesianProduct(secondLevelSetList); + //System.out.println("CardResult: "+cartResult.size()); + // Flatten and add to top level sets + Set> flat = new HashSet<>(); + int j = 0; + for(List> s : cartResult) { + j++; + //System.out.println("s from CardResult: "+cartResult.size() + " " + j); + Set flat1 = new HashSet<>(); + for(Set s1 : s) + flat1.addAll(s1); + flat.add(flat1); + } + //topLevelSets.add(flat); + } + */ + + //Alternative KEIN KARTESISCHES PRODUKT der secondlevel Ebene bilden + for(Set>> secondLevelSet : secondLevelSets) { + for (Set> secondlevelelem : secondLevelSet) { + topLevelSets.add(secondlevelelem); + } + } + //System.out.println(topLevelSets); + //System.out.println(); + + + //Aufruf von computeCartesianRecursive ANFANG + //writeLog("topLevelSets: " + topLevelSets.toString()); + return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe, finalresult); + + } + + + Set> unify2(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) { + //Aufruf von computeCartesianRecursive ENDE + + //keine Ahnung woher das kommt + //Set> setToFlatten = topLevelSets.stream().map(x -> x.iterator().next()).collect(Collectors.toCollection(HashSet::new)); + + //Muss auskommentiert werden, wenn computeCartesianRecursive ANFANG + // Cartesian product over all (up to 10) top level sets + //Set>> eqPrimeSet = setOps.cartesianProduct(topLevelSets) + // .stream().map(x -> new HashSet<>(x)) + // .collect(Collectors.toCollection(HashSet::new)); + //Muss auskommentiert werden, wenn computeCartesianRecursive ENDE + + + + Set> eqPrimePrimeSet = new HashSet<>(); + + Set forks = new HashSet<>(); + + //Muss auskommentiert werden, wenn computeCartesianRecursive ANFANG + //for(Set> setToFlatten : eqPrimeSet) { + // Flatten the cartesian product + //Muss auskommentiert werden, wenn computeCartesianRecursive ENDE + Set eqPrime = new HashSet<>(); + setToFlatten.stream().forEach(x -> eqPrime.addAll(x)); + + /* + * Step 5: Substitution + */ + //writeLog("vor Subst: " + eqPrime); + writeLog("vor Subst: " + oderConstraints); + String ocString = oderConstraints.toString(); + List>> newOderConstraints = new ArrayList<>(oderConstraints); + Optional> eqPrimePrime = rules.subst(eqPrime, newOderConstraints); + Set> unifyres1 = null; + Set> unifyres2 = null; + if (!ocString.equals(newOderConstraints.toString())) writeLog("nach Subst: " + newOderConstraints); + //writeLog("nach Subst: " + eqPrimePrime); + /* + * Step 6 a) Restart (fork) for pairs where subst was applied + */ + /* + if(parallel) { + if (eqPrime.equals(eq) && !eqPrimePrime.isPresent() + && oderConstraints.isEmpty()) //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch + //PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent()) + //PL 2018-05-18 beide Bedingungen muessen gelten, da eqPrime Veränderungen in allem ausser subst + //eqPrimePrime Veraenderungen in subst repraesentieren. + eqPrimePrimeSet.add(eqPrime); + else if(eqPrimePrime.isPresent()) { + //System.out.println("nextStep: " + eqPrimePrime.get()); + TypeUnifyTask fork = new TypeUnifyTask(eqPrimePrime.get(), fc, true, logFile, log); + forks.add(fork); + fork.fork(); + } + else { + //System.out.println("nextStep: " + eqPrime); + TypeUnifyTask fork = new TypeUnifyTask(eqPrime, fc, true, logFile, log); + forks.add(fork); + fork.fork(); + } + } + else */ + {// sequentiell (Step 6b is included) + if (printtag) System.out.println("nextStep: " + eqPrimePrime); + if (eqPrime.equals(eq) && !eqPrimePrime.isPresent() + && oderConstraints.isEmpty()) { //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch + //PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent()) + //PL 2018-05-18 beide Bedingungen muessen gelten, da eqPrime Veränderungen in allem ausser subst + //eqPrimePrime Veraenderungen in subst repraesentieren. + //try { + //if (isSolvedForm(eqPrime)) { + // writeLog("eqPrime:" + eqPrime.toString()+"\n"); + //} + //} + //catch (IOException e) { + // System.err.println("log-File nicht vorhanden"); + //} + eqPrimePrimeSet.add(eqPrime); + if (finalresult && isSolvedForm(eqPrime)) { + writeLog("eqPrime:" + eqPrime.toString()+"\n"); + urm.notify(eqPrimePrimeSet); + } + } + else if(eqPrimePrime.isPresent()) { + Set> unifyres = unifyres1 = unify(eqPrimePrime.get(), newOderConstraints, fc, parallel, rekTiefe, finalresult); + + eqPrimePrimeSet.addAll(unifyres); + } + else { + Set> unifyres = unifyres2 = unify(eqPrime, newOderConstraints, fc, parallel, rekTiefe, finalresult); + + + eqPrimePrimeSet.addAll(unifyres); + } + } + //Muss auskommentiert werden, wenn computeCartesianRecursive ANFANG + //} + //Muss auskommentiert werden, wenn computeCartesianRecursive ENDE + + /* + * Step 6 b) Build the union over everything. + */ + /* + * PL 2019-01-22: geloescht + + if(parallel) + for(TypeUnifyTask fork : forks) + eqPrimePrimeSet.addAll(fork.join()); + */ + /* + * Step 7: Filter empty sets; + */ + eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new)); + if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet)) { + writeLog("Result1 " + eqPrimePrimeSet.toString()); + } + return eqPrimePrimeSet; + } + + + + Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) { + //ArrayList>> remainingSets = new ArrayList<>(topLevelSets); + + fstElems.addAll(topLevelSets.stream() + .filter(x -> x.size()==1) + .map(y -> y.stream().findFirst().get()) + .collect(Collectors.toCollection(HashSet::new))); + ArrayList>> remainingSets = topLevelSets.stream() + .filter(x -> x.size()>1) + .collect(Collectors.toCollection(ArrayList::new)); + if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig + Set> result = unify2(fstElems, eq, oderConstraints, fc, parallel, rekTiefe, finalresult); + return result; + } + Set> nextSet = remainingSets.remove(0); + writeLog("nextSet: " + nextSet.toString()); + List> nextSetasList =new ArrayList<>(nextSet); + try { + //List> + //nextSetasList = oup.sortedCopy(nextSet);//new ArrayList<>(nextSet); + } + catch (java.lang.IllegalArgumentException e) { + System.out.print(""); + } + Set> result = new HashSet<>(); + int variance = 0; + + ArrayList zeroNextElem = new ArrayList<>(nextSetasList.get(0)); + UnifyPair fstBasePair = zeroNextElem.remove(0).getBasePair(); + + if (fstBasePair != null) { + Boolean sameBase = true; + for (UnifyPair ele : nextSetasList.get(0)) {//check ob a <. ty base oder ob Ueberladung + sameBase = sameBase && ele.getBasePair() != null && ele.getBasePair().equals(fstBasePair); + } + if (sameBase) { + Optional xi = nextSetasList.stream().map(x -> x.stream().filter(y -> y.getLhsType() instanceof PlaceholderType) + .filter(z -> ((PlaceholderType)z.getLhsType()).getVariance() != 0) + .map(c -> ((PlaceholderType)c.getLhsType()).getVariance()) + .reduce((a,b)-> {if (a==b) return a; else return 0; })) //2 kommt insbesondere bei Oder-Constraints vor + .filter(d -> d.isPresent()) + .map(e -> e.get()) + .findAny(); + if (xi.isPresent()) { + variance = xi.get(); + } + } + else { + variance = 2; + } + + } + else { + variance = 2; + } + //if (variance == 1 && nextSetasList.size() > 1) { + // List> al = new ArrayList<>(nextSetasList.size()); + // for (int ii = 0; ii < nextSetasList.size();ii++) { + // al.add(0,nextSetasList.get(ii)); + // } + // nextSetasList = al; + //} + //Set a = nextSetasListIt.next(); + /*if (nextSetasList.size()>1) {zu loeschen + if (nextSetasList.iterator().next().iterator().next().getLhsType().getName().equals("D")) + System.out.print(""); + if (variance == 1) { + a_next = oup.max(nextSetasList.iterator()); + } + else if (variance == -1) { + a_next = oup.min(nextSetasList.iterator()); + } + else if (variance == 0) { + a_next = nextSetasList.iterator().next(); + } + } + else { + a_next = nextSetasList.iterator().next(); + } + */ + if (!nextSetasList.iterator().hasNext()) + System.out.print(""); + if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1) + System.out.print(""); + writeLog("nextSetasList: " + nextSetasList.toString()); + Set nextSetElem = nextSetasList.get(0); + writeLog("BasePair1: " + nextSetElem + " " + nextSetElem.iterator().next().getBasePair()); + + /* sameEqSet-Bestimmung: Wenn a = ty \in nextSet dann enthaelt sameEqSet alle Paare a < ty1 oder ty2 < a aus fstElems */ + Set sameEqSet = new HashSet<>(); + if (variance != 2) { + Optional optOrigPair = nextSetElem.stream().filter(x -> ( + //x.getBasePair() != null && ist gegeben wenn variance != 2 + //x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && + (x.getPairOp().equals(PairOperator.EQUALSDOT) + /* + (x.getBasePair().getLhsType() instanceof PlaceholderType + && x.getLhsType().equals(x.getBasePair().getLhsType())) + || (x.getBasePair().getRhsType() instanceof PlaceholderType + && x.getLhsType().equals(x.getBasePair().getRhsType()) + */ + ))).filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist + x.getLhsType().equals(x.getBasePair().getLhsType()) || + x.getLhsType().equals(x.getBasePair().getRhsType()) + ).findFirst(); + writeLog("optOrigPair: " + optOrigPair); + if (optOrigPair.isPresent()) { + UnifyPair origPair = optOrigPair.get(); + UnifyType tyVar; + if (!((tyVar = origPair.getLhsType()) instanceof PlaceholderType)) { + tyVar = origPair.getRhsType(); + } + UnifyType tyVarEF = tyVar; + sameEqSet = fstElems.stream().map(xx -> xx.iterator().next()) + .filter(x -> (((x.getLhsType().equals(tyVarEF) && !(x.getRhsType() instanceof PlaceholderType)) + || (x.getRhsType().equals(tyVarEF) && !(x.getLhsType() instanceof PlaceholderType))))) + .collect(Collectors.toCollection(HashSet::new)); + } + } + /* sameEqSet-Bestimmung Ende */ + + Set a = null; + while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) { + Set a_last = a; + List> nextSetasListRest = new ArrayList<>(); + //List> nextSetasListRestMin = new ArrayList<>(); + //List> nextSetasListRestOder = new ArrayList<>(); + if (variance == 1) { + a = oup.max(nextSetasList.iterator()); + nextSetasList.remove(a); + nextSetasListRest = new ArrayList<>(nextSetasList); + Iterator> nextSetasListItRest = new ArrayList>(nextSetasListRest).iterator(); + while (nextSetasListItRest.hasNext()) { + Set a_next = nextSetasListItRest.next(); + if (//a.equals(a_next) || + (oup.compare(a, a_next) == 1)) { + nextSetasListRest.remove(a_next); + } + } + //Alle maximale Elemente in nextSetasListRest bestimmen + List> nextSetasListRestTest; + do { + nextSetasListRestTest = new ArrayList>(nextSetasListRest); + if (!nextSetasListRest.isEmpty()) { + Set max = oup.max(nextSetasListRest.iterator()); + Iterator> nextSetasListItRest2 = new ArrayList>(nextSetasListRest).iterator(); + while (nextSetasListItRest2.hasNext()) { + Set a_nextRest = nextSetasListItRest2.next(); + if (//a.equals(a_next) || + (oup.compare(max, a_nextRest) == 1)) { + nextSetasListRest.remove(a_nextRest); + } + + }} + } while(!nextSetasListRestTest.equals(nextSetasListRest)); + + } + else if (variance == -1) { + a = oup.min(nextSetasList.iterator()); + nextSetasList.remove(a); + nextSetasListRest = new ArrayList<>(nextSetasList); + Iterator> nextSetasListItRest = new ArrayList>(nextSetasListRest).iterator(); + while (nextSetasListItRest.hasNext()) { + Set a_next = nextSetasListItRest.next(); + if (//a.equals(a_next) || + (oup.compare(a, a_next) == -1)) { + nextSetasListRest.remove(a_next); + } + } + //Alle minimalen Elemente in nextSetasListRest bestimmen + + List> nextSetasListRestTest; + do { + nextSetasListRestTest = new ArrayList>(nextSetasListRest); + if (!nextSetasListRest.isEmpty()) { + Set min = oup.min(nextSetasListRest.iterator()); + Iterator> nextSetasListItRest2 = new ArrayList>(nextSetasListRest).iterator(); + while (nextSetasListItRest2.hasNext()) { + Set a_nextRest = nextSetasListItRest2.next(); + if (//a.equals(a_next) || + (oup.compare(min, a_nextRest) == -1)) { + nextSetasListRest.remove(a_nextRest); + } + + }} + } while(!nextSetasListRestTest.equals(nextSetasListRest)); + } + else if (variance == 2) { + a = nextSetasList.remove(0); + nextSetasListRest = new ArrayList<>(nextSetasList); + } + else if (variance == 0) { + a = nextSetasList.remove(0); + } + //writeLog("nextSet: " + nextSetasList.toString()+ "\n"); + //nextSetasList.remove(a); + /* zu loeschen + if (nextSetasList.size() > 0) { + if (nextSetasList.size()>1) { + if (variance == 1) { + a_next = oup.max(nextSetasList.iterator()); + } + else if (variance == -1) { + a_next = oup.min(nextSetasList.iterator()); + } + else { + a_next = nextSetasList.iterator().next(); + } + } + else { + a_next = nextSetasList.iterator().next(); + } + } + */ + //PL 2018-03-01 + //TODO: 1. Maximum und Minimum unterscheiden + //TODO: 2. compare noch für alle Elmemente die nicht X =. ty sind erweitern + //for(Set a : newSet) { + i++; + Set> elems = new HashSet>(fstElems); + writeLog("a1: " + rekTiefe + " "+ "variance: "+ variance + " " + a.toString()+ "\n"); + //elems.add(a); PL 2019-01-20 Muss weg, weil das in jeweiligen Thread erfolgen muss. Fuer den sequentiellen Fall + //im else-Zweig + //if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt + //writeLog("Vor unify2 Aufruf: " + elems.toString()); + Set> res = new HashSet<>(); + Set>> add_res = new HashSet<>(); + Set> aParDef = new HashSet<>(); + + /* PL 2019-03-11 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ + if (variance != 2 && !sameEqSet.isEmpty()) { + Optional optAPair = a.stream().filter(x -> ( + //x.getBasePair() != null && ist gegeben wenn variance != 2 + //x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && + (x.getPairOp().equals(PairOperator.EQUALSDOT) + /* + (x.getBasePair().getLhsType() instanceof PlaceholderType + && x.getLhsType().equals(x.getBasePair().getLhsType())) + || (x.getBasePair().getRhsType() instanceof PlaceholderType + && x.getLhsType().equals(x.getBasePair().getRhsType()) + */ + ))).filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist + x.getLhsType().equals(x.getBasePair().getLhsType()) || + x.getLhsType().equals(x.getBasePair().getRhsType()) + ).findFirst(); + + if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a + UnifyPair aPair = optAPair.get(); + //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); + writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet); + if (!checkA(aPair, sameEqSet, elems, result)) { + a = null; + noShortendElements++; + continue; + } + } + } + /* PL 2019-03-11 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ + + if(parallel && (variance == 1) && noOfThread <= MaxNoOfThreads) { + Set forks = new HashSet<>(); + Set newEqOrig = new HashSet<>(eq); + Set> newElemsOrig = new HashSet<>(elems); + List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); + newElemsOrig.add(a); + + /* FORK ANFANG */ + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); + //forks.add(forkOrig); + synchronized(usedTasks) { + if (this.myIsCancelled()) { + return new HashSet<>(); + } + forkOrig.fork(); + } + /* FORK ENDE */ + + synchronized (this) { + writeLog("a in " + variance + " "+ a); + writeLog("nextSetasListRest: " + nextSetasListRest.toString()); + } + while (!nextSetasListRest.isEmpty()) { + Set nSaL = nextSetasListRest.remove(0); + synchronized (this) { nextSetasList.remove(nSaL); + writeLog("1 RM" + nSaL.toString()); + } + + /* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ + Optional optAPair = nSaL.stream().filter(x -> ( + //x.getBasePair() != null && ist gegeben wenn variance != 2 + //x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && + (x.getPairOp().equals(PairOperator.EQUALSDOT) + /* + (x.getBasePair().getLhsType() instanceof PlaceholderType + && x.getLhsType().equals(x.getBasePair().getLhsType())) + || (x.getBasePair().getRhsType() instanceof PlaceholderType + && x.getLhsType().equals(x.getBasePair().getRhsType()) + */ + ))).filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist + x.getLhsType().equals(x.getBasePair().getLhsType()) || + x.getLhsType().equals(x.getBasePair().getRhsType()) + ).findFirst(); + + if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a + UnifyPair aPair = optAPair.get(); + //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); + writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet); + if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) { + nSaL = null; + noShortendElements++; + continue; + } + } + /* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ + + Set newEq = new HashSet<>(eq); + Set> newElems = new HashSet<>(elems); + List>> newOderConstraints = new ArrayList<>(oderConstraints); + newElems.add(nSaL); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); + forks.add(fork); + synchronized(usedTasks) { + if (this.myIsCancelled()) { + return new HashSet<>(); + } + fork.fork(); + } + } + //res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); + + /* FORK ANFANG */ + synchronized (this) { + noOfThread--; + writeLog("wait "+ forkOrig.thNo); + res = forkOrig.join(); + forkOrig.writeLog("final Orig 1"); + forkOrig.closeLogFile(); + //Set> fork_res = forkOrig.join(); + writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); + //noOfThread--; an das Ende von compute verschoben + //add_res.add(fork_res); + }; + /* FORK ENDE */ + + forks.forEach(x -> writeLog("wait: " + x.thNo)); + for(TypeUnify2Task fork : forks) { + synchronized (this) { + Set> fork_res = fork.join(); + writeLog("Join " + new Integer(fork.thNo).toString()); + //noOfThread--; an das Ende von compute verschoben + writeLog("fork_res: " + fork_res.toString()); + writeLog(new Boolean((isUndefinedPairSetSet(fork_res))).toString()); + add_res.add(fork_res); + if (!isUndefinedPairSetSet(fork_res)) { + aParDef.add(fork.getNextSetElement()); + } + fork.writeLog("final 1"); + fork.closeLogFile(); + }; + } + noOfThread++; + } else { + if(parallel && (variance == -1) && noOfThread <= MaxNoOfThreads) { + Set forks = new HashSet<>(); + Set newEqOrig = new HashSet<>(eq); + Set> newElemsOrig = new HashSet<>(elems); + List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); + newElemsOrig.add(a); + + /* FORK ANFANG */ + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); + //forks.add(forkOrig); + synchronized(usedTasks) { + if (this.myIsCancelled()) { + return new HashSet<>(); + } + forkOrig.fork(); + } + /* FORK ENDE */ + + synchronized (this) { + writeLog("a in " + variance + " "+ a); + writeLog("nextSetasListRest: " + nextSetasListRest.toString()); + } + while (!nextSetasListRest.isEmpty()) { + Set nSaL = nextSetasListRest.remove(0); + synchronized (this) { nextSetasList.remove(nSaL); + writeLog("-1 RM" + nSaL.toString()); + } + + /* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ + Optional optAPair = nSaL.stream().filter(x -> ( + //x.getBasePair() != null && ist gegeben wenn variance != 2 + //x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && + (x.getPairOp().equals(PairOperator.EQUALSDOT) + /* + (x.getBasePair().getLhsType() instanceof PlaceholderType + && x.getLhsType().equals(x.getBasePair().getLhsType())) + || (x.getBasePair().getRhsType() instanceof PlaceholderType + && x.getLhsType().equals(x.getBasePair().getRhsType()) + */ + ))).filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist + x.getLhsType().equals(x.getBasePair().getLhsType()) || + x.getLhsType().equals(x.getBasePair().getRhsType()) + ).findFirst(); + + if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a + UnifyPair aPair = optAPair.get(); + //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); + writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet); + if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) { + nSaL = null; + noShortendElements++; + continue; + } + } + /* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ + + Set newEq = new HashSet<>(eq); + Set> newElems = new HashSet<>(elems); + List>> newOderConstraints = new ArrayList<>(oderConstraints); + newElems.add(nSaL); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); + forks.add(fork); + synchronized(usedTasks) { + if (this.myIsCancelled()) { + return new HashSet<>(); + } + fork.fork(); + } + } + //res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); + + /* FORK ANFANG */ + synchronized (this) { + noOfThread--; + writeLog("wait "+ forkOrig.thNo); + res = forkOrig.join(); + forkOrig.writeLog("final Orig -1"); + forkOrig.closeLogFile(); + //Set> fork_res = forkOrig.join(); + writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); + //noOfThread--; an das Ende von compute verschoben + //add_res.add(fork_res); + }; + /* FORK ENDE */ + + forks.forEach(x -> writeLog("wait: " + x.thNo)); + for(TypeUnify2Task fork : forks) { + synchronized (this) { + Set> fork_res = fork.join(); + writeLog("Join " + new Integer(fork.thNo).toString()); + //noOfThread--; an das Ende von compute verschoben + writeLog("fork_res: " + fork_res.toString()); + writeLog(new Boolean((isUndefinedPairSetSet(fork_res))).toString()); + add_res.add(fork_res); + if (!isUndefinedPairSetSet(fork_res)) { + aParDef.add(fork.getNextSetElement()); + } + fork.writeLog("final -1"); + fork.closeLogFile(); + }; + } + noOfThread++; + } else { + if(parallel && (variance == 2) && noOfThread <= MaxNoOfThreads) { + writeLog("var2einstieg"); + Set forks = new HashSet<>(); + Set newEqOrig = new HashSet<>(eq); + Set> newElemsOrig = new HashSet<>(elems); + List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); + newElemsOrig.add(a); + + /* FORK ANFANG */ + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); + //forks.add(forkOrig); + synchronized(usedTasks) { + if (this.myIsCancelled()) { + return new HashSet<>(); + } + forkOrig.fork(); + } + /* FORK ENDE */ + + synchronized (this) { + writeLog("a in " + variance + " "+ a); + writeLog("nextSetasListRest: " + nextSetasListRest.toString()); + } + while (!nextSetasListRest.isEmpty()) { + Set nSaL = nextSetasListRest.remove(0); + //nextSetasList.remove(nSaL); + Set newEq = new HashSet<>(eq); + Set> newElems = new HashSet<>(elems); + List>> newOderConstraints = new ArrayList<>(oderConstraints); + newElems.add(nSaL); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); + forks.add(fork); + synchronized(usedTasks) { + if (this.myIsCancelled()) { + return new HashSet<>(); + } + fork.fork(); + } + } + //res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); + + /* FORK ANFANG */ + synchronized (this) { + noOfThread--; + writeLog("wait "+ forkOrig.thNo); + res = forkOrig.join(); + forkOrig.writeLog("final Orig 2"); + forkOrig.closeLogFile(); + //Set> fork_res = forkOrig.join(); + writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); + //noOfThread--; an das Ende von compute verschoben + //add_res.add(fork_res); //vermutlich falsch + }; + /* FORK ENDE */ + forks.forEach(x -> writeLog("wait: " + x.thNo)); + for(TypeUnify2Task fork : forks) { + synchronized (this) { + Set> fork_res = fork.join(); + writeLog("Join " + new Integer(fork.thNo).toString()); + //noOfThread--; an das Ende von compute verschoben + add_res.add(fork_res); + fork.writeLog("final 2"); + fork.closeLogFile(); + }; + } + noOfThread++; + } else { + //parallel = false; //Wenn MaxNoOfThreads erreicht ist, sequentiell weiterarbeiten + elems.add(a); //PL 2019-01-16 muss das wirklich hin steht schon in Zeile 859 ja braucht man siehe Zeile 859 + res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe, finalresult); + }}} + if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { + //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen + result = res; + } + else { + if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) + || (!isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) + || result.isEmpty()) { + + if ((!result.isEmpty() && !res.isEmpty() && !isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) //korrekte Loesungen aus und-constraints + && (a.stream().map(x-> (x.getBasePair() != null)).reduce(true, (x, y) -> (x && y)))) //bei oder-Constraints nicht ausfuehren + { + //TODO: PL 2019-01-15: Bug 129: Im Moment wird nur das Maximum und das Minimum des aktuellen Elements betrachtet. + //Die zu vereinigenden Mengen können mehrere Elemente enthalten. Das ist bisher nicht berücksichtigt + + //Alle Variablen bestimmen die nicht hinzugefügt wurden in a + //PL 2018-12-28: Hier gab es eine ClassCastException, war nicht reproduzierbar + System.out.println(""); + List vars_a = + a.stream().filter(x -> ((x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) + && (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getLhsType() instanceof PlaceholderType)) + || ((x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName())) + && (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getRhsType() instanceof PlaceholderType))) + ) + .map(y -> (PlaceholderType)y.getLhsType()).collect(Collectors.toCollection(ArrayList::new)); + Set fstElemRes = res.iterator().next(); + Set compRes = fstElemRes.stream().filter(x -> vars_a.contains(((PlaceholderType)x.getLhsType()))).collect(Collectors.toCollection(HashSet::new)); + + //Alle Variablen bestimmen die nicht hinzugefügt wurden in a_last + //System.out.println(a_last); + + try {//PL eingefuegt 2019-03-06 da bei map mmer wieder Nullpointer kamen + a_last.forEach(x -> {writeLog("a_last_elem:" + x + " basepair: " + x.getBasePair());});//PL 2019-05-13 ins try hinzugefuegt Nullpointer-Exception ist in der Zeile aufgetaucht. + List varsLast_a = + a_last.stream().filter(x -> ((x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) + && (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getLhsType() instanceof PlaceholderType)) + || ((x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName()))) + && (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getRhsType() instanceof PlaceholderType))) + .map(y -> (PlaceholderType)y.getLhsType()).collect(Collectors.toCollection(ArrayList::new)); + //[(java.util.Vector <. gen_aq, , 1), (CEK =. ? extends gen_aq, 1)] KANN VORKOMMEN + //erstes Element genügt, da vars immer auf die gleichen Elemente zugeordnet werden muessen + Set fstElemResult = result.iterator().next(); + Set compResult = fstElemResult.stream().filter(x -> varsLast_a.contains(((PlaceholderType)x.getLhsType()))).collect(Collectors.toCollection(HashSet::new));; + if (variance == 1) { + writeLog("a_last:" + a_last + " a: " + a); + writeLog("varsLast_a:" + varsLast_a + " vars_a: " + vars_a); + writeLog("compResult:" + compResult + " compRes: " + compRes); + int resOfCompare = oup.compare(compResult, compRes); + if (resOfCompare == -1) { + writeLog("Geloescht result: " + result); + result = res; + } else { + if (resOfCompare == 0) { + result.addAll(res); + } //else { + if (resOfCompare == 1) { + writeLog("Geloescht res: " + res); + //result = result; + }}} + else { if (variance == -1) { + writeLog("a_last:" + a_last + " a: " + a); + writeLog("varsLast_a:" + varsLast_a + " vars_a: " + vars_a); + writeLog("compResult:" + compResult + " compRes: " + compRes); + int resOfCompare = oup.compare(compResult, compRes); + if (resOfCompare == 1) { + writeLog("Geloescht result: " + result); + result = res; + } else { + if (resOfCompare == 0) { + result.addAll(res); + } else { + if (resOfCompare == -1) { + writeLog("Geloescht res: " + res); + //result = result; + }}}} + else { if (variance == 0) { + writeLog("RES var=1 ADD:" + result.toString() + " " + res.toString()); + result.addAll(res); + }}} + } + catch (NullPointerException e) { + writeLog("NullPointerException: " + a_last.toString()); + } + } + else { + //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden + writeLog("RES Fst: reuslt: " + result.toString() + " res: " + res.toString()); + result.addAll(res); + } + } + //else { + //wenn Korrekte Ergebnisse da und Feherfälle dazukommen Fehlerfälle ignorieren + // if (isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) { + // result = result; + // } + //} + } + + //} + //else {//duerfte gar nicht mehr vorkommen PL 2018-04-03 + //result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); + //} + if (parallel) { + for (Set> par_res : add_res) { + if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { + //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen + result = par_res; + if (par_res.iterator().next() instanceof WildcardType) { + System.out.println(""); + } + } + else { + if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) + || (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result)) + || result.isEmpty()) { + //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden + writeLog("RES var1 ADD:" + result.toString() + " " + par_res.toString()); + result.addAll(par_res); + } + } + } + //break; + } + + /* auskommentiert um alle Max und min Betrachtung auszuschalten ANFANG */ + if (!result.isEmpty() && (!isUndefinedPairSetSet(res) || !aParDef.isEmpty())) { + if (nextSetasList.iterator().hasNext() && nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("B")).findFirst().isPresent() && nextSetasList.size()>1) + System.out.print(""); + Iterator> nextSetasListIt = new ArrayList>(nextSetasList).iterator(); + if (variance == 1) { + /* vorgezogen vor das if + if (parallel) { + for (Set> par_res : add_res) { + if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { + //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen + result = par_res; + if (par_res.iterator().next() instanceof WildcardType) { + System.out.println(""); + } + } + else { + if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) + || (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result)) + || result.isEmpty()) { + //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden + writeLog("RES var1 ADD:" + result.toString() + " " + par_res.toString()); + result.addAll(par_res); + } + } + } + //break; + */ + + /* nextSetasList = nextSetasListRest; */ + /* wird bereits vor den unify2-Aufruf durchgefuehrt und nextSetasListRest zugeordnet + */ + + System.out.println(""); + writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); + writeLog("aParDef: " + aParDef.toString()); + aParDef.add(a); + Iterator> aParDefIt = aParDef.iterator(); + while(aParDefIt.hasNext()) { + Set a_new = aParDefIt.next(); + while (nextSetasListIt.hasNext()) { + Set a_next = nextSetasListIt.next(); + if (a_new.equals(a_next) || + (oup.compare(a_new, a_next) == 1)) { + writeLog("Removed: " + a_next.toString()); + nextSetasList.remove(a_next); + } + else { + writeLog("Not Removed: " + a_next.toString()); + System.out.println(""); + } + } + } + } + else { if (variance == -1) { + /* vorgezogen vor das if + if (parallel) { + for (Set> par_res : add_res) { + if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { + //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen + result = par_res; + if (par_res.iterator().next() instanceof WildcardType) { + System.out.println(""); + } + } + else { + if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) + || (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result)) + || result.isEmpty()) { + //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden + writeLog("RES var-1 ADD:" + result.toString() + " " + par_res.toString()); + result.addAll(par_res); + } + } + } + //break; + } + + } + */ + + System.out.println(""); + writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); + writeLog("aParDef: " + aParDef.toString()); + aParDef.add(a); + Iterator> aParDefIt = aParDef.iterator(); + while(aParDefIt.hasNext()) { + Set a_new = aParDefIt.next(); + while (nextSetasListIt.hasNext()) { + Set a_next = nextSetasListIt.next(); + if (a_new.equals(a_next) || + (oup.compare(a_new, a_next) == -1)) { + writeLog("Removed: " + a_next.toString()); + nextSetasList.remove(a_next); //PL geaendert 2019-01-09 + } + else { + System.out.println(""); + writeLog("Not Removed: " + a_next.toString()); + } + } + } + } + else { if (variance == 0) { + writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); + break; } + else { if (variance == 2) { + /* vorgezogen vor das if + if (parallel) { + for (Set> par_res : add_res) { + if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { + //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen + result = par_res; + if (par_res.iterator().next() instanceof WildcardType) { + System.out.println(""); + } + } + else { + if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) + || (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result)) + || result.isEmpty()) { + //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden + writeLog("RES var2 ADD:" + result.toString() + " " + par_res.toString()); + result.addAll(par_res); + } + } + } + //break; + } + */ + }}} + writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); + } + } + /* auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */ + + if (isUndefinedPairSetSet(res) && aParDef.isEmpty()) { + int nofstred= 0; + Set abhSubst = res.stream() + .map(b -> + b.stream() + .map(x -> x.getAllSubstitutions()) + .reduce((y,z) -> { y.addAll(z); return y;}).get()) + .reduce((y,z) -> { y.addAll(z); return y;}).get(); + abhSubst.addAll( + res.stream() + .map(b -> + b.stream() + .map(x -> x.getAllBases()) + .reduce((y,z) -> { y.addAll(z); return y;}).get()) + .reduce((y,z) -> { y.addAll(z); return y;}).get() + ); + Set b = a;//effective final a + Set durchschnitt = abhSubst.stream() + .filter(x -> b.contains(x)) + //.filter(y -> abhSubst.contains(y)) + .collect(Collectors.toCollection(HashSet::new)); + //Set vars = durchschnitt.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); + int len = nextSetasList.size(); + Set undefRes = res.stream().reduce((y,z) -> { y.addAll(z); return y;}).get(); //flatten aller undef results + Set, UnifyPair>> reducedUndefResSubstGroundedBasePair = undefRes.stream() + .map(x -> { Set su = x.getAllSubstitutions(); //alle benutzten Substitutionen + su.add(x.getGroundBasePair()); // urspruengliches Paar + su.removeAll(durchschnitt); //alle aktuell genänderten Paare entfernen + return new Pair<>(su, x.getGroundBasePair());}) + .collect(Collectors.toCollection(HashSet::new)); + if (res.size() > 1) { + System.out.println(); + } + nextSetasList = nextSetasList.stream().filter(x -> { + //Boolean ret = false; + //for (PlaceholderType var : vars) { + // ret = ret || x.stream().map(b -> b.getLhsType().equals(var)).reduce((c,d) -> c || d).get(); + //} + return (!x.containsAll(durchschnitt)); + })//.filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y)) //fuer testzwecke auskommentiert um nofstred zu bestimmen PL 2018-10-10 + .collect(Collectors.toCollection(ArrayList::new)); + nofstred = nextSetasList.size(); + //NOCH NICHT korrekt PL 2018-10-12 + //nextSetasList = nextSetasList.stream().filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y)) + // .collect(Collectors.toCollection(ArrayList::new)); + writeLog("res (undef): " + res.toString()); + writeLog("abhSubst: " + abhSubst.toString()); + writeLog("a2: " + rekTiefe + " " + a.toString()); + writeLog("Durchschnitt: " + durchschnitt.toString()); + writeLog("nextSet: " + nextSet.toString()); + writeLog("nextSetasList: " + nextSetasList.toString()); + writeLog("Number first erased Elements (undef): " + (len - nofstred)); + writeLog("Number second erased Elements (undef): " + (nofstred- nextSetasList.size())); + writeLog("Number erased Elements (undef): " + (len - nextSetasList.size())); + noAllErasedElements = noAllErasedElements + (len - nextSetasList.size()); + writeLog("Number of all erased Elements (undef): " + noAllErasedElements.toString()); + noBacktracking++; + writeLog("Number of Backtracking: " + noBacktracking); + System.out.println(""); + } + //if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) { + // return result; + //} + //else { + // result.removeIf(y -> isUndefinedPairSet(y)); + //} + //else result.stream().filter(y -> !isUndefinedPairSet(y)); + writeLog("res: " + res.toString()); + } + + writeLog("Return computeCR: " + result.toString()); + return result; + } + + protected Boolean checkA (UnifyPair aPair, Set sameEqSet, Set> elems, Set> result) { + writeLog("checkA: " + aPair + "sameEqSet: " + sameEqSet); + for (UnifyPair sameEq : sameEqSet) { + if (sameEq.getLhsType() instanceof PlaceholderType) { + Set localEq = new HashSet<>(); + Set unitedSubst = new HashSet<>(aPair.getAllSubstitutions()); + unitedSubst.addAll(aPair.getAllBases()); + unitedSubst.addAll(sameEq.getAllSubstitutions()); + unitedSubst.addAll(sameEq.getAllBases()); + localEq.add(new UnifyPair(aPair.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); + Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); + if (isUndefinedPairSetSet(localRes)) { + if (result.isEmpty() || isUndefinedPairSetSet(result)) { + result.addAll(localRes); + } + //writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet); + return false; + } + } + else { + Set localEq = new HashSet<>(); + Set unitedSubst = new HashSet<>(aPair.getAllSubstitutions()); + unitedSubst.addAll(aPair.getAllBases()); + unitedSubst.addAll(sameEq.getAllSubstitutions()); + unitedSubst.addAll(sameEq.getAllBases()); + localEq.add(new UnifyPair(sameEq.getLhsType(), aPair.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); + Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); + if (isUndefinedPairSetSet(localRes)) { + if (result.isEmpty() || isUndefinedPairSetSet(result)) { + result.addAll(localRes); + } + //writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet); + return false; + } + } + } + //writeLog("TRUE: " + aPair + "sameEqSet: " + sameEqSet); + return true; + } + + protected boolean couldBecorrect(Set, UnifyPair>> reducedUndefResSubstGroundedBasePair, Set nextElem) { + return reducedUndefResSubstGroundedBasePair.stream() + .map(pair -> { + Set reducedAbhSubst = pair.getKey(); + reducedAbhSubst.addAll(nextElem); + Optional> substRes = rules.subst(reducedAbhSubst); + if (!substRes.isPresent()) { + return true; + } + //PL 2018-10-12 + //Evtl. zurest applyTypeUnification aufrufen + //evtl auch unify aufrufen + else { + UnifyPair checkPair = substRes.get().stream() + .filter(x -> x.getGroundBasePair().equals(pair.getValue().get())).findFirst().get(); + if (((checkPair.getLhsType() instanceof PlaceholderType) || (checkPair.getRhsType() instanceof PlaceholderType)) + && (checkPair.getPairOp() == PairOperator.SMALLERDOT || checkPair.getPairOp() == PairOperator.SMALLERDOTWC)) + { + /* + Set setCheckPair = new HashSet<>(); + setCheckPair.add(checkPair); + Set setReturnCheckPair = applyTypeUnificationRules(setCheckPair, fc); + UnifyPair checkPair1 = setReturnCheckPair.iterator().next(); + Set up = new HashSet<>(); + up.add(checkPair1); + Set undef = new HashSet<>(); + */ + PairOperator pairOp = checkPair.getPairOp(); + UnifyType lhsType = checkPair.getLhsType(); + UnifyType rhsType = checkPair.getRhsType(); + ///* Case 1: (a <. Theta') + if ((((pairOp == PairOperator.SMALLERDOT) || (pairOp == PairOperator.SMALLERNEQDOT)) && lhsType instanceof PlaceholderType) + // Case 2: (a <.? ? ext Theta') + || (pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType) + // Case 3: (a <.? ? sup Theta') + || (pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof SuperType) + + // Case 4 was replaced by an inference rule + // Case 4: (a <.? Theta') + || (pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType) + // Case 5: (Theta <. a) + || ((pairOp == PairOperator.SMALLERDOT) && rhsType instanceof PlaceholderType) + // Case 6 was replaced by an inference rule. + // Case 6: (? ext Theta <.? a) + || (pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof ExtendsType && rhsType instanceof PlaceholderType) + // Case 7 was replaced by an inference rule + // Case 7: (? sup Theta <.? a) + || (pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof SuperType && rhsType instanceof PlaceholderType) + // Case 8: (Theta <.? a) + || (pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType) + //reduceWildcardLow + || (pairOp == PairOperator.SMALLERDOTWC && (lhsType instanceof ExtendsType) && (rhsType instanceof ExtendsType)) + //reduceWildcardLowRight + || ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof ReferenceType) && (rhsType instanceof ExtendsType)) + //reduceWildcardUp + || ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof SuperType) && (rhsType instanceof SuperType)) + //reduceWildcardUpRight + || ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof ReferenceType) && (rhsType instanceof SuperType)) + //reduceFunN + || (((pairOp == PairOperator.SMALLERDOT) || (pairOp == PairOperator.EQUALSDOT)) + //PL 2017-10-03 hinzugefuegt + //da Regel auch fuer EQUALSDOT anwendbar + && (lhsType instanceof FunNType) && (rhsType instanceof FunNType)) + //greaterFunN + || ((pairOp== PairOperator.SMALLERDOT) && (lhsType instanceof FunNType) && (rhsType instanceof PlaceholderType)) + //smallerFunN + || ((pairOp == PairOperator.SMALLERDOT) && (lhsType instanceof PlaceholderType && rhsType instanceof FunNType)) + //reduceTph + || ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof PlaceholderType && rhsType instanceof ReferenceType)) + //reduceTphExt + || ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof ExtendsType) && rhsType instanceof PlaceholderType) + //reduceTphSup + || ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof SuperType) && rhsType instanceof PlaceholderType)) { + return true; + } + // Case unknown: If a pair fits no other case, then the type unification has failed. + // Through application of the rules, every pair should have one of the above forms. + // Pairs that do not have one of the aboves form are contradictory. + else { + writeLog("Second erase:" +checkPair.toString()); + return false; + } + //*/ + } else { + //Pair type <. ? extends ? extends type betrachten TODO PL 2018-10-09 + }} + return true;}).reduce((xx, yy) -> xx || yy).get(); + } + + protected boolean isUndefinedPairSet(Set s) { + if (s.size() >= 1 ) { + Boolean ret = s.stream().map(x -> x.isUndefinedPair()).reduce(true, (x,y)-> (x && y)); + return ret; + } + else { + return false; + } + } + + protected boolean isUndefinedPairSetSet(Set> s) { + if (s.size() >= 1) { + Boolean ret = s.stream(). map(x -> isUndefinedPairSet(x)).reduce(true, (x,y)-> (x && y)); + return ret; + } + return false; + + } + /** + * Checks whether a set of pairs is in solved form. + * @param eqPrimePrime The set of pair + * @return True if in solved form, false otherwise. + */ + protected boolean isSolvedForm(Set eqPrimePrime) { + for(UnifyPair pair : eqPrimePrime) { + UnifyType lhsType = pair.getLhsType(); + UnifyType rhsType = pair.getRhsType(); + + if(!(lhsType instanceof PlaceholderType)) + return false; + + // If operator is not equals, both sides must be placeholders + if(pair.getPairOp() != PairOperator.EQUALSDOT && !(rhsType instanceof PlaceholderType)) + return false; + } + return true; + } + + /** + * Repeatedly applies type unification rules to a set of equations. + * This is step one of the unification algorithm. + * @return The set of pairs that results from repeated application of the inference rules. + */ + public Set applyTypeUnificationRules(Set eq, IFiniteClosure fc) { + + /* + * Rule Application Strategy: + * + * 1. Swap all pairs and erase all erasable pairs + * 2. Apply all possible rules to a single pair, then move it to the result set. + * Iterating over pairs first, then iterating over rules prevents the application + * of rules to a "finished" pair over and over. + * 2.1 Apply all rules repeatedly except for erase rules. If + * the application of a rule creates new pairs, check immediately + * against the erase rules. + */ + + + LinkedHashSet targetSet = new LinkedHashSet(); + LinkedList eqQueue = new LinkedList<>(); + + /* + * Swap all pairs and erase all erasable pairs + */ + eq.forEach(x -> swapAddOrErase(x, fc, eqQueue)); + + /* + * Apply rules until the queue is empty + */ + while(!eqQueue.isEmpty()) { + UnifyPair pair = eqQueue.pollFirst(); + + // ReduceUp, ReduceLow, ReduceUpLow + Optional opt = rules.reduceUpLow(pair); + opt = opt.isPresent() ? opt : rules.reduceLow(pair); + opt = opt.isPresent() ? opt : rules.reduceUp(pair); + opt = opt.isPresent() ? opt : rules.reduceWildcardLow(pair); + opt = opt.isPresent() ? opt : rules.reduceWildcardLowRight(pair); + opt = opt.isPresent() ? opt : rules.reduceWildcardUp(pair); + opt = opt.isPresent() ? opt : rules.reduceWildcardUpRight(pair); + //PL 2018-03-06 auskommentiert muesste falsch sein vgl. JAVA_BSP/Wildcard6.java + //opt = opt.isPresent() ? opt : rules.reduceWildcardLowUp(pair); + //opt = opt.isPresent() ? opt : rules.reduceWildcardUpLow(pair); + //opt = opt.isPresent() ? opt : rules.reduceWildcardLeft(pair); + + // Reduce TPH + opt = opt.isPresent() ? opt : rules.reduceTph(pair); + + // One of the rules has been applied + if(opt.isPresent()) { + swapAddOrErase(opt.get(), fc, eqQueue); + continue; + } + + // Reduce1, Reduce2, ReduceExt, ReduceSup, ReduceEq + //try { + // logFile.write("PAIR1 " + pair + "\n"); + // logFile.flush(); + //} + //catch (IOException e) { } + + Optional> optSet = rules.reduce1(pair, fc); + optSet = optSet.isPresent() ? optSet : rules.reduce2(pair); + optSet = optSet.isPresent() ? optSet : rules.reduceExt(pair, fc); + optSet = optSet.isPresent() ? optSet : rules.reduceSup(pair, fc); + optSet = optSet.isPresent() ? optSet : rules.reduceEq(pair); + + // ReduceTphExt, ReduceTphSup + optSet = optSet.isPresent() ? optSet : rules.reduceTphExt(pair); + optSet = optSet.isPresent() ? optSet : rules.reduceTphSup(pair); + + + // FunN Rules + optSet = optSet.isPresent() ? optSet : rules.reduceFunN(pair); + optSet = optSet.isPresent() ? optSet : rules.greaterFunN(pair); + optSet = optSet.isPresent() ? optSet : rules.smallerFunN(pair); + + // One of the rules has been applied + if(optSet.isPresent()) { + optSet.get().forEach(x -> swapAddOrErase(x, fc, eqQueue)); + continue; + } + + // Adapt, AdaptExt, AdaptSup + //try { + // logFile.write("PAIR2 " + pair + "\n"); + // logFile.flush(); + //} + //catch (IOException e) { } + opt = rules.adapt(pair, fc); + opt = opt.isPresent() ? opt : rules.adaptExt(pair, fc); + opt = opt.isPresent() ? opt : rules.adaptSup(pair, fc); + + // One of the rules has been applied + if(opt.isPresent()) { + swapAddOrErase(opt.get(), fc, eqQueue); + continue; + } + + // None of the rules has been applied + targetSet.add(pair); + } + + return targetSet; + } + + /** + * Applies the rule swap to a pair if possible. Then adds the pair to the set if no erase rule applies. + * If an erase rule applies, the pair is not added (erased). + * @param pair The pair to swap and add or erase. + * @param collection The collection to which the pairs are added. + */ + protected void swapAddOrErase(UnifyPair pair, IFiniteClosure fc, Collection collection) { + Optional opt = rules.swap(pair); + UnifyPair pair2 = opt.isPresent() ? opt.get() : pair; + + if(rules.erase1(pair2, fc) || rules.erase3(pair2) || rules.erase2(pair2, fc)) + return; + + collection.add(pair2); + } + + /** + * Splits the equation eq into a set eq1s where both terms are type variables, + * and a set eq2s where one of both terms is not a type variable. + * @param eq Set of pairs to be splitted. + * @param eq1s Subset of eq where both terms are type variables. + * @param eq2s eq/eq1s. + */ + protected void splitEq(Set eq, Set eq1s, Set eq2s) { + for(UnifyPair pair : eq) + if(pair.getLhsType() instanceof PlaceholderType && pair.getRhsType() instanceof PlaceholderType) + eq1s.add(pair); + else + eq2s.add(pair); + } + + /** + * Creates sets of pairs specified in the fourth step. Does not calculate cartesian products. + * @param undefined All pairs that did not match one of the 8 cases are added to this set. + * @return The set of the eight cases (without empty sets). Each case is a set, containing sets generated + * from the pairs that matched the case. Each generated set contains singleton sets or sets with few elements + * (as in case 1 where sigma is added to the innermost set). + */ + protected Set>>> calculatePairSets(Set eq2s, List>> oderConstraintsInput, IFiniteClosure fc, Set undefined, List>> oderConstraintsOutput) { + oderConstraintsOutput.addAll(oderConstraintsInput); + List>>> result = new ArrayList<>(9); + + // Init all 8 cases + 9. Case: oderConstraints + for(int i = 0; i < 9; i++) + result.add(new HashSet<>()); + + ArrayList eq2sprime = new ArrayList<>(eq2s); + Iterator eq2sprimeit = eq2sprime.iterator(); + ArrayList eq2sAsList = new ArrayList<>(); + Boolean first = true; + while(eq2sprimeit.hasNext()) {// alle mit Variance != 0 nach vorne schieben + UnifyPair up = eq2sprimeit.next(); + if ((up.getLhsType() instanceof PlaceholderType && ((PlaceholderType)up.getLhsType()).getVariance() != 0) + || (up.getRhsType() instanceof PlaceholderType && ((PlaceholderType)up.getRhsType()).getVariance() != 0)) { + eq2sAsList.add(up); + eq2s.remove(up); + } + } + if (eq2sAsList.isEmpty()) { + List>> oderConstraintsVariance = oderConstraintsOutput.stream() //Alle Elemente rauswerfen, die Variance 0 haben oder keine TPH in LHS oder RHS sind + .filter(x -> x.stream() + .filter(y -> + y.stream().filter(z -> ((z.getLhsType() instanceof PlaceholderType) + && (((PlaceholderType)(z.getLhsType())).getVariance() != 0)) + || ((z.getRhsType() instanceof PlaceholderType) + && (((PlaceholderType)(z.getRhsType())).getVariance() != 0)) + ).findFirst().isPresent() + ).findFirst().isPresent()).collect(Collectors.toList()); + if (!oderConstraintsVariance.isEmpty()) { + Set> ret = oderConstraintsVariance.get(0); + oderConstraintsOutput.remove(ret); + //Set retFlat = new HashSet<>(); + //ret.stream().forEach(x -> retFlat.addAll(x)); + ret.stream().forEach(x -> x.stream().forEach(y -> y.addSubstitutions(x))); + result.get(8).add(ret); + first = false; + } + } + + eq2sAsList.addAll(eq2s); + + if (eq2sAsList.isEmpty() && first) {//Alle eq2s sind empty und alle oderConstraints mit Variance != 0 sind bearbeitet + if (!oderConstraintsOutput.isEmpty()) { + Set> ret = oderConstraintsOutput.remove(0); + //if (ret.iterator().next().iterator().next().getLhsType().getName().equals("M")) + // System.out.println("M"); + //Set retFlat = new HashSet<>(); + //ret.stream().forEach(x -> retFlat.addAll(x)); + ret.stream().forEach(x -> x.stream().forEach(y -> y.addSubstitutions(x))); + result.get(8).add(ret); + first = false; + } + } + /* + Bei allen die Abhaengigkeit der Elemente aus eq2sAsList als evtl. als Substitution + hinzufuegen + */ + Set consideredElements = new HashSet<>(); + for(UnifyPair pair : eq2sAsList) { + if (consideredElements.contains(pair)) { + continue; + } + PairOperator pairOp = pair.getPairOp(); + UnifyType lhsType = pair.getLhsType(); + UnifyType rhsType = pair.getRhsType(); + + // Case 1: (a <. Theta') + if (((pairOp == PairOperator.SMALLERDOT) || (pairOp == PairOperator.SMALLERNEQDOT)) && lhsType instanceof PlaceholderType) { + //System.out.println(pair); + if (first) { //writeLog(pair.toString()+"\n"); + if (((PlaceholderType)(pair.getLhsType())).getName().equals("AR")) { + System.out.println("AR"); + } + Set> x1 = unifyCase1(pair, fc); + if (pairOp == PairOperator.SMALLERNEQDOT) { + Set remElem = new HashSet<>(); + remElem.add(new UnifyPair(pair.getLhsType(), pair.getRhsType(), PairOperator.EQUALSDOT)); + x1.remove(remElem); + remElem = new HashSet<>(); + remElem.add(new UnifyPair(pair.getLhsType(), new ExtendsType(pair.getRhsType()), PairOperator.EQUALSDOT)); + x1.remove(remElem); + remElem = new HashSet<>(); + remElem.add(new UnifyPair(pair.getLhsType(), new SuperType(pair.getRhsType()), PairOperator.EQUALSDOT)); + x1.remove(remElem); + } + /* ZU LOESCHEN ANFANG + //System.out.println(x1); + Set sameEqSet = eq2sAsList.stream() + .filter(x -> ((x.getLhsType().equals(lhsType) || x.getRhsType().equals(lhsType)) && !x.equals(pair))) + .collect(Collectors.toCollection(HashSet::new)); + consideredElements.addAll(sameEqSet); + Set> x2 = x1; + Set> x1Res = new HashSet<>(); + writeLog("pair:\n" + pair.toString()); + writeLog("x1 Start:\n" + x1.toString()); + writeLog("sameEqSet:\n" + sameEqSet.toString()); + for (UnifyPair sameEq : sameEqSet) { + writeLog("x1 Original:\n" + x1.toString()); + if (sameEq.getLhsType() instanceof PlaceholderType) { + x1 = x1.stream().filter(y -> { + UnifyPair type = y.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); + Set localEq = new HashSet<>(); + Set unitedSubst = new HashSet<>(type.getSubstitution()); + unitedSubst.addAll(sameEq.getSubstitution()); + localEq.add(new UnifyPair(type.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); + Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); + Boolean localCorr = !isUndefinedPairSetSet(localRes); + if (!localCorr) { + collectErr.addAll(localRes); + } + else { + localRes.forEach(z -> z.addAll(y)); + x1Res.addAll(localRes); + } + return localCorr; + } + ).collect(Collectors.toCollection(HashSet::new)); + } + else { + x1 = x1.stream().filter(y -> { + UnifyPair type = y.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); + Set localEq = new HashSet<>(); + Set unitedSubst = new HashSet<>(type.getSubstitution()); + unitedSubst.addAll(sameEq.getSubstitution()); + localEq.add(new UnifyPair(sameEq.getLhsType(), type.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); + Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); + Boolean localCorr = !isUndefinedPairSetSet(localRes); + if (!localCorr) { + collectErr.addAll(localRes); + } + else { + localRes.forEach(z -> z.addAll(y)); + x1Res.addAll(localRes); + } + return localCorr; + } + ).collect(Collectors.toCollection(HashSet::new)); + } + writeLog("x1 nach Loeschung von " + sameEq.toString()+" :\n" + x1.toString()); + } + Set> x1ResPrime; + if (sameEqSet.isEmpty()) { + x1ResPrime = x1; + } + else { + x1ResPrime = x1Res; + } + result.get(0).add(x1ResPrime); + ZU LOESCHEN ENDE */ + result.get(0).add(x1); + if (x1.isEmpty()) { + undefined.add(pair); //Theta ist nicht im FC => Abbruch + } + } + else { + Set s1 = new HashSet<>(); + s1.add(pair); + Set> s2 = new HashSet<>(); + s2.add(s1); + result.get(0).add(s2); + } + + } + // Case 2: (a <.? ? ext Theta') + else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType) + if (first) { //writeLog(pair.toString()+"\n"); + Set> x1 = unifyCase2(pair, fc); + result.get(1).add(x1); + if (x1.isEmpty()) { + undefined.add(pair); //Theta ist nicht im FC + } + } + else { + Set s1 = new HashSet<>(); + s1.add(pair); + Set> s2 = new HashSet<>(); + s2.add(s1); + result.get(1).add(s2); + } + + // Case 3: (a <.? ? sup Theta') + else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof SuperType) + if (first) { //writeLog(pair.toString()+"\n"); + Set> x1 = unifyCase3(pair, fc); + result.get(2).add(x1); + if (x1.isEmpty()) { + undefined.add(pair); //Theta ist nicht im FC + } + } + else { + Set s1 = new HashSet<>(); + s1.add(pair); + Set> s2 = new HashSet<>(); + s2.add(s1); + result.get(2).add(s2); + } + + // Case 4 was replaced by an inference rule + // Case 4: (a <.? Theta') + //else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType) + // result.get(3).add(unifyCase4((PlaceholderType) lhsType, rhsType, fc)); + + // Case 5: (Theta <. a) + else if ((pairOp == PairOperator.SMALLERDOT) && rhsType instanceof PlaceholderType) + if (first) { //writeLog(pair.toString()+"\n"); + Set> x1 = unifyCase5(pair, fc); + result.get(4).add(x1); + if (x1.isEmpty()) { + undefined.add(pair); //Theta ist nicht im FC + } + } + else { + Set s1 = new HashSet<>(); + s1.add(pair); + Set> s2 = new HashSet<>(); + s2.add(s1); + result.get(4).add(s2); + } + + // Case 6 was replaced by an inference rule. + // Case 6: (? ext Theta <.? a) + //else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof ExtendsType && rhsType instanceof PlaceholderType) + // result.get(5).add(unifyCase6((ExtendsType) lhsType, (PlaceholderType) rhsType, fc)); + + // Case 7 was replaced by an inference rule + // Case 7: (? sup Theta <.? a) + //else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof SuperType && rhsType instanceof PlaceholderType) + // result.get(6).add(unifyCase7((SuperType) lhsType, (PlaceholderType) rhsType, fc)); + + // Case 8: (Theta <.? a) + else if(pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType) + if (first) { //writeLog(pair.toString()+"\n"); + Set> x1 = unifyCase8(pair, fc); + result.get(7).add(x1); + if (x1.isEmpty()) { + undefined.add(pair); //Theta ist nicht im FC + } + } + else { + Set s1 = new HashSet<>(); + s1.add(pair); + Set> s2 = new HashSet<>(); + s2.add(s1); + result.get(7).add(s2); + } + // Case unknown: If a pair fits no other case, then the type unification has failed. + // Through application of the rules, every pair should have one of the above forms. + // Pairs that do not have one of the aboves form are contradictory. + else { + // If a pair is not defined, the unificiation will fail, so the loop can be stopped here. + undefined.add(pair); + break; + } + first = false; + } + + // Filter empty sets or sets that only contain an empty set. + return result.stream().map(x -> x.stream().filter(y -> y.size() > 0).collect(Collectors.toCollection(HashSet::new))) + .filter(x -> x.size() > 0).collect(Collectors.toCollection(HashSet::new)); + } + + //TODO: Wenn Theta' nicht im FC muss ein Fehler produziert werden PL 18-04-20 + /** + * Cartesian product Case 1: (a <. Theta') + */ + protected Set> unifyCase1(UnifyPair pair, IFiniteClosure fc) { + PlaceholderType a = (PlaceholderType)pair.getLhsType(); + UnifyType thetaPrime = pair.getRhsType(); + byte variance = pair.getVariance(); + + Set> result = new HashSet<>(); + + boolean allGen = thetaPrime.getTypeParams().size() > 0; + for(UnifyType t : thetaPrime.getTypeParams()) + if(!(t instanceof PlaceholderType) || !((PlaceholderType) t).isGenerated()) { + allGen = false; + break; + } + //if (thetaPrime.getName().equals("java.util.Vector") //Fuer Bug 127 + // && thetaPrime instanceof ReferenceType + // && ((ReferenceType)thetaPrime).getTypeParams().iterator().next() instanceof PlaceholderType) //.getName().equals("java.util.Vector")) + // && ((ReferenceType)((ReferenceType)thetaPrime).getTypeParams().iterator().next()).getTypeParams().iterator().next().getName().equals("java.lang.Integer")) { + // { + // System.out.println(""); + //} + Set cs = fc.getAllTypesByName(thetaPrime.getName());//cs= [java.util.Vector, java.util.Vector>, ????java.util.Vector???] + + + //PL 18-02-06 entfernt, kommt durch unify wieder rein + //cs.add(thetaPrime); + //PL 18-02-06 entfernt + + //cs muessen fresh Typvars gesetzt werden PL 2018-03-18 + Set csPHRenamed = cs.stream().map(x -> { + BinaryOperator> combiner = (aa,b) -> { aa.putAll(b); return aa;}; + HashMap hm = x.getInvolvedPlaceholderTypes().stream() + .reduce(new HashMap(), + (aa, b)-> { aa.put(b,PlaceholderType.freshPlaceholder()); return aa; }, combiner); + return x.accept(new freshPlaceholder(), hm); + }).collect(Collectors.toCollection(HashSet::new)); + + + for(UnifyType c : csPHRenamed) { + //PL 18-02-05 getChildren durch smaller ersetzt in getChildren werden die Varianlen nicht ersetzt. + Set thetaQs = new HashSet<>(); + //TODO smaller wieder reinnehmen? + //thetaQs.add(c);// + thetaQs = fc.smaller(c, new HashSet<>()).stream().collect(Collectors.toCollection(HashSet::new)); + //Set thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new)); + //thetaQs.add(thetaPrime); //PL 18-02-05 wieder geloescht + //PL 2017-10-03: War auskommentiert habe ich wieder einkommentiert, + //da children offensichtlich ein echtes kleiner und kein kleinergleich ist + + //PL 18-02-06: eingefuegt, thetaQs der Form V> <. V'> werden entfernt + //TODO PL 19-01-14 wieder reinnehmen kurzfristig auskommentiert + thetaQs = thetaQs.stream().filter(ut -> ut.getTypeParams().arePlaceholders()).collect(Collectors.toCollection(HashSet::new)); + //PL 18-02-06: eingefuegt + + Set thetaQPrimes = new HashSet<>(); + TypeParams cParams = c.getTypeParams(); + if(cParams.size() == 0) + thetaQPrimes.add(c); + else { + ArrayList> candidateParams = new ArrayList<>(); + + for(UnifyType param : cParams) + candidateParams.add(fc.grArg(param, new HashSet<>())); + + for(TypeParams tp : permuteParams(candidateParams)) + thetaQPrimes.add(c.setTypeParams(tp)); + } + + for(UnifyType tqp : thetaQPrimes) { + Collection tphs = tqp.getInvolvedPlaceholderTypes(); + Optional opt = stdUnify.unify(tqp, thetaPrime); + if (!opt.isPresent()) { + continue; + } + Unifier unifier = opt.get(); + unifier.swapPlaceholderSubstitutions(thetaPrime.getTypeParams()); + Set substitutionSet = new HashSet<>(); + for (Entry sigma : unifier) { + if (!tphs.contains(sigma.getKey())) {//eingefuegt PL 2019-02-02 Bug 127 + substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT, + //TODO: nochmals ueberlegen ob hier pair.getSubstitution() korrekt ist, oder ob leere Menge hin müsste + //alle folgenden New UnifyPair ebenfalls ueberpruefen PL 2018-04-19 + pair.getSubstitution(), pair)); + } + } + //List freshTphs = new ArrayList<>(); PL 18-02-06 in die For-Schleife verschoben + for (UnifyType tq : thetaQs) { + Set smaller = fc.smaller(unifier.apply(tq), new HashSet<>()); + //eingefuegt PL 2018-03-29 Anfang ? ext. theta hinzufuegen + if (a.isWildcardable()) { + Set smaller_ext = smaller.stream().filter(x -> !(x instanceof ExtendsType) && !(x instanceof SuperType)) + .map(x -> { + //BinaryOperator> combiner = (aa,b) -> { aa.putAll(b); return aa;}; //Variablenumbenennung rausgenommen + //HashMap hm = x.getInvolvedPlaceholderTypes().stream() //Variablen muessen wahrscheinlich erhalten bleiben + // .reduce(new HashMap(), + // (aa, b)-> { aa.put(b,PlaceholderType.freshPlaceholder()); return aa; }, combiner); + return new ExtendsType (x);})//.accept(new freshPlaceholder(), hm));} + .collect(Collectors.toCollection(HashSet::new)); + smaller.addAll(smaller_ext); + } + //eingefuegt PL 2018-03-29 Ende ? ext. theta hinzufuegen + for(UnifyType theta : smaller) { + List freshTphs = new ArrayList<>(); + Set resultPrime = new HashSet<>(); + + for(int i = 0; !allGen && i < theta.getTypeParams().size(); i++) { + if(freshTphs.size()-1 < i)//IST DAS RICHTIG??? PL 2018-12-12 + freshTphs.add(PlaceholderType.freshPlaceholder()); + freshTphs.forEach(x -> ((PlaceholderType)x).setInnerType(true)); + resultPrime.add(new UnifyPair(freshTphs.get(i), theta.getTypeParams().get(i), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair)); + } + + if(allGen) { + UnifyPair up = new UnifyPair(a, theta, PairOperator.EQUALSDOT, pair.getSubstitution(), pair); + Iterator upit = up.getRhsType().getTypeParams().iterator(); + //TODO PL 2019-01-24: upit.next() ist nicht unbedingt ein PlaceholderType -> Visitor erledigt + while (upit.hasNext()) upit.next().accept(new distributeVariance(), a.getVariance());//((PlaceholderType)upit.next()).setVariance(a.getVariance()); + resultPrime.add(up); + } + else { + UnifyPair up = new UnifyPair(a, theta.setTypeParams(new TypeParams(freshTphs.toArray(new UnifyType[0]))), PairOperator.EQUALSDOT, pair.getSubstitution(), pair); + Iterator upit = up.getRhsType().getTypeParams().iterator(); + distributeVariance dv = new distributeVariance(); + //TODO PL 2019-01-24: upit.next() ist nicht unbedingt ein PlaceholderType -> Visitor erledigt + while (upit.hasNext()) upit.next().accept(new distributeVariance(), a.getVariance()); //((PlaceholderType)upit.next()).setVariance(a.getVariance()); + resultPrime.add(up); + } + resultPrime.addAll(substitutionSet); + //writeLog("Substitution: " + substitutionSet.toString()); + resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); + result.add(resultPrime); + //writeLog("Result: " + resultPrime.toString()); + //writeLog("MAX: " + oup.max(resultPrime.iterator()).toString()); + } + } + + } + } + + return result; + } + + /** + * Cartesian Product Case 2: (a <.? ? ext Theta') + */ + private Set> unifyCase2(UnifyPair pair, IFiniteClosure fc) { + PlaceholderType a = (PlaceholderType) pair.getLhsType(); + ExtendsType extThetaPrime = (ExtendsType) pair.getRhsType(); + byte variance = pair.getVariance(); + Set> result = new HashSet<>(); + + UnifyType aPrime = PlaceholderType.freshPlaceholder(); + ((PlaceholderType)aPrime).setVariance(((PlaceholderType)a).getVariance()); + ((PlaceholderType)aPrime).disableWildcardtable(); + UnifyType extAPrime = new ExtendsType(aPrime); + UnifyType thetaPrime = extThetaPrime.getExtendedType(); + Set resultPrime = new HashSet<>(); + resultPrime.add(new UnifyPair(a, thetaPrime, PairOperator.SMALLERDOT, pair.getSubstitution(), pair)); + result.add(resultPrime); + + resultPrime = new HashSet<>(); + resultPrime.add(new UnifyPair(a, extAPrime, PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); + resultPrime.add(new UnifyPair(aPrime, thetaPrime, PairOperator.SMALLERDOT, pair.getSubstitution(), pair)); + resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); + result.add(resultPrime); + //writeLog("Result: " + resultPrime.toString()); + return result; + } + + /** + * Cartesian Product Case 3: (a <.? ? sup Theta') + */ + private Set> unifyCase3(UnifyPair pair, IFiniteClosure fc) { + PlaceholderType a = (PlaceholderType) pair.getLhsType(); + a.reversVariance(); + SuperType subThetaPrime = (SuperType) pair.getRhsType(); + byte variance = pair.getVariance(); + Set> result = new HashSet<>(); + + UnifyType aPrime = PlaceholderType.freshPlaceholder(); + ((PlaceholderType)aPrime).setVariance(((PlaceholderType)a).getVariance()); + ((PlaceholderType)aPrime).disableWildcardtable(); + UnifyType supAPrime = new SuperType(aPrime); + UnifyType thetaPrime = subThetaPrime.getSuperedType(); + Set resultPrime = new HashSet<>(); + resultPrime.add(new UnifyPair(thetaPrime, a, PairOperator.SMALLERDOT, pair.getSubstitution(), pair, pair.getfBounded())); + result.add(resultPrime); + //writeLog(resultPrime.toString()); + + resultPrime = new HashSet<>(); + resultPrime.add(new UnifyPair(a, supAPrime, PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); + resultPrime.add(new UnifyPair(thetaPrime, aPrime, PairOperator.SMALLERDOT, pair.getSubstitution(), pair)); + resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); + result.add(resultPrime); + //writeLog(resultPrime.toString()); + + return result; + } + + /** + * Cartesian Product Case 5: (Theta <. a) + */ + private Set> unifyCase5(UnifyPair pair, IFiniteClosure fc) { + UnifyType theta = pair.getLhsType(); + PlaceholderType a = (PlaceholderType) pair.getRhsType(); + byte variance = pair.getVariance(); + Set> result = new HashSet<>(); + + boolean allGen = theta.getTypeParams().size() > 0; + for(UnifyType t : theta.getTypeParams()) + if(!(t instanceof PlaceholderType) || !((PlaceholderType) t).isGenerated()) { + allGen = false; + break; + } + + //eingefuegt PL 2019-01-03 ANFANG + //fc.setLogTrue(); + //writeLog("FBOUNDED: " + pair.getfBounded()); + //writeLog("Pair: " + pair); + Set greater = fc.greater(theta, pair.getfBounded()); + //writeLog("GREATER: " + greater + pair + "THETA: " + theta + "FBOUNDED: " + pair.getfBounded() + " "); + if (a.isWildcardable()) { + Set greater_ext = greater.stream().filter(x -> !(x instanceof ExtendsType) && !(x instanceof SuperType)) + .map(x -> { + //BinaryOperator> combiner = (aa,b) -> { aa.putAll(b); return aa;}; //Variablenumbenennung rausgenommen + //HashMap hm = x.getInvolvedPlaceholderTypes().stream() //Variablen muessen wahrscheinlich erhalten bleiben + // .reduce(new HashMap(), + // (aa, b)-> { aa.put(b,PlaceholderType.freshPlaceholder()); return aa; }, combiner); + return new SuperType (x);})//.accept(new freshPlaceholder(), hm));} + .collect(Collectors.toCollection(HashSet::new)); + greater.addAll(greater_ext); + } + //eingefuegt PL 2019-01-03 ENDE + + //for(UnifyType thetaS : fc.greater(theta, pair.getfBounded())) { + for(UnifyType thetaS : greater) { + Set resultPrime = new HashSet<>(); + Match match = new Match(); + + UnifyType[] freshTphs = new UnifyType[thetaS.getTypeParams().size()]; + for(int i = 0; !allGen && i < freshTphs.length; i++) { + freshTphs[i] = PlaceholderType.freshPlaceholder(); + ((PlaceholderType)freshTphs[i]).setVariance(((PlaceholderType)a).getVariance()); + Set fBounded = new HashSet<>(pair.getfBounded()); //PL 2019-01-09 new HashSet eingefuegt + + int i_ef = i; + BiFunction f = (x,y) -> + { + ArrayList termList = new ArrayList(); + termList.add(new UnifyPair(y,thetaS.getTypeParams().get(i_ef), PairOperator.EQUALSDOT)); + return ((match.match(termList).isPresent()) || x); + }; + //if (parai.getName().equals("java.lang.Integer")) { + // System.out.println(""); + //} + BinaryOperator bo = (x,y) -> (x || y); + if (fBounded.stream().reduce(false,f,bo)) { + resultPrime.add(new UnifyPair(freshTphs[i], thetaS.getTypeParams().get(i), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); + } + else { + fBounded.add(thetaS.getTypeParams().get(i)); + resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair, fBounded)); + } + } + + if(allGen) + resultPrime.add(new UnifyPair(a, thetaS, PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); + else + resultPrime.add(new UnifyPair(a, thetaS.setTypeParams(new TypeParams(freshTphs)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); + resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); + result.add(resultPrime); + //writeLog("FBOUNDED2: " + pair.getfBounded()); + //writeLog("resultPrime Theta < a: " + greater + pair + "THETA: " + theta + "FBOUNDED: " + pair.getfBounded() + " " + resultPrime.toString()); + } + + return result; + } + + /** + * Cartesian Product Case 8: (Theta <.? a) + */ + private Set> unifyCase8(UnifyPair pair, IFiniteClosure fc) { + UnifyType theta = pair.getLhsType(); + PlaceholderType a = (PlaceholderType) pair.getRhsType(); + byte variance = pair.getVariance(); + Set> result = new HashSet<>(); + //for(UnifyType thetaS : fc.grArg(theta)) { + Set resultPrime = new HashSet<>(); + resultPrime.add(new UnifyPair(a, theta, PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); + result.add(resultPrime); + //writeLog(resultPrime.toString()); + + UnifyType freshTph = PlaceholderType.freshPlaceholder(); + + ((PlaceholderType)freshTph).setVariance(a.getVariance()); + ((PlaceholderType)freshTph).disableWildcardtable(); + resultPrime = new HashSet<>(); + resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); + resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair, pair.getfBounded())); + result.add(resultPrime); + //writeLog("resultPrime: " + resultPrime.toString()); + + resultPrime = new HashSet<>(); + resultPrime.add(new UnifyPair(a, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); + resultPrime.add(new UnifyPair(freshTph, theta, PairOperator.SMALLERDOT, pair.getSubstitution(), pair)); + resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); + result.add(resultPrime); + //writeLog(resultPrime.toString()); + //} + + return result; + } + + /** + * Takes a set of candidates for each position and computes all possible permutations. + * @param candidates The length of the list determines the number of type params. Each set + * contains the candidates for the corresponding position. + */ + protected Set permuteParams(ArrayList> candidates) { + Set result = new HashSet<>(); + permuteParams(candidates, 0, result, new UnifyType[candidates.size()]); + return result; + } + + /** + * Takes a set of candidates for each position and computes all possible permutations. + * @param candidates The length of the list determines the number of type params. Each set + * contains the candidates for the corresponding position. + * @param idx Idx for the current permutatiton. + * @param result Set of all permutations found so far + * @param current The permutation of type params that is currently explored + */ + private void permuteParams(ArrayList> candidates, int idx, Set result, UnifyType[] current) { + if(candidates.size() == idx) { + result.add(new TypeParams(Arrays.copyOf(current, current.length))); + return; + } + + Set localCandidates = candidates.get(idx); + + for(UnifyType t : localCandidates) { + current[idx] = t; + permuteParams(candidates, idx+1, result, current); + } + } + + void writeLog(String str) { + synchronized ( this ) { + if (log) { + try { + logFile.write("Thread no.:" + thNo + "\n"); + logFile.write("noOfThread:" + noOfThread + "\n"); + logFile.write("parallel:" + parallel + "\n"); + logFile.write(str+"\n\n"); + logFile.flush(); + + } + catch (IOException e) { + System.err.println("kein LogFile"); + } + } + } + } +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java index 37d70d550..50371d348 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java @@ -1,68 +1,68 @@ -package de.dhbwstuttgart.typeinference.unify.interfaces; - -import java.util.Optional; -import java.util.Set; - -import de.dhbwstuttgart.typeinference.unify.model.ExtendsType; -import de.dhbwstuttgart.typeinference.unify.model.FunNType; -import de.dhbwstuttgart.typeinference.unify.model.PairOperator; -import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; -import de.dhbwstuttgart.typeinference.unify.model.ReferenceType; -import de.dhbwstuttgart.typeinference.unify.model.SuperType; -import de.dhbwstuttgart.typeinference.unify.model.UnifyType; - -/** - * - * @author Florian Steurer - */ -public interface IFiniteClosure { - - public void setLogTrue(); - /** - * Returns all types of the finite closure that are subtypes of the argument. - * @return The set of subtypes of the argument. - */ - public Set smaller(UnifyType type, Set fBounded); - - /** - * Returns all types of the finite closure that are supertypes of the argument. - * @return The set of supertypes of the argument. - */ - public Set greater(UnifyType type, Set fBounded); - - /** - * Wo passt Type rein? - * @param type - * @return - */ - public Set grArg(UnifyType type, Set fBounded); - - /** - * Was passt in Type rein? - * @param type - * @return - */ - public Set smArg(UnifyType type, Set fBounded); - - public Set grArg(ReferenceType type, Set fBounded); - public Set smArg(ReferenceType type, Set fBounded); - - public Set grArg(ExtendsType type, Set fBounded); - public Set smArg(ExtendsType type, Set fBounded); - - public Set grArg(SuperType type, Set fBounded); - public Set smArg(SuperType type, Set fBounded); +package de.dhbwstuttgart.typeinference.unify.interfaces; - public Set grArg(PlaceholderType type, Set fBounded); - public Set smArg(PlaceholderType type, Set fBounded); +import java.util.Optional; +import java.util.Set; + +import de.dhbwstuttgart.typeinference.unify.model.ExtendsType; +import de.dhbwstuttgart.typeinference.unify.model.FunNType; +import de.dhbwstuttgart.typeinference.unify.model.PairOperator; +import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; +import de.dhbwstuttgart.typeinference.unify.model.ReferenceType; +import de.dhbwstuttgart.typeinference.unify.model.SuperType; +import de.dhbwstuttgart.typeinference.unify.model.UnifyType; + +/** + * + * @author Florian Steurer + */ +public interface IFiniteClosure { + + public void setLogTrue(); + /** + * Returns all types of the finite closure that are subtypes of the argument. + * @return The set of subtypes of the argument. + */ + public Set smaller(UnifyType type, Set fBounded); + + /** + * Returns all types of the finite closure that are supertypes of the argument. + * @return The set of supertypes of the argument. + */ + public Set greater(UnifyType type, Set fBounded); + + /** + * Wo passt Type rein? + * @param type + * @return + */ + public Set grArg(UnifyType type, Set fBounded); + + /** + * Was passt in Type rein? + * @param type + * @return + */ + public Set smArg(UnifyType type, Set fBounded); + + public Set grArg(ReferenceType type, Set fBounded); + public Set smArg(ReferenceType type, Set fBounded); + + public Set grArg(ExtendsType type, Set fBounded); + public Set smArg(ExtendsType type, Set fBounded); + + public Set grArg(SuperType type, Set fBounded); + public Set smArg(SuperType type, Set fBounded); + + public Set grArg(PlaceholderType type, Set fBounded); + public Set smArg(PlaceholderType type, Set fBounded); + + public Set grArg(FunNType type, Set fBounded); + public Set smArg(FunNType type, Set fBounded); + + public Optional getLeftHandedType(String typeName); + public Set getAncestors(UnifyType t); + public Set getChildren(UnifyType t); + public Set getAllTypesByName(String typeName); - public Set grArg(FunNType type, Set fBounded); - public Set smArg(FunNType type, Set fBounded); - - public Optional getLeftHandedType(String typeName); - public Set getAncestors(UnifyType t); - public Set getChildren(UnifyType t); - public Set getAllTypesByName(String typeName); - public int compare(UnifyType rhsType, UnifyType rhsType2, PairOperator pairop); -} +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IMatch.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IMatch.java index ab88f33b7..a60de878c 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IMatch.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IMatch.java @@ -1,29 +1,29 @@ -package de.dhbwstuttgart.typeinference.unify.interfaces; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -import de.dhbwstuttgart.typeinference.unify.model.UnifyType; -import de.dhbwstuttgart.typeinference.unify.model.Unifier; -import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; - -/** - * Match - * @author Martin Pluemicke - * abgeleitet aus IUnify.java - */ -public interface IMatch { - - /** - * Finds the most general matcher sigma of the set {t1 =. t1',...,tn =. tn'} so that - * sigma(t1) = t1' , ... sigma(tn) = tn'. - * @param terms The set of terms to be matched - * @return An optional of the most general matcher if it exists or an empty optional if there is no matcher. - */ - public Optional match(ArrayList termsList); - - -} +package de.dhbwstuttgart.typeinference.unify.interfaces; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +import de.dhbwstuttgart.typeinference.unify.model.UnifyType; +import de.dhbwstuttgart.typeinference.unify.model.Unifier; +import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; + +/** + * Match + * @author Martin Pluemicke + * abgeleitet aus IUnify.java + */ +public interface IMatch { + + /** + * Finds the most general matcher sigma of the set {t1 =. t1',...,tn =. tn'} so that + * sigma(t1) = t1' , ... sigma(tn) = tn'. + * @param terms The set of terms to be matched + * @return An optional of the most general matcher if it exists or an empty optional if there is no matcher. + */ + public Optional match(ArrayList termsList); + + +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java index 1ed46cb01..752ff8b28 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java @@ -1,102 +1,102 @@ -package de.dhbwstuttgart.typeinference.unify.interfaces; - -import java.util.List; -import java.util.Optional; -import java.util.Set; - -import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; - -/** - * Contains the inference rules that are applied to the set Eq. - * @author Florian Steurer - */ -public interface IRuleSet { - - public Optional reduceUp(UnifyPair pair); - public Optional reduceLow(UnifyPair pair); - public Optional reduceUpLow(UnifyPair pair); - public Optional> reduceExt(UnifyPair pair, IFiniteClosure fc); - public Optional> reduceSup(UnifyPair pair, IFiniteClosure fc); - public Optional> reduceEq(UnifyPair pair); - public Optional> reduce1(UnifyPair pair, IFiniteClosure fc); - public Optional> reduce2(UnifyPair pair); - - /* - * Missing Reduce-Rules for Wildcards - */ - public Optional reduceWildcardLow(UnifyPair pair); - public Optional reduceWildcardLowRight(UnifyPair pair); - public Optional reduceWildcardUp(UnifyPair pair); - public Optional reduceWildcardUpRight(UnifyPair pair); - - /* - * vgl. JAVA_BSP/Wildcard6.java - public Optional reduceWildcardLowUp(UnifyPair pair); - public Optional reduceWildcardUpLow(UnifyPair pair); - public Optional reduceWildcardLeft(UnifyPair pair); - */ - - /* - * Additional Rules which replace cases of the cartesian product - */ - - /** - * Rule that replaces the fourth case of the cartesian product where (a <.? Theta) - */ - public Optional reduceTph(UnifyPair pair); - - /** - * Rule that replaces the sixth case of the cartesian product where (? ext Theta <.? a) - */ - public Optional> reduceTphExt(UnifyPair pair); - - /** - * Rule that replaces the fourth case of the cartesian product where (? sup Theta <.? a) - */ - public Optional> reduceTphSup(UnifyPair pair); - - /* - * FunN Rules - */ - public Optional> reduceFunN(UnifyPair pair); - public Optional> greaterFunN(UnifyPair pair); - public Optional> smallerFunN(UnifyPair pair); - - /** - * Checks whether the erase1-Rule applies to the pair. - * @return True if the pair is erasable, false otherwise. - */ - public boolean erase1(UnifyPair pair, IFiniteClosure fc); - - /** - * Checks whether the erase2-Rule applies to the pair. - * @return True if the pair is erasable, false otherwise. - */ - public boolean erase2(UnifyPair pair, IFiniteClosure fc); - - /** - * Checks whether the erase3-Rule applies to the pair. - * @return True if the pair is erasable, false otherwise. - */ - public boolean erase3(UnifyPair pair); - - public Optional swap(UnifyPair pair); - - public Optional adapt(UnifyPair pair, IFiniteClosure fc); - public Optional adaptExt(UnifyPair pair, IFiniteClosure fc); - public Optional adaptSup(UnifyPair pair, IFiniteClosure fc); - - /** - * Applies the subst-Rule to a set of pairs (usually Eq'). - * @param pairs The set of pairs where the subst rule should apply. - * @return An optional of the modified set, if there were any substitutions. An empty optional if there were no substitutions. - */ - public Optional> subst(Set pairs, List>> oderConstraints); - - /** - * Applies the subst-Rule to a set of pairs (usually Eq'). - * @param pairs The set of pairs where the subst rule should apply. - * @return An optional of the modified set, if there were any substitutions. An empty optional if there were no substitutions. - */ - public Optional> subst(Set pairs); -} +package de.dhbwstuttgart.typeinference.unify.interfaces; + +import java.util.List; +import java.util.Optional; +import java.util.Set; + +import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; + +/** + * Contains the inference rules that are applied to the set Eq. + * @author Florian Steurer + */ +public interface IRuleSet { + + public Optional reduceUp(UnifyPair pair); + public Optional reduceLow(UnifyPair pair); + public Optional reduceUpLow(UnifyPair pair); + public Optional> reduceExt(UnifyPair pair, IFiniteClosure fc); + public Optional> reduceSup(UnifyPair pair, IFiniteClosure fc); + public Optional> reduceEq(UnifyPair pair); + public Optional> reduce1(UnifyPair pair, IFiniteClosure fc); + public Optional> reduce2(UnifyPair pair); + + /* + * Missing Reduce-Rules for Wildcards + */ + public Optional reduceWildcardLow(UnifyPair pair); + public Optional reduceWildcardLowRight(UnifyPair pair); + public Optional reduceWildcardUp(UnifyPair pair); + public Optional reduceWildcardUpRight(UnifyPair pair); + + /* + * vgl. JAVA_BSP/Wildcard6.java + public Optional reduceWildcardLowUp(UnifyPair pair); + public Optional reduceWildcardUpLow(UnifyPair pair); + public Optional reduceWildcardLeft(UnifyPair pair); + */ + + /* + * Additional Rules which replace cases of the cartesian product + */ + + /** + * Rule that replaces the fourth case of the cartesian product where (a <.? Theta) + */ + public Optional reduceTph(UnifyPair pair); + + /** + * Rule that replaces the sixth case of the cartesian product where (? ext Theta <.? a) + */ + public Optional> reduceTphExt(UnifyPair pair); + + /** + * Rule that replaces the fourth case of the cartesian product where (? sup Theta <.? a) + */ + public Optional> reduceTphSup(UnifyPair pair); + + /* + * FunN Rules + */ + public Optional> reduceFunN(UnifyPair pair); + public Optional> greaterFunN(UnifyPair pair); + public Optional> smallerFunN(UnifyPair pair); + + /** + * Checks whether the erase1-Rule applies to the pair. + * @return True if the pair is erasable, false otherwise. + */ + public boolean erase1(UnifyPair pair, IFiniteClosure fc); + + /** + * Checks whether the erase2-Rule applies to the pair. + * @return True if the pair is erasable, false otherwise. + */ + public boolean erase2(UnifyPair pair, IFiniteClosure fc); + + /** + * Checks whether the erase3-Rule applies to the pair. + * @return True if the pair is erasable, false otherwise. + */ + public boolean erase3(UnifyPair pair); + + public Optional swap(UnifyPair pair); + + public Optional adapt(UnifyPair pair, IFiniteClosure fc); + public Optional adaptExt(UnifyPair pair, IFiniteClosure fc); + public Optional adaptSup(UnifyPair pair, IFiniteClosure fc); + + /** + * Applies the subst-Rule to a set of pairs (usually Eq'). + * @param pairs The set of pairs where the subst rule should apply. + * @return An optional of the modified set, if there were any substitutions. An empty optional if there were no substitutions. + */ + public Optional> subst(Set pairs, List>> oderConstraints); + + /** + * Applies the subst-Rule to a set of pairs (usually Eq'). + * @param pairs The set of pairs where the subst rule should apply. + * @return An optional of the modified set, if there were any substitutions. An empty optional if there were no substitutions. + */ + public Optional> subst(Set pairs); +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/ISetOperations.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/ISetOperations.java index 4a98aaba3..cf0def376 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/ISetOperations.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/ISetOperations.java @@ -1,16 +1,16 @@ -package de.dhbwstuttgart.typeinference.unify.interfaces; - -import java.util.List; -import java.util.Set; - -/** - * Contains operations on sets. - * @author Florian Steurer - */ -public interface ISetOperations { - /** - * Calculates the cartesian product of the sets. - * @return The cartesian product - */ - Set> cartesianProduct(List> sets); -} +package de.dhbwstuttgart.typeinference.unify.interfaces; + +import java.util.List; +import java.util.Set; + +/** + * Contains operations on sets. + * @author Florian Steurer + */ +public interface ISetOperations { + /** + * Calculates the cartesian product of the sets. + * @return The cartesian product + */ + Set> cartesianProduct(List> sets); +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IUnify.java index 57b417362..5647e1892 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IUnify.java @@ -1,35 +1,35 @@ -package de.dhbwstuttgart.typeinference.unify.interfaces; - -import java.util.Arrays; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -import de.dhbwstuttgart.typeinference.unify.model.UnifyType; -import de.dhbwstuttgart.typeinference.unify.model.Unifier; - -/** - * Standard unification algorithm (e.g. Robinson, Paterson-Wegman, Martelli-Montanari) - * @author Florian Steurer - */ -public interface IUnify { - - /** - * Finds the most general unifier sigma of the set {t1 =. t1',...,tn =. tn'} so that - * sigma(t1) = sigma(t1') , ... sigma(tn) = sigma(tn'). - * @param terms The set of terms to be unified - * @return An optional of the most general unifier if it exists or an empty optional if there is no unifier. - */ - public Optional unify(Set terms); - - /** - * Finds the most general unifier sigma of the set {t1 =. t1',...,tn =. tn'} so that - * sigma(t1) = sigma(t1') , ... sigma(tn) = sigma(tn'). - * @param terms The set of terms to be unified - * @return An optional of the most general unifier if it exists or an empty optional if there is no unifier. - */ - default public Optional unify(UnifyType... terms) { - return unify(Arrays.stream(terms).collect(Collectors.toSet())); - } - -} +package de.dhbwstuttgart.typeinference.unify.interfaces; + +import java.util.Arrays; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +import de.dhbwstuttgart.typeinference.unify.model.UnifyType; +import de.dhbwstuttgart.typeinference.unify.model.Unifier; + +/** + * Standard unification algorithm (e.g. Robinson, Paterson-Wegman, Martelli-Montanari) + * @author Florian Steurer + */ +public interface IUnify { + + /** + * Finds the most general unifier sigma of the set {t1 =. t1',...,tn =. tn'} so that + * sigma(t1) = sigma(t1') , ... sigma(tn) = sigma(tn'). + * @param terms The set of terms to be unified + * @return An optional of the most general unifier if it exists or an empty optional if there is no unifier. + */ + public Optional unify(Set terms); + + /** + * Finds the most general unifier sigma of the set {t1 =. t1',...,tn =. tn'} so that + * sigma(t1) = sigma(t1') , ... sigma(tn) = sigma(tn'). + * @param terms The set of terms to be unified + * @return An optional of the most general unifier if it exists or an empty optional if there is no unifier. + */ + default public Optional unify(UnifyType... terms) { + return unify(Arrays.stream(terms).collect(Collectors.toSet())); + } + +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java index e9b805c1c..ef7e950e8 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java @@ -1,96 +1,96 @@ -package de.dhbwstuttgart.typeinference.unify.model; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Set; - -import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; -import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; - -/** - * An extends wildcard type "? extends T". - */ -public final class ExtendsType extends WildcardType { - - public UnifyType accept(UnifyTypeVisitor visitor, T ht) { - return visitor.visit(this, ht); - } - - /** - * Creates a new extends wildcard type. - * @param extendedType The extended type e.g. Integer in "? extends Integer" - */ - public ExtendsType(UnifyType extendedType) { - super("? extends " + extendedType.getName(), extendedType); - if (extendedType instanceof ExtendsType) { - System.out.print(""); - } - } - - /** - * The extended type e.g. Integer in "? extends Integer" - */ - public UnifyType getExtendedType() { - return wildcardedType; - } - - /** - * Sets the type parameters of the wildcarded type and returns a new extendstype that extends that type. - */ - @Override - public UnifyType setTypeParams(TypeParams newTp) { - UnifyType newType = wildcardedType.setTypeParams(newTp); - if(newType == wildcardedType) - return this; // Reduced the amount of objects created - return new ExtendsType(wildcardedType.setTypeParams(newTp)); - } - - @Override - Set smArg(IFiniteClosure fc, Set fBounded) { - return fc.smArg(this, fBounded); - } - - @Override - Set grArg(IFiniteClosure fc, Set fBounded) { - return fc.grArg(this, fBounded); - } - - @Override - UnifyType apply(Unifier unif) { - UnifyType newType = wildcardedType.apply(unif); - if(newType.hashCode() == wildcardedType.hashCode() && newType.equals(wildcardedType)) - return this; // Reduced the amount of objects created - return new ExtendsType(newType); - } - - @Override - public int hashCode() { - /* - * It is important that the prime that is added is different to the prime added in hashCode() of SuperType. - * Otherwise ? extends T and ? super T have the same hashCode() for every Type T. - */ - return wildcardedType.hashCode() + 229; - } - - @Override - public boolean equals(Object obj) { - if(!(obj instanceof ExtendsType)) - return false; - - if(obj.hashCode() != this.hashCode()) - return false; - - ExtendsType other = (ExtendsType) obj; - - - return other.getWildcardedType().equals(wildcardedType); - } - - @Override - public String toString() { - return "? extends " + wildcardedType; - } - - -} +package de.dhbwstuttgart.typeinference.unify.model; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Set; + +import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; + +/** + * An extends wildcard type "? extends T". + */ +public final class ExtendsType extends WildcardType { + + public UnifyType accept(UnifyTypeVisitor visitor, T ht) { + return visitor.visit(this, ht); + } + + /** + * Creates a new extends wildcard type. + * @param extendedType The extended type e.g. Integer in "? extends Integer" + */ + public ExtendsType(UnifyType extendedType) { + super("? extends " + extendedType.getName(), extendedType); + if (extendedType instanceof ExtendsType) { + System.out.print(""); + } + } + + /** + * The extended type e.g. Integer in "? extends Integer" + */ + public UnifyType getExtendedType() { + return wildcardedType; + } + + /** + * Sets the type parameters of the wildcarded type and returns a new extendstype that extends that type. + */ + @Override + public UnifyType setTypeParams(TypeParams newTp) { + UnifyType newType = wildcardedType.setTypeParams(newTp); + if(newType == wildcardedType) + return this; // Reduced the amount of objects created + return new ExtendsType(wildcardedType.setTypeParams(newTp)); + } + + @Override + Set smArg(IFiniteClosure fc, Set fBounded) { + return fc.smArg(this, fBounded); + } + + @Override + Set grArg(IFiniteClosure fc, Set fBounded) { + return fc.grArg(this, fBounded); + } + + @Override + UnifyType apply(Unifier unif) { + UnifyType newType = wildcardedType.apply(unif); + if(newType.hashCode() == wildcardedType.hashCode() && newType.equals(wildcardedType)) + return this; // Reduced the amount of objects created + return new ExtendsType(newType); + } + + @Override + public int hashCode() { + /* + * It is important that the prime that is added is different to the prime added in hashCode() of SuperType. + * Otherwise ? extends T and ? super T have the same hashCode() for every Type T. + */ + return wildcardedType.hashCode() + 229; + } + + @Override + public boolean equals(Object obj) { + if(!(obj instanceof ExtendsType)) + return false; + + if(obj.hashCode() != this.hashCode()) + return false; + + ExtendsType other = (ExtendsType) obj; + + + return other.getWildcardedType().equals(wildcardedType); + } + + @Override + public String toString() { + return "? extends " + wildcardedType; + } + + +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index 6ce7b541c..95c903773 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -1,748 +1,748 @@ -package de.dhbwstuttgart.typeinference.unify.model; - -import java.io.FileWriter; -import java.io.IOException; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.function.BiFunction; -import java.util.function.BinaryOperator; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -import com.google.common.collect.Ordering; - -//PL 18-02-05/18-04-05 Unifier durch Matcher ersetzt -//muss greater noch ersetzt werden ja erledigt 18--04-05 -import de.dhbwstuttgart.typeinference.unify.MartelliMontanariUnify; - -import de.dhbwstuttgart.typeinference.unify.Match; -import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask; -import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; -import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify; - -/** - * The finite closure for the type unification - * @author Florian Steurer - */ -public class FiniteClosure //extends Ordering //entfernt PL 2018-12-11 -implements IFiniteClosure { - - Writer logFile; - static Boolean log = false; - public void setLogTrue() { - log = true; - } - /** - * A map that maps every type to the node in the inheritance graph that contains that type. - */ - private HashMap> inheritanceGraph; - - /** - * A map that maps every typename to the nodes of the inheritance graph that contain a type with that name. - */ - private HashMap>> strInheritanceGraph; - - - /** - * The initial pairs of that define the inheritance tree - */ - private Set pairs; - - /** - * Hastable fuer die greater-Werte, damit sie nicht doppelt berechnet werden muessen - */ - Hashtable> greaterHash = new Hashtable<>(); - - /** - * Hastable fuer die smaller-Werte, damit sie nicht doppelt berechnet werden muessen - */ - Hashtable> smallerHash = new Hashtable<>(); - - /** - * Creates a new instance using the inheritance tree defined in the pairs. - */ - public FiniteClosure(Set pairs, Writer logFile) { - this.logFile = logFile; - this.pairs = new HashSet<>(pairs); - inheritanceGraph = new HashMap>(); - - // Build the transitive closure of the inheritance tree - for(UnifyPair pair : pairs) { - if(pair.getPairOp() != PairOperator.SMALLER) - continue; - - //VERSUCH PL 18-02-06 - //koennte ggf. die FC reduzieren - //TO DO: Ueberpruefen, ob das sinnvll und korrekt ist - //if (!pair.getLhsType().getTypeParams().arePlaceholders() - // && !pair.getRhsType().getTypeParams().arePlaceholders()) - // continue; -; - // Add nodes if not already in the graph - if(!inheritanceGraph.containsKey(pair.getLhsType())) - inheritanceGraph.put(pair.getLhsType(), new Node(pair.getLhsType())); - if(!inheritanceGraph.containsKey(pair.getRhsType())) - inheritanceGraph.put(pair.getRhsType(), new Node(pair.getRhsType())); - - Node childNode = inheritanceGraph.get(pair.getLhsType()); - Node parentNode = inheritanceGraph.get(pair.getRhsType()); - - // Add edge - parentNode.addDescendant(childNode); - - // Add edges to build the transitive closure - parentNode.getPredecessors().stream().forEach(x -> x.addDescendant(childNode)); - childNode.getDescendants().stream().forEach(x -> x.addPredecessor(parentNode)); - } - - // Build the alternative representation with strings as keys - strInheritanceGraph = new HashMap<>(); - for(UnifyType key : inheritanceGraph.keySet()) { - if(!strInheritanceGraph.containsKey(key.getName())) - strInheritanceGraph.put(key.getName(), new HashSet<>()); - - strInheritanceGraph.get(key.getName()).add(inheritanceGraph.get(key)); - } - } - - void testSmaller() { - UnifyType tq1, tq2, tq3; - tq1 = new ExtendsType(PlaceholderType.freshPlaceholder()); - List l1 = new ArrayList<>(); - List l2 = new ArrayList<>(); - l1.add(tq1); - tq2 = new ReferenceType("java.util.Vector", new TypeParams(l1)); - l2.add(tq2); - tq3 = new ReferenceType("java.util.Vector", new TypeParams(l2)); - Set smaller = smaller(tq3, new HashSet<>()); - } - - /** - * Returns all types of the finite closure that are subtypes of the argument. - * @return The set of subtypes of the argument. - */ - @Override - public Set smaller(UnifyType type, Set fBounded) { - - Set ret; - if ((ret = smallerHash.get(new hashKeyType(type))) != null) { - //System.out.println(greaterHash); - return new HashSet<>(ret); - } - - if(type instanceof FunNType) - return computeSmallerFunN((FunNType) type, fBounded); - - Set>> ts = new HashSet<>(); - ts.add(new Pair<>(type, fBounded)); - Set result = computeSmaller(ts); - smallerHash.put(new hashKeyType(type), result); - /* - try { - logFile.write("\ntype: " + type + "\nret: " + ret + "\nresult: " + result);//"smallerHash: " + greaterHash.toString()); - logFile.flush(); - } - catch (IOException e) { - System.err.println("no LogFile"); - }*/ - return result; - } - - /** - * Computes the smaller functions for every type except FunNTypes. - */ - private Set computeSmaller(Set>> types) { - Set>> result = new HashSet<>(); - - //PL 18-02-05 Unifier durch Matcher ersetzt - //IUnify unify = new MartelliMontanariUnify(); - Match match = new Match(); - - for(Pair> pt : types) { - UnifyType t = pt.getKey(); - Set fBounded = pt.getValue().get(); - - // if T = T' then T <* T' - try { - result.add(new Pair<>(t, fBounded)); - } - catch (StackOverflowError e) { - System.out.println(""); - } - - // if C<...> <* C<...> then ... (third case in definition of <*) - if(t.getTypeParams().size() > 0) { - ArrayList> paramCandidates = new ArrayList<>(); - for (int i = 0; i < t.getTypeParams().size(); i++) - paramCandidates.add(smArg(t.getTypeParams().get(i), fBounded)); - permuteParams(paramCandidates).forEach(x -> result.add(new Pair<>(t.setTypeParams(x), fBounded))); - } - - if(!strInheritanceGraph.containsKey(t.getName())) - continue; - - // if T <* T' then sigma(T) <* sigma(T') - Set> candidates = strInheritanceGraph.get(t.getName()); //cadidates= [???Node(java.util.Vector>)??? - // , Node(java.util.Vector) - //] - for(Node candidate : candidates) { - UnifyType theta2 = candidate.getContent(); - //PL 18-02-05 Unifier durch Matcher ersetzt ANFANG - ArrayList termList= new ArrayList(); - termList.add(new UnifyPair(theta2,t, PairOperator.EQUALSDOT)); - Optional optSigma = match.match(termList); - //PL 18-02-05 Unifier durch Matcher ersetzt ENDE - if(!optSigma.isPresent()) - continue; - - Unifier sigma = optSigma.get(); - sigma.swapPlaceholderSubstitutions(t.getTypeParams()); - - Set theta1Set = candidate.getContentOfDescendants(); - - for(UnifyType theta1 : theta1Set) - result.add(new Pair<>(theta1.apply(sigma), fBounded)); - } - } - - HashSet resut = result.stream().map(x -> x.getKey()).collect(Collectors.toCollection(HashSet::new)); - if(resut.equals(types.stream().map(x -> x.getKey()).collect(Collectors.toCollection(HashSet::new)))) - return resut; - return computeSmaller(result); - } - - /** - * Computes the smaller-Function for FunNTypes. - */ - private Set computeSmallerFunN(FunNType type, Set fBounded) { - Set result = new HashSet<>(); - - // if T = T' then T <=* T' - result.add(type); - - // Because real function types are implicitly variant - // it is enough to permute the params with the values of greater / smaller. - ArrayList> paramCandidates = new ArrayList<>(); - paramCandidates.add(smaller(type.getTypeParams().get(0), fBounded)); - for (int i = 1; i < type.getTypeParams().size(); i++) - paramCandidates.add(greater(type.getTypeParams().get(i), new HashSet<>())); - - permuteParams(paramCandidates).forEach(x -> result.add(type.setTypeParams(x))); - return result; - } - - /** - * Returns all types of the finite closure that are supertypes of the argument. - * @return The set of supertypes of the argument. - */ - @Override - //Eingefuegt PL 2018-05-24 F-Bounded Problematik - public Set greater(UnifyType type, Set fBounded) { - - Set ret; - if ((ret = greaterHash.get(new hashKeyType(type))) != null) { - //System.out.println(greaterHash); - return new HashSet<>(ret); - } - - - if(type instanceof FunNType) { - return computeGreaterFunN((FunNType) type, fBounded); - } - - Set result = new HashSet<>(); - Set>> PairResultFBounded = new HashSet<>(); - - Match match = new Match(); - - - // if T = T' then T <=* T' - result.add(type); - if(!strInheritanceGraph.containsKey(type.getName())) - return result; - - // if T <* T' then sigma(T) <* sigma(T') - Set> candidates = strInheritanceGraph.get(type.getName()); - - /* - try { - if (log) logFile.write(candidates.toString()); - //log = false; - } - catch (IOException e) { - System.err.println("no LogFile"); - } - */ - - for(Node candidate : candidates) { - UnifyType theta1 = candidate.getContent(); - - //PL 18-04-05 Unifier durch Matcher ersetzt ANFANG - ArrayList termList= new ArrayList(); - termList.add(new UnifyPair(theta1,type, PairOperator.EQUALSDOT)); - Optional optSigma = match.match(termList); - //PL 18-04-05 Unifier durch Matcher ersetzt ENDE - if(!optSigma.isPresent()) { - continue; - } - Unifier sigma = optSigma.get(); - sigma.swapPlaceholderSubstitutionsReverse(theta1.getTypeParams()); - - Set fBoundedNew = new HashSet<>(fBounded); - fBoundedNew.add(theta1); - Set theta2Set = candidate.getContentOfPredecessors(); - //System.out.println(""); - for(UnifyType theta2 : theta2Set) { - result.add(theta2.apply(sigma)); - PairResultFBounded.add(new Pair<>(theta2.apply(sigma), fBoundedNew)); - } - } - /* - try { - if (log) logFile.write(PairResultFBounded.toString()); - log = false; - } - catch (IOException e) { - System.err.println("no LogFile"); - } - */ - for(Pair> pt : PairResultFBounded) { - UnifyType t = pt.getKey(); - Set lfBounded = pt.getValue().get(); - - // if C<...> <* C<...> then ... (third case in definition of <*) - //TypeParams typeparams = t.getTypeParams(); - if(t.getTypeParams().size() > 0) { - ArrayList> paramCandidates = new ArrayList<>(); - - for (int i = 0; i < t.getTypeParams().size(); i++) { - //UnifyType parai = t.getTypeParams().get(i); - int i_ef = i; - BiFunction f = (x,y) -> - { - ArrayList termList = new ArrayList(); - termList.add(new UnifyPair(y,t.getTypeParams().get(i_ef), PairOperator.EQUALSDOT)); - return ((match.match(termList).isPresent()) || x); - }; - //if (parai.getName().equals("java.lang.Integer")) { - // System.out.println(""); - //} - BinaryOperator bo = (a,b) -> (a || b); - if (lfBounded.stream().reduce(false,f,bo)) { - //F-Bounded Endlosrekursion - HashSet res = new HashSet(); - paramCandidates.add(res); - } - else { - paramCandidates.add(grArg(t.getTypeParams().get(i), new HashSet<>(fBounded) )); - } - } - permuteParams(paramCandidates).forEach(x -> result.add(t.setTypeParams(x))); - //System.out.println(""); - } - } - - greaterHash.put(new hashKeyType(type), result); - /* - try { - logFile.write("\ntype: " + type + "\nret: " + ret + "\nresult: " + result);//"greaterHash: " + greaterHash.toString()); - logFile.flush(); - } - catch (IOException e) { - System.err.println("no LogFile"); - }*/ - return result; - } - - /* auskommentiert PL 2018-05-24 - /** - * Returns all types of the finite closure that are supertypes of the argument. - * @return The set of supertypes of the argument. - * - //@Override - public Set oldgreater(UnifyType type, Set fBounded) { - if(type instanceof FunNType) - return computeGreaterFunN((FunNType) type, fBounded); - - Set>> ts = new HashSet<>(); - ts.add(new Pair<>(type, fBounded)); - return computeGreater(ts); - } - - /** - * Computes the greater function for all types except function types. - * - protected Set computeGreater(Set>> types) { - Set>> result = new HashSet<>(); - - //PL 18-04-05 Unifier durch Matcher ersetzt - //IUnify unify = new MartelliMontanariUnify(); - Match match = new Match(); - - for(Pair> pt : types) { - UnifyType t = pt.getKey(); - Set fBounded = pt.getValue().get(); - // if T = T' then T <=* T' - result.add(pt); - - // if C<...> <* C<...> then ... (third case in definition of <*) - if(t.getTypeParams().size() > 0) { - ArrayList> paramCandidates = new ArrayList<>(); - for (int i = 0; i < t.getTypeParams().size(); i++) { - UnifyType parai = t.getTypeParams().get(i); - int i_ef = i; - BiFunction f = (x,y) -> - { - ArrayList termList = new ArrayList(); - termList.add(new UnifyPair(y,t.getTypeParams().get(i_ef), PairOperator.EQUALSDOT)); - return ((match.match(termList).isPresent()) || x); - }; - if (parai.getName().equals("java.lang.Integer")) { - System.out.println(""); - } - BinaryOperator bo = (a,b) -> (a || b); - if (fBounded.stream().reduce(false,f,bo)) continue; //F-Bounded Endlosrekursion - paramCandidates.add(grArg(t.getTypeParams().get(i), new HashSet<>(fBounded) )); - } - permuteParams(paramCandidates).forEach(x -> result.add(new Pair<>(t.setTypeParams(x), new HashSet<>(fBounded)))); - } - - if(!strInheritanceGraph.containsKey(t.getName())) - continue; - - // if T <* T' then sigma(T) <* sigma(T') - Set> candidates = strInheritanceGraph.get(t.getName()); - for(Node candidate : candidates) { - UnifyType theta1 = candidate.getContent(); - - //PL 18-04-05 Unifier durch Matcher ersetzt ANFANG - ArrayList termList= new ArrayList(); - termList.add(new UnifyPair(theta1,t, PairOperator.EQUALSDOT)); - Optional optSigma = match.match(termList); - //PL 18-04-05 Unifier durch Matcher ersetzt ENDE - if(!optSigma.isPresent()) - continue; - - Unifier sigma = optSigma.get(); - sigma.swapPlaceholderSubstitutionsReverse(theta1.getTypeParams()); - - Set fBoundedNew = new HashSet<>(fBounded); - fBoundedNew.add(theta1); - Set theta2Set = candidate.getContentOfPredecessors(); - - for(UnifyType theta2 : theta2Set) - result.add(new Pair<>(theta2.apply(sigma), fBoundedNew)); - } - - } - - HashSet resut = result.stream().map(x -> x.getKey()).collect(Collectors.toCollection(HashSet::new)); - System.out.println(resut); - if(resut.equals(types.stream().map(x -> x.getKey()).collect(Collectors.toCollection(HashSet::new)))) - return resut; - return computeGreater(result); - } - */ - - /** - * Computes the greater function for FunN-Types - */ - protected Set computeGreaterFunN(FunNType type, Set fBounded) { - Set result = new HashSet<>(); - - // if T = T' then T <=* T' - result.add(type); - - // Because real function types are implicitly variant - // it is enough to permute the params with the values of greater / smaller. - ArrayList> paramCandidates = new ArrayList<>(); - paramCandidates.add(greater(type.getTypeParams().get(0), new HashSet<>())); - for (int i = 1; i < type.getTypeParams().size(); i++) - paramCandidates.add(smaller(type.getTypeParams().get(i), fBounded)); - permuteParams(paramCandidates).forEach(x -> result.add(type.setTypeParams(x))); - return result; - } - - - @Override - public Set grArg(UnifyType type, Set fBounded) { - return type.grArg(this, fBounded); - } - - @Override - public Set grArg(ReferenceType type, Set fBounded) { - Set result = new HashSet(); - result.add(type); - smaller(type, fBounded).forEach(x -> result.add(new SuperType(x))); - greater(type,fBounded).forEach(x -> result.add(new ExtendsType(x))); - return result; - } - - @Override - public Set grArg(FunNType type, Set fBounded) { - Set result = new HashSet(); - result.add(type); - smaller(type, fBounded).forEach(x -> result.add(new SuperType(x))); - greater(type, fBounded).forEach(x -> result.add(new ExtendsType(x))); - return result; - } - - @Override - public Set grArg(ExtendsType type, Set fBounded) { - Set result = new HashSet(); - result.add(type); - UnifyType t = type.getExtendedType(); - greater(t, fBounded).forEach(x -> result.add(new ExtendsType(x))); - return result; - } - - @Override - public Set grArg(SuperType type, Set fBounded) { - Set result = new HashSet(); - result.add(type); - UnifyType t = type.getSuperedType(); - smaller(t, fBounded).forEach(x -> result.add(new SuperType(x))); - return result; - } - - @Override - public Set grArg(PlaceholderType type, Set fBounded) { - HashSet result = new HashSet<>(); - result.add(type); - return result; - } - - @Override - public Set smArg(UnifyType type, Set fBounded) { - return type.smArg(this, fBounded); - } - - @Override - public Set smArg(ReferenceType type, Set fBounded) { - Set result = new HashSet(); - result.add(type); - return result; - } - - @Override - public Set smArg(FunNType type, Set fBounded) { - Set result = new HashSet(); - result.add(type); - return result; - } - - @Override - public Set smArg(ExtendsType type, Set fBounded) { - Set result = new HashSet(); - result.add(type); - UnifyType t = type.getExtendedType(); - result.add(t); - smaller(t, fBounded).forEach(x -> { - result.add(new ExtendsType(x)); - result.add(x); - }); - return result; - } - - - @Override - public Set smArg(SuperType type, Set fBounded) { - Set result = new HashSet(); - result.add(type); - UnifyType t = type.getSuperedType(); - result.add(t); -//*** ACHTUNG das koennte FALSCH sein PL 2018-05-23 evtl. HashSet durch smArg durchschleifen - greater(t, fBounded).forEach(x -> { - result.add(new SuperType(x)); - result.add(x); - }); - return result; - } - - @Override - public Set smArg(PlaceholderType type, Set fBounded) { - HashSet result = new HashSet<>(); - result.add(type); - return result; - } - - @Override - public Set getAllTypesByName(String typeName) { - if(!strInheritanceGraph.containsKey(typeName)) - return new HashSet<>(); - return strInheritanceGraph.get(typeName).stream().map(x -> x.getContent()).collect(Collectors.toCollection(HashSet::new)); - } - - @Override - public Optional getLeftHandedType(String typeName) { - if(!strInheritanceGraph.containsKey(typeName)) - return Optional.empty(); - - for(UnifyPair pair : pairs) - if(pair.getLhsType().getName().equals(typeName) && pair.getLhsType().typeParams.arePlaceholders()) - return Optional.of(pair.getLhsType()); - - return Optional.empty(); - } - - @Override - public Set getAncestors(UnifyType t) { - if(!inheritanceGraph.containsKey(t)) - return new HashSet<>(); - Set result = inheritanceGraph.get(t).getContentOfPredecessors(); - result.add(t); - return result; - } - - @Override - public Set getChildren(UnifyType t) { - if(!inheritanceGraph.containsKey(t)) - return new HashSet<>(); - Set result = inheritanceGraph.get(t).getContentOfDescendants(); - result.add(t); - return result; - } - - /** - * Takes a set of candidates for each position and computes all possible permutations. - * @param candidates The length of the list determines the number of type params. Each set - * contains the candidates for the corresponding position. - */ - protected Set permuteParams(ArrayList> candidates) { - Set result = new HashSet<>(); - permuteParams(candidates, 0, result, new UnifyType[candidates.size()]); - return result; - } - - /** - * Takes a set of candidates for each position and computes all possible permutations. - * @param candidates The length of the list determines the number of type params. Each set - * contains the candidates for the corresponding position. - * @param idx Idx for the current permutatiton. - * @param result Set of all permutations found so far - * @param current The permutation of type params that is currently explored - */ - protected void permuteParams(ArrayList> candidates, int idx, Set result, UnifyType[] current) { - if(candidates.size() == idx) { - result.add(new TypeParams(Arrays.copyOf(current, current.length))); - return; - } - - Set localCandidates = candidates.get(idx); - - for(UnifyType t : localCandidates) { - current[idx] = t; - permuteParams(candidates, idx+1, result, current); - } - } - - @Override - public String toString(){ - return this.inheritanceGraph.toString(); - } - - /* entfernt PL 2018-12-11 - public int compare (UnifyType left, UnifyType right) { - return compare(left, right, PairOperator.SMALLERDOT); - } - */ - - public int compare (UnifyType left, UnifyType right, PairOperator pairop) { - if (left.getName().equals("Matrix") || right.getName().equals("Matrix")) - System.out.println(""); - /* - pairop = PairOperator.SMALLERDOTWC; - List al = new ArrayList<>(); - PlaceholderType xx =new PlaceholderType("xx"); - al.add(xx); - left = new ExtendsType(new ReferenceType("Vector", new TypeParams(al))); - - List alr = new ArrayList<>(); - UnifyType exx = new ExtendsType(xx); - alr.add(exx); - right = new ExtendsType(new ReferenceType("Vector", new TypeParams(alr))); - */ - /* - List al = new ArrayList<>(); - PlaceholderType xx =new PlaceholderType("xx"); - al.add(xx); - left = new ExtendsType(xx); - right = xx; - */ - /* - List al = new ArrayList<>(); - PlaceholderType xx =new PlaceholderType("xx"); - PlaceholderType yy =new PlaceholderType("yy"); - al.add(xx); - left = yy; - right = new ExtendsType(xx); - */ - //Die Faelle abfangen, bei den Variablen verglichen werden PL 2018-12-11 - UnifyType ex; - if (left instanceof PlaceholderType) { - if ((right instanceof WildcardType) - && ((ex = ((WildcardType)right).wildcardedType) instanceof PlaceholderType) - && ((PlaceholderType)left).getName().equals(((PlaceholderType)ex).getName())) {// a <.? ? extends a oder a <.? ? super a - return -1; - } - else { - return 0; - } - } - if (right instanceof PlaceholderType) {//&& (left instanceof WildcardType)) {PL geloescht 2019-01-15 analog zu oben - if ((left instanceof WildcardType) //PL eingefuegt 2019-01-15 analog zu oben - && ((ex = ((WildcardType)left).wildcardedType) instanceof PlaceholderType) - && ((PlaceholderType)right).getName().equals(((PlaceholderType)ex).getName())) {// ? extends a <. a oder ? super a <. a - return 1; - } - else { - return 0; - } - } - UnifyPair up = new UnifyPair(left, right, pairop); - TypeUnifyTask unifyTask = new TypeUnifyTask(); - HashSet hs = new HashSet<>(); - hs.add(up); - Set smallerRes = unifyTask.applyTypeUnificationRules(hs, this); - if (left.getName().equals("Matrix") || right.getName().equals("Matrix")) - {try { - logFile.write("\nsmallerRes: " + smallerRes);//"smallerHash: " + greaterHash.toString()); - logFile.flush(); - } - catch (IOException e) { - System.err.println("no LogFile");}} - //Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok. - Predicate delFun = x -> !((x.getLhsType() instanceof PlaceholderType || - x.getRhsType() instanceof PlaceholderType) - && !((x.getLhsType() instanceof WildcardType) && //? extends/super a <.? a - ((WildcardType)x.getLhsType()).getWildcardedType().equals(x.getRhsType())) - ); - long smallerLen = smallerRes.stream().filter(delFun).count(); - if (smallerLen == 0) return -1; - else { - up = new UnifyPair(right, left, pairop); - //TypeUnifyTask unifyTask = new TypeUnifyTask(); - hs = new HashSet<>(); - hs.add(up); - Set greaterRes = unifyTask.applyTypeUnificationRules(hs, this); - if (left.getName().equals("Matrix") || right.getName().equals("Matrix")) - {try { - logFile.write("\ngreaterRes: " + greaterRes);//"smallerHash: " + greaterHash.toString()); - logFile.flush(); - } - catch (IOException e) { - System.err.println("no LogFile");}} - //Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok. - long greaterLen = greaterRes.stream().filter(delFun).count(); - if (greaterLen == 0) return 1; - else return 0; - } - } -} +package de.dhbwstuttgart.typeinference.unify.model; + +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.function.BiFunction; +import java.util.function.BinaryOperator; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +import com.google.common.collect.Ordering; + +//PL 18-02-05/18-04-05 Unifier durch Matcher ersetzt +//muss greater noch ersetzt werden ja erledigt 18--04-05 +import de.dhbwstuttgart.typeinference.unify.MartelliMontanariUnify; + +import de.dhbwstuttgart.typeinference.unify.Match; +import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask; +import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify; + +/** + * The finite closure for the type unification + * @author Florian Steurer + */ +public class FiniteClosure //extends Ordering //entfernt PL 2018-12-11 +implements IFiniteClosure { + + Writer logFile; + static Boolean log = false; + public void setLogTrue() { + log = true; + } + /** + * A map that maps every type to the node in the inheritance graph that contains that type. + */ + private HashMap> inheritanceGraph; + + /** + * A map that maps every typename to the nodes of the inheritance graph that contain a type with that name. + */ + private HashMap>> strInheritanceGraph; + + + /** + * The initial pairs of that define the inheritance tree + */ + private Set pairs; + + /** + * Hastable fuer die greater-Werte, damit sie nicht doppelt berechnet werden muessen + */ + Hashtable> greaterHash = new Hashtable<>(); + + /** + * Hastable fuer die smaller-Werte, damit sie nicht doppelt berechnet werden muessen + */ + Hashtable> smallerHash = new Hashtable<>(); + + /** + * Creates a new instance using the inheritance tree defined in the pairs. + */ + public FiniteClosure(Set pairs, Writer logFile) { + this.logFile = logFile; + this.pairs = new HashSet<>(pairs); + inheritanceGraph = new HashMap>(); + + // Build the transitive closure of the inheritance tree + for(UnifyPair pair : pairs) { + if(pair.getPairOp() != PairOperator.SMALLER) + continue; + + //VERSUCH PL 18-02-06 + //koennte ggf. die FC reduzieren + //TO DO: Ueberpruefen, ob das sinnvll und korrekt ist + //if (!pair.getLhsType().getTypeParams().arePlaceholders() + // && !pair.getRhsType().getTypeParams().arePlaceholders()) + // continue; +; + // Add nodes if not already in the graph + if(!inheritanceGraph.containsKey(pair.getLhsType())) + inheritanceGraph.put(pair.getLhsType(), new Node(pair.getLhsType())); + if(!inheritanceGraph.containsKey(pair.getRhsType())) + inheritanceGraph.put(pair.getRhsType(), new Node(pair.getRhsType())); + + Node childNode = inheritanceGraph.get(pair.getLhsType()); + Node parentNode = inheritanceGraph.get(pair.getRhsType()); + + // Add edge + parentNode.addDescendant(childNode); + + // Add edges to build the transitive closure + parentNode.getPredecessors().stream().forEach(x -> x.addDescendant(childNode)); + childNode.getDescendants().stream().forEach(x -> x.addPredecessor(parentNode)); + } + + // Build the alternative representation with strings as keys + strInheritanceGraph = new HashMap<>(); + for(UnifyType key : inheritanceGraph.keySet()) { + if(!strInheritanceGraph.containsKey(key.getName())) + strInheritanceGraph.put(key.getName(), new HashSet<>()); + + strInheritanceGraph.get(key.getName()).add(inheritanceGraph.get(key)); + } + } + + void testSmaller() { + UnifyType tq1, tq2, tq3; + tq1 = new ExtendsType(PlaceholderType.freshPlaceholder()); + List l1 = new ArrayList<>(); + List l2 = new ArrayList<>(); + l1.add(tq1); + tq2 = new ReferenceType("java.util.Vector", new TypeParams(l1)); + l2.add(tq2); + tq3 = new ReferenceType("java.util.Vector", new TypeParams(l2)); + Set smaller = smaller(tq3, new HashSet<>()); + } + + /** + * Returns all types of the finite closure that are subtypes of the argument. + * @return The set of subtypes of the argument. + */ + @Override + public Set smaller(UnifyType type, Set fBounded) { + + Set ret; + if ((ret = smallerHash.get(new hashKeyType(type))) != null) { + //System.out.println(greaterHash); + return new HashSet<>(ret); + } + + if(type instanceof FunNType) + return computeSmallerFunN((FunNType) type, fBounded); + + Set>> ts = new HashSet<>(); + ts.add(new Pair<>(type, fBounded)); + Set result = computeSmaller(ts); + smallerHash.put(new hashKeyType(type), result); + /* + try { + logFile.write("\ntype: " + type + "\nret: " + ret + "\nresult: " + result);//"smallerHash: " + greaterHash.toString()); + logFile.flush(); + } + catch (IOException e) { + System.err.println("no LogFile"); + }*/ + return result; + } + + /** + * Computes the smaller functions for every type except FunNTypes. + */ + private Set computeSmaller(Set>> types) { + Set>> result = new HashSet<>(); + + //PL 18-02-05 Unifier durch Matcher ersetzt + //IUnify unify = new MartelliMontanariUnify(); + Match match = new Match(); + + for(Pair> pt : types) { + UnifyType t = pt.getKey(); + Set fBounded = pt.getValue().get(); + + // if T = T' then T <* T' + try { + result.add(new Pair<>(t, fBounded)); + } + catch (StackOverflowError e) { + System.out.println(""); + } + + // if C<...> <* C<...> then ... (third case in definition of <*) + if(t.getTypeParams().size() > 0) { + ArrayList> paramCandidates = new ArrayList<>(); + for (int i = 0; i < t.getTypeParams().size(); i++) + paramCandidates.add(smArg(t.getTypeParams().get(i), fBounded)); + permuteParams(paramCandidates).forEach(x -> result.add(new Pair<>(t.setTypeParams(x), fBounded))); + } + + if(!strInheritanceGraph.containsKey(t.getName())) + continue; + + // if T <* T' then sigma(T) <* sigma(T') + Set> candidates = strInheritanceGraph.get(t.getName()); //cadidates= [???Node(java.util.Vector>)??? + // , Node(java.util.Vector) + //] + for(Node candidate : candidates) { + UnifyType theta2 = candidate.getContent(); + //PL 18-02-05 Unifier durch Matcher ersetzt ANFANG + ArrayList termList= new ArrayList(); + termList.add(new UnifyPair(theta2,t, PairOperator.EQUALSDOT)); + Optional optSigma = match.match(termList); + //PL 18-02-05 Unifier durch Matcher ersetzt ENDE + if(!optSigma.isPresent()) + continue; + + Unifier sigma = optSigma.get(); + sigma.swapPlaceholderSubstitutions(t.getTypeParams()); + + Set theta1Set = candidate.getContentOfDescendants(); + + for(UnifyType theta1 : theta1Set) + result.add(new Pair<>(theta1.apply(sigma), fBounded)); + } + } + + HashSet resut = result.stream().map(x -> x.getKey()).collect(Collectors.toCollection(HashSet::new)); + if(resut.equals(types.stream().map(x -> x.getKey()).collect(Collectors.toCollection(HashSet::new)))) + return resut; + return computeSmaller(result); + } + + /** + * Computes the smaller-Function for FunNTypes. + */ + private Set computeSmallerFunN(FunNType type, Set fBounded) { + Set result = new HashSet<>(); + + // if T = T' then T <=* T' + result.add(type); + + // Because real function types are implicitly variant + // it is enough to permute the params with the values of greater / smaller. + ArrayList> paramCandidates = new ArrayList<>(); + paramCandidates.add(smaller(type.getTypeParams().get(0), fBounded)); + for (int i = 1; i < type.getTypeParams().size(); i++) + paramCandidates.add(greater(type.getTypeParams().get(i), new HashSet<>())); + + permuteParams(paramCandidates).forEach(x -> result.add(type.setTypeParams(x))); + return result; + } + + /** + * Returns all types of the finite closure that are supertypes of the argument. + * @return The set of supertypes of the argument. + */ + @Override + //Eingefuegt PL 2018-05-24 F-Bounded Problematik + public Set greater(UnifyType type, Set fBounded) { + + Set ret; + if ((ret = greaterHash.get(new hashKeyType(type))) != null) { + //System.out.println(greaterHash); + return new HashSet<>(ret); + } + + + if(type instanceof FunNType) { + return computeGreaterFunN((FunNType) type, fBounded); + } + + Set result = new HashSet<>(); + Set>> PairResultFBounded = new HashSet<>(); + + Match match = new Match(); + + + // if T = T' then T <=* T' + result.add(type); + if(!strInheritanceGraph.containsKey(type.getName())) + return result; + + // if T <* T' then sigma(T) <* sigma(T') + Set> candidates = strInheritanceGraph.get(type.getName()); + + /* + try { + if (log) logFile.write(candidates.toString()); + //log = false; + } + catch (IOException e) { + System.err.println("no LogFile"); + } + */ + + for(Node candidate : candidates) { + UnifyType theta1 = candidate.getContent(); + + //PL 18-04-05 Unifier durch Matcher ersetzt ANFANG + ArrayList termList= new ArrayList(); + termList.add(new UnifyPair(theta1,type, PairOperator.EQUALSDOT)); + Optional optSigma = match.match(termList); + //PL 18-04-05 Unifier durch Matcher ersetzt ENDE + if(!optSigma.isPresent()) { + continue; + } + Unifier sigma = optSigma.get(); + sigma.swapPlaceholderSubstitutionsReverse(theta1.getTypeParams()); + + Set fBoundedNew = new HashSet<>(fBounded); + fBoundedNew.add(theta1); + Set theta2Set = candidate.getContentOfPredecessors(); + //System.out.println(""); + for(UnifyType theta2 : theta2Set) { + result.add(theta2.apply(sigma)); + PairResultFBounded.add(new Pair<>(theta2.apply(sigma), fBoundedNew)); + } + } + /* + try { + if (log) logFile.write(PairResultFBounded.toString()); + log = false; + } + catch (IOException e) { + System.err.println("no LogFile"); + } + */ + for(Pair> pt : PairResultFBounded) { + UnifyType t = pt.getKey(); + Set lfBounded = pt.getValue().get(); + + // if C<...> <* C<...> then ... (third case in definition of <*) + //TypeParams typeparams = t.getTypeParams(); + if(t.getTypeParams().size() > 0) { + ArrayList> paramCandidates = new ArrayList<>(); + + for (int i = 0; i < t.getTypeParams().size(); i++) { + //UnifyType parai = t.getTypeParams().get(i); + int i_ef = i; + BiFunction f = (x,y) -> + { + ArrayList termList = new ArrayList(); + termList.add(new UnifyPair(y,t.getTypeParams().get(i_ef), PairOperator.EQUALSDOT)); + return ((match.match(termList).isPresent()) || x); + }; + //if (parai.getName().equals("java.lang.Integer")) { + // System.out.println(""); + //} + BinaryOperator bo = (a,b) -> (a || b); + if (lfBounded.stream().reduce(false,f,bo)) { + //F-Bounded Endlosrekursion + HashSet res = new HashSet(); + paramCandidates.add(res); + } + else { + paramCandidates.add(grArg(t.getTypeParams().get(i), new HashSet<>(fBounded) )); + } + } + permuteParams(paramCandidates).forEach(x -> result.add(t.setTypeParams(x))); + //System.out.println(""); + } + } + + greaterHash.put(new hashKeyType(type), result); + /* + try { + logFile.write("\ntype: " + type + "\nret: " + ret + "\nresult: " + result);//"greaterHash: " + greaterHash.toString()); + logFile.flush(); + } + catch (IOException e) { + System.err.println("no LogFile"); + }*/ + return result; + } + + /* auskommentiert PL 2018-05-24 + /** + * Returns all types of the finite closure that are supertypes of the argument. + * @return The set of supertypes of the argument. + * + //@Override + public Set oldgreater(UnifyType type, Set fBounded) { + if(type instanceof FunNType) + return computeGreaterFunN((FunNType) type, fBounded); + + Set>> ts = new HashSet<>(); + ts.add(new Pair<>(type, fBounded)); + return computeGreater(ts); + } + + /** + * Computes the greater function for all types except function types. + * + protected Set computeGreater(Set>> types) { + Set>> result = new HashSet<>(); + + //PL 18-04-05 Unifier durch Matcher ersetzt + //IUnify unify = new MartelliMontanariUnify(); + Match match = new Match(); + + for(Pair> pt : types) { + UnifyType t = pt.getKey(); + Set fBounded = pt.getValue().get(); + // if T = T' then T <=* T' + result.add(pt); + + // if C<...> <* C<...> then ... (third case in definition of <*) + if(t.getTypeParams().size() > 0) { + ArrayList> paramCandidates = new ArrayList<>(); + for (int i = 0; i < t.getTypeParams().size(); i++) { + UnifyType parai = t.getTypeParams().get(i); + int i_ef = i; + BiFunction f = (x,y) -> + { + ArrayList termList = new ArrayList(); + termList.add(new UnifyPair(y,t.getTypeParams().get(i_ef), PairOperator.EQUALSDOT)); + return ((match.match(termList).isPresent()) || x); + }; + if (parai.getName().equals("java.lang.Integer")) { + System.out.println(""); + } + BinaryOperator bo = (a,b) -> (a || b); + if (fBounded.stream().reduce(false,f,bo)) continue; //F-Bounded Endlosrekursion + paramCandidates.add(grArg(t.getTypeParams().get(i), new HashSet<>(fBounded) )); + } + permuteParams(paramCandidates).forEach(x -> result.add(new Pair<>(t.setTypeParams(x), new HashSet<>(fBounded)))); + } + + if(!strInheritanceGraph.containsKey(t.getName())) + continue; + + // if T <* T' then sigma(T) <* sigma(T') + Set> candidates = strInheritanceGraph.get(t.getName()); + for(Node candidate : candidates) { + UnifyType theta1 = candidate.getContent(); + + //PL 18-04-05 Unifier durch Matcher ersetzt ANFANG + ArrayList termList= new ArrayList(); + termList.add(new UnifyPair(theta1,t, PairOperator.EQUALSDOT)); + Optional optSigma = match.match(termList); + //PL 18-04-05 Unifier durch Matcher ersetzt ENDE + if(!optSigma.isPresent()) + continue; + + Unifier sigma = optSigma.get(); + sigma.swapPlaceholderSubstitutionsReverse(theta1.getTypeParams()); + + Set fBoundedNew = new HashSet<>(fBounded); + fBoundedNew.add(theta1); + Set theta2Set = candidate.getContentOfPredecessors(); + + for(UnifyType theta2 : theta2Set) + result.add(new Pair<>(theta2.apply(sigma), fBoundedNew)); + } + + } + + HashSet resut = result.stream().map(x -> x.getKey()).collect(Collectors.toCollection(HashSet::new)); + System.out.println(resut); + if(resut.equals(types.stream().map(x -> x.getKey()).collect(Collectors.toCollection(HashSet::new)))) + return resut; + return computeGreater(result); + } + */ + + /** + * Computes the greater function for FunN-Types + */ + protected Set computeGreaterFunN(FunNType type, Set fBounded) { + Set result = new HashSet<>(); + + // if T = T' then T <=* T' + result.add(type); + + // Because real function types are implicitly variant + // it is enough to permute the params with the values of greater / smaller. + ArrayList> paramCandidates = new ArrayList<>(); + paramCandidates.add(greater(type.getTypeParams().get(0), new HashSet<>())); + for (int i = 1; i < type.getTypeParams().size(); i++) + paramCandidates.add(smaller(type.getTypeParams().get(i), fBounded)); + permuteParams(paramCandidates).forEach(x -> result.add(type.setTypeParams(x))); + return result; + } + + + @Override + public Set grArg(UnifyType type, Set fBounded) { + return type.grArg(this, fBounded); + } + + @Override + public Set grArg(ReferenceType type, Set fBounded) { + Set result = new HashSet(); + result.add(type); + smaller(type, fBounded).forEach(x -> result.add(new SuperType(x))); + greater(type,fBounded).forEach(x -> result.add(new ExtendsType(x))); + return result; + } + + @Override + public Set grArg(FunNType type, Set fBounded) { + Set result = new HashSet(); + result.add(type); + smaller(type, fBounded).forEach(x -> result.add(new SuperType(x))); + greater(type, fBounded).forEach(x -> result.add(new ExtendsType(x))); + return result; + } + + @Override + public Set grArg(ExtendsType type, Set fBounded) { + Set result = new HashSet(); + result.add(type); + UnifyType t = type.getExtendedType(); + greater(t, fBounded).forEach(x -> result.add(new ExtendsType(x))); + return result; + } + + @Override + public Set grArg(SuperType type, Set fBounded) { + Set result = new HashSet(); + result.add(type); + UnifyType t = type.getSuperedType(); + smaller(t, fBounded).forEach(x -> result.add(new SuperType(x))); + return result; + } + + @Override + public Set grArg(PlaceholderType type, Set fBounded) { + HashSet result = new HashSet<>(); + result.add(type); + return result; + } + + @Override + public Set smArg(UnifyType type, Set fBounded) { + return type.smArg(this, fBounded); + } + + @Override + public Set smArg(ReferenceType type, Set fBounded) { + Set result = new HashSet(); + result.add(type); + return result; + } + + @Override + public Set smArg(FunNType type, Set fBounded) { + Set result = new HashSet(); + result.add(type); + return result; + } + + @Override + public Set smArg(ExtendsType type, Set fBounded) { + Set result = new HashSet(); + result.add(type); + UnifyType t = type.getExtendedType(); + result.add(t); + smaller(t, fBounded).forEach(x -> { + result.add(new ExtendsType(x)); + result.add(x); + }); + return result; + } + + + @Override + public Set smArg(SuperType type, Set fBounded) { + Set result = new HashSet(); + result.add(type); + UnifyType t = type.getSuperedType(); + result.add(t); +//*** ACHTUNG das koennte FALSCH sein PL 2018-05-23 evtl. HashSet durch smArg durchschleifen + greater(t, fBounded).forEach(x -> { + result.add(new SuperType(x)); + result.add(x); + }); + return result; + } + + @Override + public Set smArg(PlaceholderType type, Set fBounded) { + HashSet result = new HashSet<>(); + result.add(type); + return result; + } + + @Override + public Set getAllTypesByName(String typeName) { + if(!strInheritanceGraph.containsKey(typeName)) + return new HashSet<>(); + return strInheritanceGraph.get(typeName).stream().map(x -> x.getContent()).collect(Collectors.toCollection(HashSet::new)); + } + + @Override + public Optional getLeftHandedType(String typeName) { + if(!strInheritanceGraph.containsKey(typeName)) + return Optional.empty(); + + for(UnifyPair pair : pairs) + if(pair.getLhsType().getName().equals(typeName) && pair.getLhsType().typeParams.arePlaceholders()) + return Optional.of(pair.getLhsType()); + + return Optional.empty(); + } + + @Override + public Set getAncestors(UnifyType t) { + if(!inheritanceGraph.containsKey(t)) + return new HashSet<>(); + Set result = inheritanceGraph.get(t).getContentOfPredecessors(); + result.add(t); + return result; + } + + @Override + public Set getChildren(UnifyType t) { + if(!inheritanceGraph.containsKey(t)) + return new HashSet<>(); + Set result = inheritanceGraph.get(t).getContentOfDescendants(); + result.add(t); + return result; + } + + /** + * Takes a set of candidates for each position and computes all possible permutations. + * @param candidates The length of the list determines the number of type params. Each set + * contains the candidates for the corresponding position. + */ + protected Set permuteParams(ArrayList> candidates) { + Set result = new HashSet<>(); + permuteParams(candidates, 0, result, new UnifyType[candidates.size()]); + return result; + } + + /** + * Takes a set of candidates for each position and computes all possible permutations. + * @param candidates The length of the list determines the number of type params. Each set + * contains the candidates for the corresponding position. + * @param idx Idx for the current permutatiton. + * @param result Set of all permutations found so far + * @param current The permutation of type params that is currently explored + */ + protected void permuteParams(ArrayList> candidates, int idx, Set result, UnifyType[] current) { + if(candidates.size() == idx) { + result.add(new TypeParams(Arrays.copyOf(current, current.length))); + return; + } + + Set localCandidates = candidates.get(idx); + + for(UnifyType t : localCandidates) { + current[idx] = t; + permuteParams(candidates, idx+1, result, current); + } + } + + @Override + public String toString(){ + return this.inheritanceGraph.toString(); + } + + /* entfernt PL 2018-12-11 + public int compare (UnifyType left, UnifyType right) { + return compare(left, right, PairOperator.SMALLERDOT); + } + */ + + public int compare (UnifyType left, UnifyType right, PairOperator pairop) { + if (left.getName().equals("Matrix") || right.getName().equals("Matrix")) + System.out.println(""); + /* + pairop = PairOperator.SMALLERDOTWC; + List al = new ArrayList<>(); + PlaceholderType xx =new PlaceholderType("xx"); + al.add(xx); + left = new ExtendsType(new ReferenceType("Vector", new TypeParams(al))); + + List alr = new ArrayList<>(); + UnifyType exx = new ExtendsType(xx); + alr.add(exx); + right = new ExtendsType(new ReferenceType("Vector", new TypeParams(alr))); + */ + /* + List al = new ArrayList<>(); + PlaceholderType xx =new PlaceholderType("xx"); + al.add(xx); + left = new ExtendsType(xx); + right = xx; + */ + /* + List al = new ArrayList<>(); + PlaceholderType xx =new PlaceholderType("xx"); + PlaceholderType yy =new PlaceholderType("yy"); + al.add(xx); + left = yy; + right = new ExtendsType(xx); + */ + //Die Faelle abfangen, bei den Variablen verglichen werden PL 2018-12-11 + UnifyType ex; + if (left instanceof PlaceholderType) { + if ((right instanceof WildcardType) + && ((ex = ((WildcardType)right).wildcardedType) instanceof PlaceholderType) + && ((PlaceholderType)left).getName().equals(((PlaceholderType)ex).getName())) {// a <.? ? extends a oder a <.? ? super a + return -1; + } + else { + return 0; + } + } + if (right instanceof PlaceholderType) {//&& (left instanceof WildcardType)) {PL geloescht 2019-01-15 analog zu oben + if ((left instanceof WildcardType) //PL eingefuegt 2019-01-15 analog zu oben + && ((ex = ((WildcardType)left).wildcardedType) instanceof PlaceholderType) + && ((PlaceholderType)right).getName().equals(((PlaceholderType)ex).getName())) {// ? extends a <. a oder ? super a <. a + return 1; + } + else { + return 0; + } + } + UnifyPair up = new UnifyPair(left, right, pairop); + TypeUnifyTask unifyTask = new TypeUnifyTask(); + HashSet hs = new HashSet<>(); + hs.add(up); + Set smallerRes = unifyTask.applyTypeUnificationRules(hs, this); + if (left.getName().equals("Matrix") || right.getName().equals("Matrix")) + {try { + logFile.write("\nsmallerRes: " + smallerRes);//"smallerHash: " + greaterHash.toString()); + logFile.flush(); + } + catch (IOException e) { + System.err.println("no LogFile");}} + //Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok. + Predicate delFun = x -> !((x.getLhsType() instanceof PlaceholderType || + x.getRhsType() instanceof PlaceholderType) + && !((x.getLhsType() instanceof WildcardType) && //? extends/super a <.? a + ((WildcardType)x.getLhsType()).getWildcardedType().equals(x.getRhsType())) + ); + long smallerLen = smallerRes.stream().filter(delFun).count(); + if (smallerLen == 0) return -1; + else { + up = new UnifyPair(right, left, pairop); + //TypeUnifyTask unifyTask = new TypeUnifyTask(); + hs = new HashSet<>(); + hs.add(up); + Set greaterRes = unifyTask.applyTypeUnificationRules(hs, this); + if (left.getName().equals("Matrix") || right.getName().equals("Matrix")) + {try { + logFile.write("\ngreaterRes: " + greaterRes);//"smallerHash: " + greaterHash.toString()); + logFile.flush(); + } + catch (IOException e) { + System.err.println("no LogFile");}} + //Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok. + long greaterLen = greaterRes.stream().filter(delFun).count(); + if (greaterLen == 0) return 1; + else return 0; + } + } +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FunNType.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FunNType.java index 37cf6a0a4..f46ac9183 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FunNType.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FunNType.java @@ -1,103 +1,103 @@ -package de.dhbwstuttgart.typeinference.unify.model; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Set; - -import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; -import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; - -/** - * A real function type in java. - * @author Florian Steurer - */ -public class FunNType extends UnifyType { - - public UnifyType accept(UnifyTypeVisitor visitor, T ht) { - return visitor.visit(this, ht); - } - - /** - * Creates a FunN-Type with the specified TypeParameters. - */ - protected FunNType(TypeParams p) { - super("Fun"+(p.size()-1)+"$$", p); - } - - /** - * Creates a new FunNType. - * @param tp The parameters of the type. - * @return A FunNType. - * @throws IllegalArgumentException is thrown when there are to few type parameters or there are wildcard-types. - */ - public static FunNType getFunNType(TypeParams tp) throws IllegalArgumentException { - if(tp.size() == 0) - throw new IllegalArgumentException("FunNTypes need at least one type parameter"); - for(UnifyType t : tp) - if(t instanceof WildcardType) - throw new IllegalArgumentException("Invalid TypeParams for a FunNType: " + tp); - return new FunNType(tp); - } - - /** - * Returns the degree of the function type, e.g. 2 for FunN. - */ - public int getN() { - return typeParams.size()-1; - } - - @Override - public UnifyType setTypeParams(TypeParams newTp) { - if(newTp.hashCode() == typeParams.hashCode() && newTp.equals(typeParams)) - return this; - return getFunNType(newTp); - } - - @Override - Set smArg(IFiniteClosure fc, Set fBounded) { - return fc.smArg(this, fBounded); - } - - @Override - Set grArg(IFiniteClosure fc, Set fBounded) { - return fc.grArg(this, fBounded); - } - - @Override - UnifyType apply(Unifier unif) { - // TODO this bypasses the validation of the type parameters. - // Wildcard types can be unified into FunNTypes. - TypeParams newParams = typeParams.apply(unif); - if(newParams.hashCode() == typeParams.hashCode() && newParams.equals(typeParams)) - return this; - - return new FunNType(newParams); - } - - @Override - public Boolean wrongWildcard() { - return (new ArrayList(Arrays.asList(getTypeParams() - .get())).stream().filter(x -> (x instanceof WildcardType)).findFirst().isPresent()); - } - - @Override - public int hashCode() { - return 181 + typeParams.hashCode(); - } - - - @Override - public boolean equals(Object obj) { - if(!(obj instanceof FunNType)) - return false; - - if(obj.hashCode() != this.hashCode()) - return false; - - FunNType other = (FunNType) obj; - - return other.getTypeParams().equals(typeParams); - } - -} +package de.dhbwstuttgart.typeinference.unify.model; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Set; + +import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; + +/** + * A real function type in java. + * @author Florian Steurer + */ +public class FunNType extends UnifyType { + + public UnifyType accept(UnifyTypeVisitor visitor, T ht) { + return visitor.visit(this, ht); + } + + /** + * Creates a FunN-Type with the specified TypeParameters. + */ + protected FunNType(TypeParams p) { + super("Fun"+(p.size()-1)+"$$", p); + } + + /** + * Creates a new FunNType. + * @param tp The parameters of the type. + * @return A FunNType. + * @throws IllegalArgumentException is thrown when there are to few type parameters or there are wildcard-types. + */ + public static FunNType getFunNType(TypeParams tp) throws IllegalArgumentException { + if(tp.size() == 0) + throw new IllegalArgumentException("FunNTypes need at least one type parameter"); + for(UnifyType t : tp) + if(t instanceof WildcardType) + throw new IllegalArgumentException("Invalid TypeParams for a FunNType: " + tp); + return new FunNType(tp); + } + + /** + * Returns the degree of the function type, e.g. 2 for FunN. + */ + public int getN() { + return typeParams.size()-1; + } + + @Override + public UnifyType setTypeParams(TypeParams newTp) { + if(newTp.hashCode() == typeParams.hashCode() && newTp.equals(typeParams)) + return this; + return getFunNType(newTp); + } + + @Override + Set smArg(IFiniteClosure fc, Set fBounded) { + return fc.smArg(this, fBounded); + } + + @Override + Set grArg(IFiniteClosure fc, Set fBounded) { + return fc.grArg(this, fBounded); + } + + @Override + UnifyType apply(Unifier unif) { + // TODO this bypasses the validation of the type parameters. + // Wildcard types can be unified into FunNTypes. + TypeParams newParams = typeParams.apply(unif); + if(newParams.hashCode() == typeParams.hashCode() && newParams.equals(typeParams)) + return this; + + return new FunNType(newParams); + } + + @Override + public Boolean wrongWildcard() { + return (new ArrayList(Arrays.asList(getTypeParams() + .get())).stream().filter(x -> (x instanceof WildcardType)).findFirst().isPresent()); + } + + @Override + public int hashCode() { + return 181 + typeParams.hashCode(); + } + + + @Override + public boolean equals(Object obj) { + if(!(obj instanceof FunNType)) + return false; + + if(obj.hashCode() != this.hashCode()) + return false; + + FunNType other = (FunNType) obj; + + return other.getTypeParams().equals(typeParams); + } + +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/Node.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/Node.java index aa375c091..d108e91bb 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/Node.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/Node.java @@ -1,100 +1,100 @@ -package de.dhbwstuttgart.typeinference.unify.model; - -import java.util.HashSet; -import java.util.Set; -import java.util.stream.Collectors; - -/** - * A node of a directed graph. - * @author Florian Steurer - * - * @param The type of the content of the node. - */ -class Node { - - /** - * The content of the node. - */ - private T content; - - /** - * The set of predecessors - */ - private HashSet> predecessors = new HashSet<>(); - - /** - * The set of descendants - */ - private HashSet> descendants = new HashSet<>(); - - /** - * Creates a node containing the specified content. - */ - public Node(T content) { - this.content = content; - } - - /** - * Adds a directed edge from this node to the descendant (this -> descendant) - */ - public void addDescendant(Node descendant) { - if(descendants.contains(descendant)) - return; - - descendants.add(descendant); - descendant.addPredecessor(this); - } - - /** - * Adds a directed edge from the predecessor to this node (predecessor -> this) - */ - public void addPredecessor(Node predecessor) { - if(predecessors.contains(predecessor)) - return; - - predecessors.add(predecessor); - predecessor.addDescendant(this); - } - - /** - * The content of this node. - */ - public T getContent() { - return content; - } - - /** - * Returns all predecessors (nodes that have a directed edge to this node) - */ - public Set> getPredecessors() { - return predecessors; - } - - /** - * Returns all descendants. All nodes M, where there is a edge from this node to the node M. - * @return - */ - public Set> getDescendants() { - return descendants; - } - - /** - * Retrieves the content of all descendants. - */ - public Set getContentOfDescendants() { - return descendants.stream().map(x -> x.getContent()).collect(Collectors.toSet()); - } - - /** - * Retrieves the content of all predecessors. - */ - public Set getContentOfPredecessors() { - return predecessors.stream().map(x -> x.getContent()).collect(Collectors.toSet()); - } - - @Override - public String toString() { - return "Elem: Node(" + content.toString() + ")\nPrec: " + getContentOfPredecessors().toString() - + "\nDesc: " + getContentOfDescendants().toString() + "\n\n"; - } -} +package de.dhbwstuttgart.typeinference.unify.model; + +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * A node of a directed graph. + * @author Florian Steurer + * + * @param The type of the content of the node. + */ +class Node { + + /** + * The content of the node. + */ + private T content; + + /** + * The set of predecessors + */ + private HashSet> predecessors = new HashSet<>(); + + /** + * The set of descendants + */ + private HashSet> descendants = new HashSet<>(); + + /** + * Creates a node containing the specified content. + */ + public Node(T content) { + this.content = content; + } + + /** + * Adds a directed edge from this node to the descendant (this -> descendant) + */ + public void addDescendant(Node descendant) { + if(descendants.contains(descendant)) + return; + + descendants.add(descendant); + descendant.addPredecessor(this); + } + + /** + * Adds a directed edge from the predecessor to this node (predecessor -> this) + */ + public void addPredecessor(Node predecessor) { + if(predecessors.contains(predecessor)) + return; + + predecessors.add(predecessor); + predecessor.addDescendant(this); + } + + /** + * The content of this node. + */ + public T getContent() { + return content; + } + + /** + * Returns all predecessors (nodes that have a directed edge to this node) + */ + public Set> getPredecessors() { + return predecessors; + } + + /** + * Returns all descendants. All nodes M, where there is a edge from this node to the node M. + * @return + */ + public Set> getDescendants() { + return descendants; + } + + /** + * Retrieves the content of all descendants. + */ + public Set getContentOfDescendants() { + return descendants.stream().map(x -> x.getContent()).collect(Collectors.toSet()); + } + + /** + * Retrieves the content of all predecessors. + */ + public Set getContentOfPredecessors() { + return predecessors.stream().map(x -> x.getContent()).collect(Collectors.toSet()); + } + + @Override + public String toString() { + return "Elem: Node(" + content.toString() + ")\nPrec: " + getContentOfPredecessors().toString() + + "\nDesc: " + getContentOfDescendants().toString() + "\n\n"; + } +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java index 60cf342f2..63f3d4481 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java @@ -1,195 +1,195 @@ -package de.dhbwstuttgart.typeinference.unify.model; - -import java.io.File; -import java.io.FileWriter; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Random; -import java.util.Set; - -import de.dhbwstuttgart.typeinference.unify.distributeVariance; -import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; -import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; - -/** - * An unbounded placeholder type. - * @author Florian Steurer - */ -public final class PlaceholderType extends UnifyType{ - - /** - * Static list containing the names of all existing placeholders. - * Used for generating fresh placeholders. - */ - public static final ArrayList EXISTING_PLACEHOLDERS = new ArrayList(); - - /** - * Prefix of auto-generated placeholder names. - */ - protected static String nextName = "gen_"; - - /** - * Random number generator used to generate fresh placeholder name. - */ - protected static Random rnd = new Random(43558747548978L); - - /** - * True if this object was auto-generated, false if this object was user-generated. - */ - private final boolean IsGenerated; - - - /** - * isWildcardable gibt an, ob ein Wildcardtyp dem PlaceholderType zugeordnet werden darf - */ - private boolean wildcardable = true; - - /** - * is innerType gibt an, ob der Type des PlaceholderType innerhalb eines Typkonstruktorsverwendet wird - */ - private boolean innerType = false; - - /** - * variance shows the variance of the pair - * -1: contravariant - * 1 covariant - * 0 invariant - * PL 2018-03-21 - */ - private int variance = 0; - - /** - * Creates a new placeholder type with the specified name. - */ - public PlaceholderType(String name) { - super(name, new TypeParams()); - EXISTING_PLACEHOLDERS.add(name); // Add to list of existing placeholder names - IsGenerated = false; // This type is user generated - } - - /** - * Creates a new placeholdertype - * @param isGenerated true if this placeholder is auto-generated, false if it is user-generated. - */ - protected PlaceholderType(String name, boolean isGenerated) { - super(name, new TypeParams()); - EXISTING_PLACEHOLDERS.add(name); // Add to list of existing placeholder names - IsGenerated = isGenerated; - } - - public UnifyType accept(UnifyTypeVisitor visitor, T ht) { - return visitor.visit(this, ht); - } - - /** - * Creates a fresh placeholder type with a name that does so far not exist. - * A user could later instantiate a type using the same name that is equivalent to this type. - * @return A fresh placeholder type. - */ - public synchronized static PlaceholderType freshPlaceholder() { - String name = nextName + (char) (rnd.nextInt(22) + 97); // Returns random char between 'a' and 'z' - // Add random chars while the name is in use. - while(EXISTING_PLACEHOLDERS.contains(name)) { - name += (char) (rnd.nextInt(22) + 97); // Returns random char between 'a' and 'z' - } - return new PlaceholderType(name, true); - } - - - /** - * True if this placeholder is auto-generated, false if it is user-generated. - */ - public boolean isGenerated() { - return IsGenerated; - } - - public void setVariance(int v) { - variance = v; - } - - public int getVariance() { - return variance; - } - - public void reversVariance() { - if (variance == 1) { - setVariance(-1); - } else { - if (variance == -1) { - setVariance(1); - }} - } - - public Boolean isWildcardable() { - return wildcardable; - } - public void disableWildcardtable() { - wildcardable = false; - } - - public void enableWildcardtable() { - wildcardable = true; - } - - public void setWildcardtable(Boolean wildcardable) { - this.wildcardable = wildcardable; - } - - public Boolean isInnerType() { - return innerType; - } - - public void setInnerType(Boolean innerType) { - this.innerType = innerType; - } - - @Override - Set smArg(IFiniteClosure fc, Set fBounded) { - return fc.smArg(this, fBounded); - } - - @Override - Set grArg(IFiniteClosure fc, Set fBounded) { - return fc.grArg(this, fBounded); - } - - @Override - public UnifyType setTypeParams(TypeParams newTp) { - return this; // Placeholders never have params. - } - - @Override - public int hashCode() { - return typeName.hashCode(); - } - - @Override - UnifyType apply(Unifier unif) { - if(unif.hasSubstitute(this)) { - UnifyType ret = unif.getSubstitute(this); - //PL 2018-05-17 Auskommentierung muesste korrekt sein, - //bereits in JavaTXComplier Variancen gesetzt werden. - //ret.accept(new distributeVariance(), this.getVariance()); - return ret; - } - return this; - } - - @Override - public boolean equals(Object obj) { - if(!(obj instanceof PlaceholderType)) - return false; - - return ((PlaceholderType) obj).getName().equals(typeName); - } - - - @Override - public Collection getInvolvedPlaceholderTypes() { - ArrayList ret = new ArrayList<>(); - ret.add(this); - return ret; - } -} +package de.dhbwstuttgart.typeinference.unify.model; + +import java.io.File; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Random; +import java.util.Set; + +import de.dhbwstuttgart.typeinference.unify.distributeVariance; +import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; + +/** + * An unbounded placeholder type. + * @author Florian Steurer + */ +public final class PlaceholderType extends UnifyType{ + + /** + * Static list containing the names of all existing placeholders. + * Used for generating fresh placeholders. + */ + public static final ArrayList EXISTING_PLACEHOLDERS = new ArrayList(); + + /** + * Prefix of auto-generated placeholder names. + */ + protected static String nextName = "gen_"; + + /** + * Random number generator used to generate fresh placeholder name. + */ + protected static Random rnd = new Random(43558747548978L); + + /** + * True if this object was auto-generated, false if this object was user-generated. + */ + private final boolean IsGenerated; + + + /** + * isWildcardable gibt an, ob ein Wildcardtyp dem PlaceholderType zugeordnet werden darf + */ + private boolean wildcardable = true; + + /** + * is innerType gibt an, ob der Type des PlaceholderType innerhalb eines Typkonstruktorsverwendet wird + */ + private boolean innerType = false; + + /** + * variance shows the variance of the pair + * -1: contravariant + * 1 covariant + * 0 invariant + * PL 2018-03-21 + */ + private int variance = 0; + + /** + * Creates a new placeholder type with the specified name. + */ + public PlaceholderType(String name) { + super(name, new TypeParams()); + EXISTING_PLACEHOLDERS.add(name); // Add to list of existing placeholder names + IsGenerated = false; // This type is user generated + } + + /** + * Creates a new placeholdertype + * @param isGenerated true if this placeholder is auto-generated, false if it is user-generated. + */ + protected PlaceholderType(String name, boolean isGenerated) { + super(name, new TypeParams()); + EXISTING_PLACEHOLDERS.add(name); // Add to list of existing placeholder names + IsGenerated = isGenerated; + } + + public UnifyType accept(UnifyTypeVisitor visitor, T ht) { + return visitor.visit(this, ht); + } + + /** + * Creates a fresh placeholder type with a name that does so far not exist. + * A user could later instantiate a type using the same name that is equivalent to this type. + * @return A fresh placeholder type. + */ + public synchronized static PlaceholderType freshPlaceholder() { + String name = nextName + (char) (rnd.nextInt(22) + 97); // Returns random char between 'a' and 'z' + // Add random chars while the name is in use. + while(EXISTING_PLACEHOLDERS.contains(name)) { + name += (char) (rnd.nextInt(22) + 97); // Returns random char between 'a' and 'z' + } + return new PlaceholderType(name, true); + } + + + /** + * True if this placeholder is auto-generated, false if it is user-generated. + */ + public boolean isGenerated() { + return IsGenerated; + } + + public void setVariance(int v) { + variance = v; + } + + public int getVariance() { + return variance; + } + + public void reversVariance() { + if (variance == 1) { + setVariance(-1); + } else { + if (variance == -1) { + setVariance(1); + }} + } + + public Boolean isWildcardable() { + return wildcardable; + } + public void disableWildcardtable() { + wildcardable = false; + } + + public void enableWildcardtable() { + wildcardable = true; + } + + public void setWildcardtable(Boolean wildcardable) { + this.wildcardable = wildcardable; + } + + public Boolean isInnerType() { + return innerType; + } + + public void setInnerType(Boolean innerType) { + this.innerType = innerType; + } + + @Override + Set smArg(IFiniteClosure fc, Set fBounded) { + return fc.smArg(this, fBounded); + } + + @Override + Set grArg(IFiniteClosure fc, Set fBounded) { + return fc.grArg(this, fBounded); + } + + @Override + public UnifyType setTypeParams(TypeParams newTp) { + return this; // Placeholders never have params. + } + + @Override + public int hashCode() { + return typeName.hashCode(); + } + + @Override + UnifyType apply(Unifier unif) { + if(unif.hasSubstitute(this)) { + UnifyType ret = unif.getSubstitute(this); + //PL 2018-05-17 Auskommentierung muesste korrekt sein, + //bereits in JavaTXComplier Variancen gesetzt werden. + //ret.accept(new distributeVariance(), this.getVariance()); + return ret; + } + return this; + } + + @Override + public boolean equals(Object obj) { + if(!(obj instanceof PlaceholderType)) + return false; + + return ((PlaceholderType) obj).getName().equals(typeName); + } + + + @Override + public Collection getInvolvedPlaceholderTypes() { + ArrayList ret = new ArrayList<>(); + ret.add(this); + return ret; + } +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java index 4627dc30c..62465b1a2 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java @@ -1,100 +1,100 @@ -package de.dhbwstuttgart.typeinference.unify.model; - -import java.util.HashMap; -import java.util.Set; - -import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; -import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; - -/** - * A reference type e.q. Integer or List. - * @author Florian Steurer - * - */ -public class ReferenceType extends UnifyType { - - /** - * The buffered hashCode - */ - private final int hashCode; - - /** - * gibt an, ob der ReferenceType eine generische Typvariable ist - */ - private final boolean genericTypeVar; - - - public UnifyType accept(UnifyTypeVisitor visitor, T ht) { - return visitor.visit(this, ht); - } - - public ReferenceType(String name, Boolean genericTypeVar) { - super(name, new TypeParams()); - hashCode = 31 + 17 * typeName.hashCode() + 17 * typeParams.hashCode(); - this.genericTypeVar = genericTypeVar; - } - - public ReferenceType(String name, UnifyType... params) { - super(name, new TypeParams(params)); - hashCode = 31 + 17 * typeName.hashCode() + 17 * typeParams.hashCode(); - genericTypeVar = false; - } - - public ReferenceType(String name, TypeParams params) { - super(name, params); - hashCode = 31 + 17 * typeName.hashCode() + 17 * typeParams.hashCode(); - genericTypeVar = false; - } - - public boolean isGenTypeVar () { - return genericTypeVar; - } - - @Override - Set smArg(IFiniteClosure fc, Set fBounded) { - return fc.smArg(this, fBounded); - } - - @Override - Set grArg(IFiniteClosure fc, Set fBounded) { - return fc.grArg(this, fBounded); - } - - @Override - UnifyType apply(Unifier unif) { - TypeParams newParams = typeParams.apply(unif); - - if(newParams.hashCode() == typeParams.hashCode() && newParams.equals(typeParams)) - return this; - - return new ReferenceType(typeName, newParams); - } - - @Override - public UnifyType setTypeParams(TypeParams newTp) { - if(newTp.hashCode() == typeParams.hashCode() && newTp.equals(typeParams)) - return this; // reduced the amount of objects created - return new ReferenceType(typeName, newTp); - } - - @Override - public int hashCode() { - return hashCode; - } - - @Override - public boolean equals(Object obj) { - if(!(obj instanceof ReferenceType)) - return false; - - if(obj.hashCode() != this.hashCode()) - return false; - - ReferenceType other = (ReferenceType) obj; - - if(!other.getName().equals(typeName)) - return false; - - return other.getTypeParams().equals(typeParams); - } -} +package de.dhbwstuttgart.typeinference.unify.model; + +import java.util.HashMap; +import java.util.Set; + +import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; + +/** + * A reference type e.q. Integer or List. + * @author Florian Steurer + * + */ +public class ReferenceType extends UnifyType { + + /** + * The buffered hashCode + */ + private final int hashCode; + + /** + * gibt an, ob der ReferenceType eine generische Typvariable ist + */ + private final boolean genericTypeVar; + + + public UnifyType accept(UnifyTypeVisitor visitor, T ht) { + return visitor.visit(this, ht); + } + + public ReferenceType(String name, Boolean genericTypeVar) { + super(name, new TypeParams()); + hashCode = 31 + 17 * typeName.hashCode() + 17 * typeParams.hashCode(); + this.genericTypeVar = genericTypeVar; + } + + public ReferenceType(String name, UnifyType... params) { + super(name, new TypeParams(params)); + hashCode = 31 + 17 * typeName.hashCode() + 17 * typeParams.hashCode(); + genericTypeVar = false; + } + + public ReferenceType(String name, TypeParams params) { + super(name, params); + hashCode = 31 + 17 * typeName.hashCode() + 17 * typeParams.hashCode(); + genericTypeVar = false; + } + + public boolean isGenTypeVar () { + return genericTypeVar; + } + + @Override + Set smArg(IFiniteClosure fc, Set fBounded) { + return fc.smArg(this, fBounded); + } + + @Override + Set grArg(IFiniteClosure fc, Set fBounded) { + return fc.grArg(this, fBounded); + } + + @Override + UnifyType apply(Unifier unif) { + TypeParams newParams = typeParams.apply(unif); + + if(newParams.hashCode() == typeParams.hashCode() && newParams.equals(typeParams)) + return this; + + return new ReferenceType(typeName, newParams); + } + + @Override + public UnifyType setTypeParams(TypeParams newTp) { + if(newTp.hashCode() == typeParams.hashCode() && newTp.equals(typeParams)) + return this; // reduced the amount of objects created + return new ReferenceType(typeName, newTp); + } + + @Override + public int hashCode() { + return hashCode; + } + + @Override + public boolean equals(Object obj) { + if(!(obj instanceof ReferenceType)) + return false; + + if(obj.hashCode() != this.hashCode()) + return false; + + ReferenceType other = (ReferenceType) obj; + + if(!other.getName().equals(typeName)) + return false; + + return other.getTypeParams().equals(typeParams); + } +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/SuperType.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/SuperType.java index fa5199959..50b8dcf7b 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/SuperType.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/SuperType.java @@ -1,88 +1,88 @@ -package de.dhbwstuttgart.typeinference.unify.model; - -import java.util.HashMap; -import java.util.Set; - -import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; -import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; - -/** - * A super wildcard type e.g. ? super Integer. - * @author Florian Steurer - */ -public final class SuperType extends WildcardType { - - public UnifyType accept(UnifyTypeVisitor visitor, T ht) { - return visitor.visit(this, ht); - } - - /** - * Creates a new instance "? extends superedType" - * @param superedType The type that is supered e.g. Integer in "? super Integer" - */ - public SuperType(UnifyType superedType) { - super("? super " + superedType.getName(), superedType); - } - - /** - * The type that is supered e.g. Integer in "? super Integer" - */ - public UnifyType getSuperedType() { - return wildcardedType; - } - - @Override - public String toString() { - return "? super " + wildcardedType; - } - - /** - * Sets the type parameters of the wildcarded type and returns a new supertype that supers that type. - */ - @Override - public UnifyType setTypeParams(TypeParams newTp) { - UnifyType newType = wildcardedType.setTypeParams(newTp); - if(newType == wildcardedType) - return this; // Reduced the amount of objects created - return new SuperType(wildcardedType.setTypeParams(newTp)); - } - - @Override - Set smArg(IFiniteClosure fc, Set fBounded) { - return fc.smArg(this, fBounded); - } - - @Override - Set grArg(IFiniteClosure fc, Set fBounded) { - return fc.grArg(this, fBounded); - } - - @Override - UnifyType apply(Unifier unif) { - UnifyType newType = wildcardedType.apply(unif); - if(newType.hashCode() == wildcardedType.hashCode() && newType.equals(wildcardedType)) - return this; // Reduced the amount of objects created - return new SuperType(newType); - } - - @Override - public int hashCode() { - /* - * It is important that the prime that is added is different to the prime added in hashCode() of ExtendsType. - * Otherwise ? extends T and ? super T have the same hashCode() for every Type T. - */ - return wildcardedType.hashCode() + 3917; - } - - @Override - public boolean equals(Object obj) { - if(!(obj instanceof SuperType)) - return false; - - if(obj.hashCode() != this.hashCode()) - return false; - - SuperType other = (SuperType) obj; - return other.getSuperedType().equals(wildcardedType); - } -} +package de.dhbwstuttgart.typeinference.unify.model; + +import java.util.HashMap; +import java.util.Set; + +import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; + +/** + * A super wildcard type e.g. ? super Integer. + * @author Florian Steurer + */ +public final class SuperType extends WildcardType { + + public UnifyType accept(UnifyTypeVisitor visitor, T ht) { + return visitor.visit(this, ht); + } + + /** + * Creates a new instance "? extends superedType" + * @param superedType The type that is supered e.g. Integer in "? super Integer" + */ + public SuperType(UnifyType superedType) { + super("? super " + superedType.getName(), superedType); + } + + /** + * The type that is supered e.g. Integer in "? super Integer" + */ + public UnifyType getSuperedType() { + return wildcardedType; + } + + @Override + public String toString() { + return "? super " + wildcardedType; + } + + /** + * Sets the type parameters of the wildcarded type and returns a new supertype that supers that type. + */ + @Override + public UnifyType setTypeParams(TypeParams newTp) { + UnifyType newType = wildcardedType.setTypeParams(newTp); + if(newType == wildcardedType) + return this; // Reduced the amount of objects created + return new SuperType(wildcardedType.setTypeParams(newTp)); + } + + @Override + Set smArg(IFiniteClosure fc, Set fBounded) { + return fc.smArg(this, fBounded); + } + + @Override + Set grArg(IFiniteClosure fc, Set fBounded) { + return fc.grArg(this, fBounded); + } + + @Override + UnifyType apply(Unifier unif) { + UnifyType newType = wildcardedType.apply(unif); + if(newType.hashCode() == wildcardedType.hashCode() && newType.equals(wildcardedType)) + return this; // Reduced the amount of objects created + return new SuperType(newType); + } + + @Override + public int hashCode() { + /* + * It is important that the prime that is added is different to the prime added in hashCode() of ExtendsType. + * Otherwise ? extends T and ? super T have the same hashCode() for every Type T. + */ + return wildcardedType.hashCode() + 3917; + } + + @Override + public boolean equals(Object obj) { + if(!(obj instanceof SuperType)) + return false; + + if(obj.hashCode() != this.hashCode()) + return false; + + SuperType other = (SuperType) obj; + return other.getSuperedType().equals(wildcardedType); + } +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/TypeParams.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/TypeParams.java index 973a2785c..f70cccb06 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/TypeParams.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/TypeParams.java @@ -1,191 +1,191 @@ -package de.dhbwstuttgart.typeinference.unify.model; - -import java.util.*; - - -/** - * The generic or non-generic parameters of a type e.g. for List - * @author Florian Steurer - */ -public final class TypeParams implements Iterable{ - /** - * The array which backs the type parameters. - */ - private final UnifyType[] typeParams; - - /** - * Hashcode calculation is expensive and must be cached. - */ - private final int hashCode; - - /** - * Creates a new set of type parameters. - * @param types The type parameters. - */ - public TypeParams(List types){ - typeParams = new UnifyType[types.size()]; - for(int i=0;i x instanceof PlaceholderType); - } - - /** - * Returns the number of the type parameters in this object. - * @return number of type parameters, always positive (including 0). - */ - public int size() { - return typeParams.length; - } - - /** - * Returns true if this object has size() of zero, false otherwise. - */ - public boolean empty() { - return typeParams.length == 0; - } - - /** - * Applies a unifier to every parameter in this object. - * @param unif The applied unifier. - * @return A new type parameter object, where the unifier was applied to every parameter. - */ - public TypeParams apply(Unifier unif) { - UnifyType[] newParams = new UnifyType[typeParams.length]; - - // If true, a type was modified and a new typeparams object has to be created. - // Otherwise it is enough to return this object, since it is immutable - // This reduced the needed TypeParams-Instances for the lambda14-Test from - // 130.000 to 30.000 without a decrease in speed. - boolean isNew = false; - - for(int i = 0; i < typeParams.length; i++) { - UnifyType newType = typeParams[i].apply(unif); - newParams[i] = newType; - if(!isNew && (newType.hashCode() != typeParams[i].hashCode() || !newType.equals(typeParams[i]))) - isNew = true; - } - - if(!isNew) - return this; - return new TypeParams(newParams); - } - - /** - * True if the PlaceholderType t is a parameter of this object, or if any parameter - * contains t (arbitrary depth of recursion), false otherwise. - */ - public boolean occurs(PlaceholderType t) { - for(UnifyType p : typeParams) - if(p instanceof PlaceholderType) {//PL 2018-01-31 dangeling else Problem { ... } eingefuegt. - if(p.equals(t)) - return true; - } - else { - if(p.getTypeParams().occurs(t)) - return true; } - return false; - } - - /** - * Returns the i-th parameter of this object. - */ - public UnifyType get(int i) { - return typeParams[i]; - } - - /** - * Returns the parameters of this object. - * PL 2018-03-17 - */ - public UnifyType[] get() { - return typeParams; - } - - /** - * Sets the the type t as the i-th parameter and returns a new object - * that equals this object, except for the i-th type. - */ - public TypeParams set(UnifyType t, int idx) { - // Reduce the creation of new objects for less memory - // Reduced the needed instances of TypeParams in the lambda14-Test from - // 150.000 to 130.000 - if(t.hashCode() == typeParams[idx].hashCode() && t.equals(typeParams[idx])) - return this; - UnifyType[] newparams = Arrays.copyOf(typeParams, typeParams.length); - newparams[idx] = t; - return new TypeParams(newparams); - } - - @Override - public Iterator iterator() { - return Arrays.stream(typeParams).iterator(); - } - - @Override - public int hashCode() { - return hashCode; - } - - @Override - public boolean equals(Object obj) { - if(!(obj instanceof TypeParams)) - return false; - - if(obj.hashCode() != this.hashCode()) - return false; - - TypeParams other = (TypeParams) obj; - - if(other.size() != this.size()) - return false; - - for(int i = 0; i < this.size(); i++){ - //if(this.get(i) == null) - //System.out.print("s"); - } - for(int i = 0; i < this.size(); i++) - if(!(this.get(i).equals(other.get(i)))) - return false; - - return true; - } - - @Override - public String toString() { - String res = ""; - for(UnifyType t : typeParams) - res += t + ","; - return "<" + res.substring(0, res.length()-1) + ">"; - } - - public Collection getInvolvedPlaceholderTypes() { - ArrayList ret = new ArrayList<>(); - for(UnifyType t : typeParams){ - ret.addAll(t.getInvolvedPlaceholderTypes()); - } - return ret; - } -} - +package de.dhbwstuttgart.typeinference.unify.model; + +import java.util.*; + + +/** + * The generic or non-generic parameters of a type e.g. for List + * @author Florian Steurer + */ +public final class TypeParams implements Iterable{ + /** + * The array which backs the type parameters. + */ + private final UnifyType[] typeParams; + + /** + * Hashcode calculation is expensive and must be cached. + */ + private final int hashCode; + + /** + * Creates a new set of type parameters. + * @param types The type parameters. + */ + public TypeParams(List types){ + typeParams = new UnifyType[types.size()]; + for(int i=0;i x instanceof PlaceholderType); + } + + /** + * Returns the number of the type parameters in this object. + * @return number of type parameters, always positive (including 0). + */ + public int size() { + return typeParams.length; + } + + /** + * Returns true if this object has size() of zero, false otherwise. + */ + public boolean empty() { + return typeParams.length == 0; + } + + /** + * Applies a unifier to every parameter in this object. + * @param unif The applied unifier. + * @return A new type parameter object, where the unifier was applied to every parameter. + */ + public TypeParams apply(Unifier unif) { + UnifyType[] newParams = new UnifyType[typeParams.length]; + + // If true, a type was modified and a new typeparams object has to be created. + // Otherwise it is enough to return this object, since it is immutable + // This reduced the needed TypeParams-Instances for the lambda14-Test from + // 130.000 to 30.000 without a decrease in speed. + boolean isNew = false; + + for(int i = 0; i < typeParams.length; i++) { + UnifyType newType = typeParams[i].apply(unif); + newParams[i] = newType; + if(!isNew && (newType.hashCode() != typeParams[i].hashCode() || !newType.equals(typeParams[i]))) + isNew = true; + } + + if(!isNew) + return this; + return new TypeParams(newParams); + } + + /** + * True if the PlaceholderType t is a parameter of this object, or if any parameter + * contains t (arbitrary depth of recursion), false otherwise. + */ + public boolean occurs(PlaceholderType t) { + for(UnifyType p : typeParams) + if(p instanceof PlaceholderType) {//PL 2018-01-31 dangeling else Problem { ... } eingefuegt. + if(p.equals(t)) + return true; + } + else { + if(p.getTypeParams().occurs(t)) + return true; } + return false; + } + + /** + * Returns the i-th parameter of this object. + */ + public UnifyType get(int i) { + return typeParams[i]; + } + + /** + * Returns the parameters of this object. + * PL 2018-03-17 + */ + public UnifyType[] get() { + return typeParams; + } + + /** + * Sets the the type t as the i-th parameter and returns a new object + * that equals this object, except for the i-th type. + */ + public TypeParams set(UnifyType t, int idx) { + // Reduce the creation of new objects for less memory + // Reduced the needed instances of TypeParams in the lambda14-Test from + // 150.000 to 130.000 + if(t.hashCode() == typeParams[idx].hashCode() && t.equals(typeParams[idx])) + return this; + UnifyType[] newparams = Arrays.copyOf(typeParams, typeParams.length); + newparams[idx] = t; + return new TypeParams(newparams); + } + + @Override + public Iterator iterator() { + return Arrays.stream(typeParams).iterator(); + } + + @Override + public int hashCode() { + return hashCode; + } + + @Override + public boolean equals(Object obj) { + if(!(obj instanceof TypeParams)) + return false; + + if(obj.hashCode() != this.hashCode()) + return false; + + TypeParams other = (TypeParams) obj; + + if(other.size() != this.size()) + return false; + + for(int i = 0; i < this.size(); i++){ + //if(this.get(i) == null) + //System.out.print("s"); + } + for(int i = 0; i < this.size(); i++) + if(!(this.get(i).equals(other.get(i)))) + return false; + + return true; + } + + @Override + public String toString() { + String res = ""; + for(UnifyType t : typeParams) + res += t + ","; + return "<" + res.substring(0, res.length()-1) + ">"; + } + + public Collection getInvolvedPlaceholderTypes() { + ArrayList ret = new ArrayList<>(); + for(UnifyType t : typeParams){ + ret.addAll(t.getInvolvedPlaceholderTypes()); + } + return ret; + } +} + diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/Unifier.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/Unifier.java index f2bc52774..8cfac643e 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/Unifier.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/Unifier.java @@ -1,189 +1,189 @@ -package de.dhbwstuttgart.typeinference.unify.model; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.Set; -import java.util.function.Function; - -/** - * A set of substitutions (s -> t) that is an applicable function to types and pairs. - * @author Florian Steurer - */ -public class Unifier implements Function, Iterable> { - - /** - * The set of substitutions that unify a type-term - */ - private HashMap substitutions = new HashMap<>(); +package de.dhbwstuttgart.typeinference.unify.model; - /** - * Creates a new instance with a single substitution (source -> target). - * @param The type that is replaced - * @param The type that replaces +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.Set; +import java.util.function.Function; + +/** + * A set of substitutions (s -> t) that is an applicable function to types and pairs. + * @author Florian Steurer + */ +public class Unifier implements Function, Iterable> { + + /** + * The set of substitutions that unify a type-term + */ + private HashMap substitutions = new HashMap<>(); + + /** + * Creates a new instance with a single substitution (source -> target). + * @param The type that is replaced + * @param The type that replaces */ public Unifier(PlaceholderType source, UnifyType target) { - substitutions.put(source, target); - } - - /** - * Identity function as an "unifier". - */ - protected Unifier() { - - } - - /** - * Creates an unifier that is the identity function (thus has no substitutions). + substitutions.put(source, target); + } + + /** + * Identity function as an "unifier". + */ + protected Unifier() { + + } + + /** + * Creates an unifier that is the identity function (thus has no substitutions). + */ + public static Unifier identity() { + return new Unifier(); + } + + /** + * Adds a substitution to the unifier from (source -> target) + * @param The type that is replaced + * @param The type that replaces */ - public static Unifier identity() { - return new Unifier(); - } - - /** - * Adds a substitution to the unifier from (source -> target) - * @param The type that is replaced - * @param The type that replaces - */ public void add(PlaceholderType source, UnifyType target) { - Unifier tempU = new Unifier(source, target); - // Every new substitution must be applied to previously added substitutions - // otherwise the unifier needs to be applied multiple times to unify two terms - for(PlaceholderType pt : substitutions.keySet()) - substitutions.put(pt, substitutions.get(pt).apply(tempU)); - substitutions.put(source, target); - } - - @Override - public UnifyType apply(UnifyType t) { - return t.apply(this); - } - - /** - * Applies the unifier to the two terms of the pair. - * @return A new pair where the left and right-hand side are applied - */ - public UnifyPair apply(UnifyPair p) { - UnifyType newLhs = this.apply(p.getLhsType()); - UnifyType newRhs = this.apply(p.getRhsType()); - return new UnifyPair(newLhs, newRhs, p.getPairOp()); - } - - /** - * Applies the unifier to the two terms of the pair. - * works only for single subsitution - * @return A new pair where the left and right-hand side are applied - */ - public UnifyPair apply(UnifyPair thisAsPair, UnifyPair p) { - UnifyType newLhs = this.apply(p.getLhsType()); - UnifyType newRhs = this.apply(p.getRhsType()); - //Varianceweitergabe wird nicht benoetigt. - //PlaceholderType lhsph = (PlaceholderType)thisAsPair.getLhsType(); - //if (lhsph.getVariance() != 0) { - // if (p.getLhsType().equals(lhsph)) { - // if (p.getRhsType() instanceof PlaceholderType) { - // ((PlaceholderType)p.getRhsType()).setVariance(lhsph.getVariance()); - // } - // } - // if (p.getRhsType().equals(lhsph)) { - // if (p.getLhsType() instanceof PlaceholderType) { - // ((PlaceholderType)p.getLhsType()).setVariance(lhsph.getVariance()); - // } - // } - //} - if (!(p.getLhsType().equals(newLhs)) || !(p.getRhsType().equals(newRhs))) {//Die Anwendung von this hat was veraendert PL 2018-04-01 - Set suniUnifyPair = new HashSet<>(); - suniUnifyPair.addAll(thisAsPair.getAllSubstitutions()); - suniUnifyPair.add(thisAsPair); - if (p.getLhsType() instanceof PlaceholderType //&& newLhs instanceof PlaceholderType entfernt PL 2018-04-13 - && p.getPairOp() == PairOperator.EQUALSDOT) { - suniUnifyPair.add(p); //p koennte auch subsitution sein - } - return new UnifyPair(newLhs, newRhs, p.getPairOp(), suniUnifyPair, p); - } - return new UnifyPair(newLhs, newRhs, p.getPairOp(), p.getSubstitution(), p.getBasePair(), p.getfBounded()); - } - - /** - * Applies the unifier to the left terms of the pair. - * @return A new pair where the left and right-hand side are applied - */ - public UnifyPair applyleft(UnifyPair p) { - return new UnifyPair(this.apply(p.getLhsType()), p.getRhsType(), p.getPairOp()); - } - - /** - * True if the typevariable t will be substituted if the unifier is applied. - * false otherwise. - */ - public boolean hasSubstitute(PlaceholderType t) { - return substitutions.containsKey(t); - } - - /** - * Returns the type that will replace the typevariable t if the unifier is applied. - */ - public UnifyType getSubstitute(PlaceholderType t) { - return substitutions.get(t); - } - - /** - * The number of substitutions in the unifier. If zero, this is the identity function. - */ - public int size() { - return substitutions.size(); - } - - /** - * Garantuees that if there is a substitutions (a -> b) in this unifier, - * a is not an element of the targetParams. Substitutions that do not - * satisfy this condition, are swapped. - */ - public void swapPlaceholderSubstitutions(Iterable targetParams) { - for(UnifyType tph : targetParams) { - if(!(tph instanceof PlaceholderType)) - continue; - // Swap a substitutions (a -> b) if a is an element of the target params. - if(substitutions.containsKey(tph)) { - if((substitutions.get(tph) instanceof PlaceholderType)) { - PlaceholderType newLhs = (PlaceholderType) substitutions.get(tph); - substitutions.remove(tph); - substitutions.put(newLhs, tph); - } - } - } - } - - public void swapPlaceholderSubstitutionsReverse(Iterable sourceParams) { - for(UnifyType tph : sourceParams) { - if(!(tph instanceof PlaceholderType)) - continue; - if(substitutions.containsValue(tph)) { - UnifyType key = substitutions.values().stream().filter(x -> x.equals(tph)).findAny().get(); - if(key instanceof PlaceholderType) { - PlaceholderType newLhs = (PlaceholderType) tph; - substitutions.remove(key); - substitutions.put(newLhs, key); - } - } - } - } - - @Override - public String toString() { - String result = "{ "; - for(Entry entry : substitutions.entrySet()) - result += "(" + entry.getKey() + " -> " + entry.getValue() + "), "; - if(!substitutions.isEmpty()) - result = result.substring(0, result.length()-2); - result += " }"; - return result; - } - - @Override - public Iterator> iterator() { - return substitutions.entrySet().iterator(); - } -} - + Unifier tempU = new Unifier(source, target); + // Every new substitution must be applied to previously added substitutions + // otherwise the unifier needs to be applied multiple times to unify two terms + for(PlaceholderType pt : substitutions.keySet()) + substitutions.put(pt, substitutions.get(pt).apply(tempU)); + substitutions.put(source, target); + } + + @Override + public UnifyType apply(UnifyType t) { + return t.apply(this); + } + + /** + * Applies the unifier to the two terms of the pair. + * @return A new pair where the left and right-hand side are applied + */ + public UnifyPair apply(UnifyPair p) { + UnifyType newLhs = this.apply(p.getLhsType()); + UnifyType newRhs = this.apply(p.getRhsType()); + return new UnifyPair(newLhs, newRhs, p.getPairOp()); + } + + /** + * Applies the unifier to the two terms of the pair. + * works only for single subsitution + * @return A new pair where the left and right-hand side are applied + */ + public UnifyPair apply(UnifyPair thisAsPair, UnifyPair p) { + UnifyType newLhs = this.apply(p.getLhsType()); + UnifyType newRhs = this.apply(p.getRhsType()); + //Varianceweitergabe wird nicht benoetigt. + //PlaceholderType lhsph = (PlaceholderType)thisAsPair.getLhsType(); + //if (lhsph.getVariance() != 0) { + // if (p.getLhsType().equals(lhsph)) { + // if (p.getRhsType() instanceof PlaceholderType) { + // ((PlaceholderType)p.getRhsType()).setVariance(lhsph.getVariance()); + // } + // } + // if (p.getRhsType().equals(lhsph)) { + // if (p.getLhsType() instanceof PlaceholderType) { + // ((PlaceholderType)p.getLhsType()).setVariance(lhsph.getVariance()); + // } + // } + //} + if (!(p.getLhsType().equals(newLhs)) || !(p.getRhsType().equals(newRhs))) {//Die Anwendung von this hat was veraendert PL 2018-04-01 + Set suniUnifyPair = new HashSet<>(); + suniUnifyPair.addAll(thisAsPair.getAllSubstitutions()); + suniUnifyPair.add(thisAsPair); + if (p.getLhsType() instanceof PlaceholderType //&& newLhs instanceof PlaceholderType entfernt PL 2018-04-13 + && p.getPairOp() == PairOperator.EQUALSDOT) { + suniUnifyPair.add(p); //p koennte auch subsitution sein + } + return new UnifyPair(newLhs, newRhs, p.getPairOp(), suniUnifyPair, p); + } + return new UnifyPair(newLhs, newRhs, p.getPairOp(), p.getSubstitution(), p.getBasePair(), p.getfBounded()); + } + + /** + * Applies the unifier to the left terms of the pair. + * @return A new pair where the left and right-hand side are applied + */ + public UnifyPair applyleft(UnifyPair p) { + return new UnifyPair(this.apply(p.getLhsType()), p.getRhsType(), p.getPairOp()); + } + + /** + * True if the typevariable t will be substituted if the unifier is applied. + * false otherwise. + */ + public boolean hasSubstitute(PlaceholderType t) { + return substitutions.containsKey(t); + } + + /** + * Returns the type that will replace the typevariable t if the unifier is applied. + */ + public UnifyType getSubstitute(PlaceholderType t) { + return substitutions.get(t); + } + + /** + * The number of substitutions in the unifier. If zero, this is the identity function. + */ + public int size() { + return substitutions.size(); + } + + /** + * Garantuees that if there is a substitutions (a -> b) in this unifier, + * a is not an element of the targetParams. Substitutions that do not + * satisfy this condition, are swapped. + */ + public void swapPlaceholderSubstitutions(Iterable targetParams) { + for(UnifyType tph : targetParams) { + if(!(tph instanceof PlaceholderType)) + continue; + // Swap a substitutions (a -> b) if a is an element of the target params. + if(substitutions.containsKey(tph)) { + if((substitutions.get(tph) instanceof PlaceholderType)) { + PlaceholderType newLhs = (PlaceholderType) substitutions.get(tph); + substitutions.remove(tph); + substitutions.put(newLhs, tph); + } + } + } + } + + public void swapPlaceholderSubstitutionsReverse(Iterable sourceParams) { + for(UnifyType tph : sourceParams) { + if(!(tph instanceof PlaceholderType)) + continue; + if(substitutions.containsValue(tph)) { + UnifyType key = substitutions.values().stream().filter(x -> x.equals(tph)).findAny().get(); + if(key instanceof PlaceholderType) { + PlaceholderType newLhs = (PlaceholderType) tph; + substitutions.remove(key); + substitutions.put(newLhs, key); + } + } + } + } + + @Override + public String toString() { + String result = "{ "; + for(Entry entry : substitutions.entrySet()) + result += "(" + entry.getKey() + " -> " + entry.getValue() + "), "; + if(!substitutions.isEmpty()) + result = result.substring(0, result.length()-2); + result += " }"; + return result; + } + + @Override + public Iterator> iterator() { + return substitutions.entrySet().iterator(); + } +} + diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index 222e7308e..aafecf15a 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -1,256 +1,256 @@ -package de.dhbwstuttgart.typeinference.unify.model; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.Set; - - -/** - * A pair which contains two types and an operator, e.q. (Integer <. a). - * @author Florian Steurer - */ -public class UnifyPair { - - /** - * The type on the left hand side of the pair. - */ - private final UnifyType lhs; - - /** - * The type on the right hand side of the pair. - */ - private final UnifyType rhs; - - /** - * The operator that determines the relation between the left and right hand side type. - */ - private PairOperator pairOp; - - /** wieder loesecn wird nicht mehr benoetigt PL 2018-03-31 - * variance shows the variance of the pair - * -1: contravariant - * 1 covariant - * 0 invariant - * PL 2018-03-21 - */ - private byte variance = 0; - - private boolean undefinedPair = false; - - /** - * Unifier/substitute that generated this pair - * PL 2018-03-15 - */ - private Set substitution; - - /** - * Base on which the the unifier is applied - * PL 2018-03-15 - */ - private UnifyPair basePair; - - /** - * For pairs a <. Theta generated in the rule reduceTphSup - * to store the f-Bouned Elements to avoid endless recursion - * PL 2018-03-15 - */ - private Set fBounded = new HashSet<>(); - - private final int hashCode; - - /** - * Creates a new instance of the pair. - * @param lhs The type on the left hand side of the pair. - * @param rhs The type on the right hand side of the pair. - * @param op The operator that determines the relation between the left and right hand side type. - */ - public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op) { - this.lhs = lhs; - this.rhs = rhs; - pairOp = op; - substitution = new HashSet<>(); - - // Caching hashcode - hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode(); - } - - public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op, Set uni, UnifyPair base) { - this.lhs = lhs; - this.rhs = rhs; - pairOp = op; - substitution = uni; - basePair = base; - this.variance = variance; - - - // Caching hashcode - hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode(); - } - - public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op, Set uni, UnifyPair base, Set fBounded) { - this(lhs, rhs, op, uni, base); - - this.fBounded = fBounded; - } - - /** - * Returns the type on the left hand side of the pair. - */ - public UnifyType getLhsType() { - return lhs; - } - - /** - * Returns the type on the right hand side of the pair. - */ - public UnifyType getRhsType() { - return rhs; - } - - /** - * Returns the operator that determines the relation between the left and right hand side type. - */ - public PairOperator getPairOp() { - return pairOp; - } - - public void setPairOp(PairOperator po) { - pairOp = po; - } - - public void addSubstitutions(Set sup) { - substitution.addAll(sup); - } - - public byte getVariance() { - return variance; - } - - public void setVariance(byte v) { - variance = v; - } - - public void setUndefinedPair() { - undefinedPair = true; - } - public Set getSubstitution() { - return new HashSet<>(substitution); - } - - public UnifyPair getBasePair() { - return basePair; - } - public boolean isUndefinedPair() { - return undefinedPair; - } - - public Set getAllSubstitutions () { - Set ret = new HashSet<>(); - ret.addAll(new ArrayList<>(getSubstitution())); - if (basePair != null) { - ret.addAll(new ArrayList<>(basePair.getAllSubstitutions())); - } - return ret; - } - - public Set getAllBases () { - Set ret = new HashSet<>(); - if (basePair != null) { - ret.add(getBasePair()); - ret.addAll(basePair.getAllBases()); - } - return ret; - } - - public UnifyPair getGroundBasePair () { - if (basePair == null) { - return this; - } - if (basePair.getBasePair() == null) { - return basePair; - } - else { - return basePair.getGroundBasePair(); - } - } - - /** - * wenn in einem Paar bestehend aus 2 Typvariablen eine nicht wildcardtable ist, - * so beide auf nicht wildcardtable setzen - */ - public void disableCondWildcards() { - if (lhs instanceof PlaceholderType && rhs instanceof PlaceholderType - && (!((PlaceholderType)lhs).isWildcardable() || !((PlaceholderType)rhs).isWildcardable())) - { - ((PlaceholderType)lhs).disableWildcardtable(); - ((PlaceholderType)rhs).disableWildcardtable(); - } - - } - - public Boolean wrongWildcard() { - return lhs.wrongWildcard() || rhs.wrongWildcard(); - } - - public Set getfBounded() { - return this.fBounded; - } - - @Override - public boolean equals(Object obj) { - if(!(obj instanceof UnifyPair)) - return false; - - if(obj.hashCode() != this.hashCode()) - return false; - - UnifyPair other = (UnifyPair) obj; - - if (isUndefinedPair()) { - if (other.getBasePair() != basePair || (other.getBasePair() == null && basePair == null)) { - return false; - } - if (!other.getBasePair().equals(basePair) || - !other.getAllSubstitutions().equals(getAllSubstitutions())) { - return false; - } - } - - return other.getPairOp() == pairOp - && other.getLhsType().equals(lhs) - && other.getRhsType().equals(rhs); - } - - @Override - public int hashCode() { - return hashCode; - } - - @Override - public String toString() { - String ret = ""; - if (lhs instanceof PlaceholderType) { - ret = new Integer(((PlaceholderType)lhs).getVariance()).toString() + " " + ((PlaceholderType)lhs).isInnerType() - + " " + ((PlaceholderType)lhs).isWildcardable(); - } - if (rhs instanceof PlaceholderType) { - ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString() + " " + ((PlaceholderType)rhs).isInnerType() - + " " + ((PlaceholderType)rhs).isWildcardable(); - } - return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ")"; //+ ", [" + getfBounded().toString()+ "])"; - } - - /* - public List getInvolvedPlaceholderTypes() { - ArrayList ret = new ArrayList<>(); - ret.addAll(lhs.getInvolvedPlaceholderTypes()); - ret.addAll(rhs.getInvolvedPlaceholderTypes()); - return ret; - } - */ -} - - +package de.dhbwstuttgart.typeinference.unify.model; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; + + +/** + * A pair which contains two types and an operator, e.q. (Integer <. a). + * @author Florian Steurer + */ +public class UnifyPair { + + /** + * The type on the left hand side of the pair. + */ + private final UnifyType lhs; + + /** + * The type on the right hand side of the pair. + */ + private final UnifyType rhs; + + /** + * The operator that determines the relation between the left and right hand side type. + */ + private PairOperator pairOp; + + /** wieder loesecn wird nicht mehr benoetigt PL 2018-03-31 + * variance shows the variance of the pair + * -1: contravariant + * 1 covariant + * 0 invariant + * PL 2018-03-21 + */ + private byte variance = 0; + + private boolean undefinedPair = false; + + /** + * Unifier/substitute that generated this pair + * PL 2018-03-15 + */ + private Set substitution; + + /** + * Base on which the the unifier is applied + * PL 2018-03-15 + */ + private UnifyPair basePair; + + /** + * For pairs a <. Theta generated in the rule reduceTphSup + * to store the f-Bouned Elements to avoid endless recursion + * PL 2018-03-15 + */ + private Set fBounded = new HashSet<>(); + + private final int hashCode; + + /** + * Creates a new instance of the pair. + * @param lhs The type on the left hand side of the pair. + * @param rhs The type on the right hand side of the pair. + * @param op The operator that determines the relation between the left and right hand side type. + */ + public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op) { + this.lhs = lhs; + this.rhs = rhs; + pairOp = op; + substitution = new HashSet<>(); + + // Caching hashcode + hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode(); + } + + public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op, Set uni, UnifyPair base) { + this.lhs = lhs; + this.rhs = rhs; + pairOp = op; + substitution = uni; + basePair = base; + this.variance = variance; + + + // Caching hashcode + hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode(); + } + + public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op, Set uni, UnifyPair base, Set fBounded) { + this(lhs, rhs, op, uni, base); + + this.fBounded = fBounded; + } + + /** + * Returns the type on the left hand side of the pair. + */ + public UnifyType getLhsType() { + return lhs; + } + + /** + * Returns the type on the right hand side of the pair. + */ + public UnifyType getRhsType() { + return rhs; + } + + /** + * Returns the operator that determines the relation between the left and right hand side type. + */ + public PairOperator getPairOp() { + return pairOp; + } + + public void setPairOp(PairOperator po) { + pairOp = po; + } + + public void addSubstitutions(Set sup) { + substitution.addAll(sup); + } + + public byte getVariance() { + return variance; + } + + public void setVariance(byte v) { + variance = v; + } + + public void setUndefinedPair() { + undefinedPair = true; + } + public Set getSubstitution() { + return new HashSet<>(substitution); + } + + public UnifyPair getBasePair() { + return basePair; + } + public boolean isUndefinedPair() { + return undefinedPair; + } + + public Set getAllSubstitutions () { + Set ret = new HashSet<>(); + ret.addAll(new ArrayList<>(getSubstitution())); + if (basePair != null) { + ret.addAll(new ArrayList<>(basePair.getAllSubstitutions())); + } + return ret; + } + + public Set getAllBases () { + Set ret = new HashSet<>(); + if (basePair != null) { + ret.add(getBasePair()); + ret.addAll(basePair.getAllBases()); + } + return ret; + } + + public UnifyPair getGroundBasePair () { + if (basePair == null) { + return this; + } + if (basePair.getBasePair() == null) { + return basePair; + } + else { + return basePair.getGroundBasePair(); + } + } + + /** + * wenn in einem Paar bestehend aus 2 Typvariablen eine nicht wildcardtable ist, + * so beide auf nicht wildcardtable setzen + */ + public void disableCondWildcards() { + if (lhs instanceof PlaceholderType && rhs instanceof PlaceholderType + && (!((PlaceholderType)lhs).isWildcardable() || !((PlaceholderType)rhs).isWildcardable())) + { + ((PlaceholderType)lhs).disableWildcardtable(); + ((PlaceholderType)rhs).disableWildcardtable(); + } + + } + + public Boolean wrongWildcard() { + return lhs.wrongWildcard() || rhs.wrongWildcard(); + } + + public Set getfBounded() { + return this.fBounded; + } + + @Override + public boolean equals(Object obj) { + if(!(obj instanceof UnifyPair)) + return false; + + if(obj.hashCode() != this.hashCode()) + return false; + + UnifyPair other = (UnifyPair) obj; + + if (isUndefinedPair()) { + if (other.getBasePair() != basePair || (other.getBasePair() == null && basePair == null)) { + return false; + } + if (!other.getBasePair().equals(basePair) || + !other.getAllSubstitutions().equals(getAllSubstitutions())) { + return false; + } + } + + return other.getPairOp() == pairOp + && other.getLhsType().equals(lhs) + && other.getRhsType().equals(rhs); + } + + @Override + public int hashCode() { + return hashCode; + } + + @Override + public String toString() { + String ret = ""; + if (lhs instanceof PlaceholderType) { + ret = new Integer(((PlaceholderType)lhs).getVariance()).toString() + " " + ((PlaceholderType)lhs).isInnerType() + + " " + ((PlaceholderType)lhs).isWildcardable(); + } + if (rhs instanceof PlaceholderType) { + ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString() + " " + ((PlaceholderType)rhs).isInnerType() + + " " + ((PlaceholderType)rhs).isWildcardable(); + } + return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ")"; //+ ", [" + getfBounded().toString()+ "])"; + } + + /* + public List getInvolvedPlaceholderTypes() { + ArrayList ret = new ArrayList<>(); + ret.addAll(lhs.getInvolvedPlaceholderTypes()); + ret.addAll(rhs.getInvolvedPlaceholderTypes()); + return ret; + } + */ +} + + diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java index 298f87e7d..f7ded0a62 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java @@ -1,119 +1,119 @@ -package de.dhbwstuttgart.typeinference.unify.model; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Set; - -import de.dhbwstuttgart.syntaxtree.StatementVisitor; -import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; -import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; - -/** - * Represents a java type. - * @author Florian Steurer - */ -public abstract class UnifyType { - - /** - * The name of the type e.q. "Integer", "? extends Integer" or "List" for (List) - */ - protected final String typeName; - - /** - * The type parameters of the type. - */ - protected final TypeParams typeParams; - - /** - * Creates a new instance - * @param name Name of the type (e.q. List for List, Integer or ? extends Integer) - * @param typeParams Parameters of the type (e.q. for List) - */ - protected UnifyType(String name, TypeParams p) { - typeName = name; - typeParams = p; - } - - - abstract public UnifyType accept(UnifyTypeVisitor visitor, T ht); - - /** - * Returns the name of the type. - * @return The name e.q. List for List, Integer or ? extends Integer - */ - public String getName() { - return typeName; - } - - /** - * The parameters of the type. - * @return Parameters of the type, e.q. for List. - */ - public TypeParams getTypeParams() { - return typeParams; - } - - /** - * Returns a new type that equals this type except for the type parameters. - * @param newTp The type params of the new type. - * @return A new type object. - */ - public abstract UnifyType setTypeParams(TypeParams newTp); - - /** - * Implementation of the visitor-pattern. Returns the set of smArg - * by calling the most specific overload in the FC. - * @param fc The FC that is called. - * @return The set that is smArg(this) - */ - abstract Set smArg(IFiniteClosure fc, Set fBounded); - - /** - * Implementation of the visitor-pattern. Returns the set of grArg - * by calling the most specific overload in the FC. - * @param fc The FC that is called. - * @return The set that is grArg(this) - */ - abstract Set grArg(IFiniteClosure fc, Set fBounded); - - /** - * Applies a unifier to this object. - * @param unif The unifier - * @return A UnifyType, that may or may not be a new object, that has its subtypes substituted. - */ - abstract UnifyType apply(Unifier unif); - - @Override - public String toString() { - String params = ""; - if(typeParams.size() != 0) { - for(UnifyType param : typeParams) - params += param.toString() + ","; - params = "<" + params.substring(0, params.length()-1) + ">"; - } - - return typeName + params; - } - - public Collection getInvolvedPlaceholderTypes() { - ArrayList ret = new ArrayList<>(); - ret.addAll(typeParams.getInvolvedPlaceholderTypes()); - return ret; - } - - public Boolean wrongWildcard() {//default - return false; - } - - @Override - public int hashCode() { - return this.toString().hashCode(); - } - - @Override - public boolean equals(Object obj) { - return this.toString().equals(obj.toString()); - } +package de.dhbwstuttgart.typeinference.unify.model; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Set; + +import de.dhbwstuttgart.syntaxtree.StatementVisitor; +import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; + +/** + * Represents a java type. + * @author Florian Steurer + */ +public abstract class UnifyType { + + /** + * The name of the type e.q. "Integer", "? extends Integer" or "List" for (List) + */ + protected final String typeName; + + /** + * The type parameters of the type. + */ + protected final TypeParams typeParams; + + /** + * Creates a new instance + * @param name Name of the type (e.q. List for List, Integer or ? extends Integer) + * @param typeParams Parameters of the type (e.q. for List) + */ + protected UnifyType(String name, TypeParams p) { + typeName = name; + typeParams = p; + } + + + abstract public UnifyType accept(UnifyTypeVisitor visitor, T ht); + + /** + * Returns the name of the type. + * @return The name e.q. List for List, Integer or ? extends Integer + */ + public String getName() { + return typeName; + } + + /** + * The parameters of the type. + * @return Parameters of the type, e.q. for List. + */ + public TypeParams getTypeParams() { + return typeParams; + } + + /** + * Returns a new type that equals this type except for the type parameters. + * @param newTp The type params of the new type. + * @return A new type object. + */ + public abstract UnifyType setTypeParams(TypeParams newTp); + + /** + * Implementation of the visitor-pattern. Returns the set of smArg + * by calling the most specific overload in the FC. + * @param fc The FC that is called. + * @return The set that is smArg(this) + */ + abstract Set smArg(IFiniteClosure fc, Set fBounded); + + /** + * Implementation of the visitor-pattern. Returns the set of grArg + * by calling the most specific overload in the FC. + * @param fc The FC that is called. + * @return The set that is grArg(this) + */ + abstract Set grArg(IFiniteClosure fc, Set fBounded); + + /** + * Applies a unifier to this object. + * @param unif The unifier + * @return A UnifyType, that may or may not be a new object, that has its subtypes substituted. + */ + abstract UnifyType apply(Unifier unif); + + @Override + public String toString() { + String params = ""; + if(typeParams.size() != 0) { + for(UnifyType param : typeParams) + params += param.toString() + ","; + params = "<" + params.substring(0, params.length()-1) + ">"; + } + + return typeName + params; + } + + public Collection getInvolvedPlaceholderTypes() { + ArrayList ret = new ArrayList<>(); + ret.addAll(typeParams.getInvolvedPlaceholderTypes()); + return ret; + } + + public Boolean wrongWildcard() {//default + return false; + } + + @Override + public int hashCode() { + return this.toString().hashCode(); + } + + @Override + public boolean equals(Object obj) { + return this.toString().equals(obj.toString()); + } } \ No newline at end of file diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java index ea70139ff..ed706b26e 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java @@ -1,72 +1,72 @@ -package de.dhbwstuttgart.typeinference.unify.model; - -import java.util.ArrayList; -import java.util.Collection; - -/** - * A wildcard type that is either a ExtendsType or a SuperType. - * @author Florian Steurer - */ -public abstract class WildcardType extends UnifyType { - - /** - * The wildcarded type, e.q. Integer for ? extends Integer. Never a wildcard type itself. - */ - protected UnifyType wildcardedType; - - /** - * Creates a new instance. - * @param name The name of the type, e.q. ? extends Integer - * @param wildcardedType The wildcarded type, e.q. Integer for ? extends Integer. Never a wildcard type itself. - */ - protected WildcardType(String name, UnifyType wildcardedType) { - super(name, wildcardedType.getTypeParams()); - this.wildcardedType = wildcardedType; - } - - /** - * Returns the wildcarded type, e.q. Integer for ? extends Integer. - * @return The wildcarded type. Never a wildcard type itself. - */ - public UnifyType getWildcardedType() { - return wildcardedType; - } - - /** - * Returns the type parameters of the WILDCARDED TYPE. - */ - @Override - public TypeParams getTypeParams() { - return wildcardedType.getTypeParams(); - } - - @Override - public Boolean wrongWildcard () {//This is an error - return (wildcardedType instanceof WildcardType); - } - - @Override - public int hashCode() { - return wildcardedType.hashCode() + getName().hashCode() + 17; - } - - @Override - public boolean equals(Object obj) { - if(!(obj instanceof WildcardType)) - return false; - - if(obj.hashCode() != this.hashCode()) - return false; - - WildcardType other = (WildcardType) obj; - return other.getWildcardedType().equals(wildcardedType); - } - - - @Override - public Collection getInvolvedPlaceholderTypes() { - ArrayList ret = new ArrayList<>(); - ret.addAll(wildcardedType.getInvolvedPlaceholderTypes()); - return ret; - } -} +package de.dhbwstuttgart.typeinference.unify.model; + +import java.util.ArrayList; +import java.util.Collection; + +/** + * A wildcard type that is either a ExtendsType or a SuperType. + * @author Florian Steurer + */ +public abstract class WildcardType extends UnifyType { + + /** + * The wildcarded type, e.q. Integer for ? extends Integer. Never a wildcard type itself. + */ + protected UnifyType wildcardedType; + + /** + * Creates a new instance. + * @param name The name of the type, e.q. ? extends Integer + * @param wildcardedType The wildcarded type, e.q. Integer for ? extends Integer. Never a wildcard type itself. + */ + protected WildcardType(String name, UnifyType wildcardedType) { + super(name, wildcardedType.getTypeParams()); + this.wildcardedType = wildcardedType; + } + + /** + * Returns the wildcarded type, e.q. Integer for ? extends Integer. + * @return The wildcarded type. Never a wildcard type itself. + */ + public UnifyType getWildcardedType() { + return wildcardedType; + } + + /** + * Returns the type parameters of the WILDCARDED TYPE. + */ + @Override + public TypeParams getTypeParams() { + return wildcardedType.getTypeParams(); + } + + @Override + public Boolean wrongWildcard () {//This is an error + return (wildcardedType instanceof WildcardType); + } + + @Override + public int hashCode() { + return wildcardedType.hashCode() + getName().hashCode() + 17; + } + + @Override + public boolean equals(Object obj) { + if(!(obj instanceof WildcardType)) + return false; + + if(obj.hashCode() != this.hashCode()) + return false; + + WildcardType other = (WildcardType) obj; + return other.getWildcardedType().equals(wildcardedType); + } + + + @Override + public Collection getInvolvedPlaceholderTypes() { + ArrayList ret = new ArrayList<>(); + ret.addAll(wildcardedType.getInvolvedPlaceholderTypes()); + return ret; + } +}