Skip to content

Commit

Permalink
Began handling of feature specifications in type checker.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdidriksen committed Apr 17, 2012
1 parent 90d69dd commit 216a460
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/type_checker/tbon_tc_error.e
Expand Up @@ -50,6 +50,7 @@ feature -- Error codes
err_code_cluster_not_in_cluster_or_system,
err_code_creator_does_not_exist,
err_code_involved_class_does_not_exist,
err_code_selective_export_class_does_not_exist,
err_code_target_does_not_exist,
err_code_undefined: INTEGER = unique

Expand Down
15 changes: 15 additions & 0 deletions src/type_checker/tbon_tc_text_items.e
Expand Up @@ -8,6 +8,9 @@ class
TBON_TC_TEXT_ITEMS

feature -- Type names
any_type_name: STRING = "ANY"
-- Type name for an ANY type.

boolean_type_name: STRING = "BOOLEAN"
-- Type name for a BOOLEAN type.

Expand All @@ -17,6 +20,9 @@ feature -- Type names
integer_type_name: STRING = "INTEGER"
-- Type name for an INTEGER type.

none_type_name: STRING = "NONE"
-- Type name for a NONE type.

real_type_name: STRING = "REAL"
-- Type name for a REAL type.

Expand Down Expand Up @@ -142,6 +148,15 @@ feature -- Error messages
Result.append_string (".")
end

err_selective_export_class_does_not_exist (a_class_name, an_enclosing_class_name: STRING): STRING
do
Result := "Specified selective export class "
Result.append_string (a_class_name.string)
Result.append_string (" in class specification ")
Result.append_string (an_enclosing_class_name.string)
Result.append_string (" does not exist.")
end

err_target_does_not_exist (a_chart_name, a_class_name: STRING): STRING
do
Result := "Specified target class "
Expand Down
115 changes: 114 additions & 1 deletion src/type_checker/textual_bon_type_checker.e
Expand Up @@ -53,6 +53,7 @@ feature -- Initialization
integer_type: TBON_TC_INTEGER_TYPE
real_type: TBON_TC_REAL_TYPE
string_type: TBON_TC_STRING_TYPE
any_type: TBON_TC_CLASS_TYPE
do
-- Create type contexts
create informal_type_context.default_create
Expand All @@ -64,13 +65,23 @@ feature -- Initialization
create integer_type.make
create real_type.make
create string_type.make
-- Create ANY
create any_type.make (any_type_name)

-- Add default value types to context
add_to_informal_type_context (boolean_type)
add_to_informal_type_context (character_type)
add_to_informal_type_context (integer_type)
add_to_informal_type_context (real_type)
add_to_informal_type_context (string_type)
add_to_informal_type_context (any_type)

add_to_formal_type_context (boolean_type)
add_to_formal_type_context (character_type)
add_to_formal_type_context (integer_type)
add_to_formal_type_context (real_type)
add_to_formal_type_context (string_type)
add_to_formal_type_context (any_type)

create value_context.default_create

Expand All @@ -91,6 +102,8 @@ feature {NONE} -- Contexts

extended_ids: LIST[STRING]

unresolved_features: MML_SET[TBON_TC_FEATURE]

feature -- Status report
first_phase: BOOLEAN
-- Is the type checker in the first phase?
Expand Down Expand Up @@ -870,7 +883,7 @@ feature -- Type checking, static diagrams

Result := True

-- Add ancestors as ancestors to enclosing class
-- Add ancestors to enclosing class
if an_element.parent_count > 0 then
ancestors := an_element.parents

Expand All @@ -887,6 +900,14 @@ feature -- Type checking, static diagrams
end
end

-- Idea:
-- Put all features with unresolved types in a set.
-- Every time a new type is added to the context,
-- give corresponding features a pointer to that type.
-- If the feature set is not empty after first phase,
-- an error has occurred, as a feature is mentioning
-- a non-existing type.

else
Result := False
end
Expand Down Expand Up @@ -1045,6 +1066,58 @@ feature -- Type checking, static diagrams
end
end

check_feature_clause (an_element: FEATURE_CLAUSE; enclosing_class: TBON_TC_CLASS_TYPE): BOOLEAN
-- Does `an_element' type check as a type FEATURE_CLAUSE?
note
rule: "[
In an environment where all enclosed features specifications are OK,
and all classes mentioned in the selective export exist,
`an_element' is OK.
]"
do
if first_phase then

Result := True

from an_element.feature_specifications.start until an_element.feature_specifications.after
loop
Result := check_feature_specification (an_element.feature_specifications.item_for_iteration, an_element.selective_export, enclosing_class) and Result

an_element.feature_specifications.forth
end

elseif second_phase then

Result := True

from an_element.feature_specifications.start until an_element.feature_specifications.after
loop
Result := check_feature_specification (an_element.feature_specifications.item_for_iteration, an_element.selective_export, enclosing_class) and Result

an_element.feature_specifications.forth
end

Result := check_selective_export (an_element.selective_export, enclosing_class)

end
end

check_feature_specification (an_element: FEATURE_SPECIFICATION; selective_export: CLASS_NAME_LIST; enclosing_class: TBON_TC_CLASS_TYPE): BOOLEAN
-- Does `an_element' type check as a type FEATURE_SPECIFICATION?
note
rule: "[
In an environment where the name of `an_element' is unique in its enclosing class,
and the type of the feature is in the environment,
and all feature arguments are OK,
and if renamed is renamed consistently,
]"
do
if then

end
end

check_formal_generics (an_element: FORMAL_GENERIC_LIST; enclosing_class: TBON_TC_CLASS_TYPE): BOOLEAN
-- Does `an_element' type check as a type FORMAL_GENERIC_LIST?
note
Expand All @@ -1066,6 +1139,46 @@ feature -- Type checking, static diagrams
check false end
end

check_selective_export (an_element: CLASS_NAME_LIST; enclosing_class: TBON_TC_CLASS_TYPE): BOOLEAN
-- Does `an_element' type check as a type CLASS_NAME_LIST?
note
rule: "[
In an environment where all the classes mentioned in the selective export exist,
or are otherwise allowable (e.g. NONE),
`an_element' is OK.
]"
do
if first_phase then

Result := True
-- Nothing to be checked for first phase

elseif second_phase then

from an_element.start until an_element.after
loop
if not class_name_exists_in_context (an_element.item_for_iteration, formal_type_context) and
not (an_element.item_for_iteration ~ none_type_name) then
add_error (err_code_selective_export_class_does_not_exist, err_selective_export_class_does_not_exist (an_element.item_for_iteration, enclosing_class.name))
end
an_element.forth
end

else
Result := False
end
ensure
all_selective_export_classes_exist:
an_element.for_all (
agent (export_class_name: STRING): BOOLEAN
do
Result := class_name_exists_in_context (export_class_name, formal_type_context) xor
export_class_name ~ none_type_name
end
)
-- For all classes it holds that it exists in the environment or is of type NONE.
end

check_static_block (some_elements: STATIC_COMPONENTS): BOOLEAN
-- Does each element in `some_elements' type check as their respective types?
note
Expand Down
20 changes: 19 additions & 1 deletion src/type_checker/types/tbon_tc_class_type.e
Expand Up @@ -10,7 +10,8 @@ class
inherit
TBON_TC_TYPE
redefine
is_model_equal
is_model_equal,
is_equal
end

create
Expand Down Expand Up @@ -140,4 +141,21 @@ feature -- Status report
Result := name ~ other.name
end

is_equal (other: like Current): BOOLEAN
-- Is this model mathematically equal to `other'?
do
Result := name ~ other.name and (generics /= Void implies generics.for_all (
agent (generic: TBON_TC_GENERIC; l_other_class: TBON_TC_CLASS_TYPE): BOOLEAN
do
Result := l_other_class.generics.exists (agent (this_generic, other_generic: TBON_TC_GENERIC): BOOLEAN
do
Result := this_generic |=| (other_generic)
end (generic, ?)
)
end (?, other)
))
-- If other class is a class type and has generics, both names and generics must be equal
-- For all generics of Current, there must exist an equal generic in other.
end

end
31 changes: 30 additions & 1 deletion src/type_checker/types/tbon_tc_feature.e
Expand Up @@ -7,19 +7,35 @@ note
class
TBON_TC_FEATURE

inherit
MML_MODEL
redefine
is_model_equal
end

create
make

feature -- Initialization
make (a_name: STRING; a_type: TBON_TC_CLASS_TYPE)
make (a_name: STRING; a_type: TBON_TC_CLASS_TYPE; an_enclosing_class: TBON_TC_CLASS_TYPE)
require
a_name /= Void and then not a_name.is_empty
a_type /= Void
an_enclosing_class /= Void
do
name := a_name.string
type := a_type
enclosing_class := an_enclosing_class

create {LINKED_LIST[STRING]} selective_export.make
create {LINKED_LIST[TBON_TC_FEATURE_ARGUMENT]} arguments.make
end

feature -- Access
name: STRING

enclosing_class: TBON_TC_CLASS_TYPE

selective_export: LIST[STRING]

type: TBON_TC_CLASS_TYPE
Expand All @@ -35,6 +51,12 @@ feature -- Status report

is_redefined: BOOLEAN

is_model_equal alias "|=|" (other: TBON_TC_FEATURE): BOOLEAN
-- Is this model mathematically equal to `other'?
do
Result := name ~ other.name and enclosing_class |=| other.enclosing_class
end

feature -- Element change
set_is_deferred
do
Expand Down Expand Up @@ -70,6 +92,13 @@ feature -- Element change
is_renamed: is_renamed
end

set_type (a_type: TBON_TC_CLASS_TYPE)
require
a_type /= Void
do
type := a_type
end

feature -- Renaming
is_renamed: BOOLEAN

Expand Down
16 changes: 15 additions & 1 deletion src/type_checker/types/tbon_tc_generic.e
Expand Up @@ -7,14 +7,22 @@ note
class
TBON_TC_GENERIC

inherit
MML_MODEL
redefine
is_model_equal
end

create
make

feature -- Initialization
make (a_formal_generic_name: STRING; an_actual_generic_type: like actual_generic_type)
-- Initialize `Current'.
require
a_formal_generic_name /= Void
do
formal_generic_name := a_formal_generic_name
formal_generic_name := a_formal_generic_name.string
actual_generic_type := an_actual_generic_type
end

Expand All @@ -32,6 +40,12 @@ feature -- Status report
Result := actual_generic_type /= Void
end

is_model_equal alias "|=|" (other: TBON_TC_GENERIC): BOOLEAN
-- Is this model mathematically equal to `other'?
do
Result := formal_generic_name ~ other.formal_generic_name and actual_generic_type ~ other.actual_generic_type
end

invariant
formal_generic_name /= Void

Expand Down

0 comments on commit 216a460

Please sign in to comment.