Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intrinsics support #1261

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Empty file.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""
A custom Exception to display Invalid Intrinsics and Symbol Table format.
It also has a list of helper functions that cleanup the processing in IntrinsicResolver and IntrinsicSymbolTable
"""
from six import string_types


class InvalidIntrinsicException(Exception):
pass


def verify_intrinsic_type_bool(argument, property_type="", message="", position_in_list=""):
verify_intrinsic_type(argument, property_type, message, position_in_list, primitive_type=bool)


def verify_intrinsic_type_list(argument, property_type="", message="", position_in_list=""):
verify_intrinsic_type(argument, property_type, message, position_in_list, primitive_type=list)


def verify_intrinsic_type_dict(argument, property_type="", message="", position_in_list=""):
verify_intrinsic_type(argument, property_type, message, position_in_list, primitive_type=dict)


def verify_intrinsic_type_int(argument, property_type="", message="", position_in_list=""):
# Special case since bool is a subclass of int in python
if isinstance(argument, bool):
raise InvalidIntrinsicException(
message or "The {} argument to {} must resolve to a {} type".format(position_in_list, property_type,
int))
verify_intrinsic_type(argument, property_type, message, position_in_list, primitive_type=int)


def verify_intrinsic_type_str(argument, property_type="", message="", position_in_list=""):
verify_intrinsic_type(argument, property_type, message, position_in_list, primitive_type=string_types)


def verify_non_null(argument, property_type="", message="", position_in_list=""):
if argument is None:
raise InvalidIntrinsicException(
message or "The {} argument to {} is missing from the intrinsic function".format(position_in_list,
property_type))


def verify_intrinsic_type(argument, property_type="", message="", position_in_list="", primitive_type=string_types):
verify_non_null(argument, property_type, message, position_in_list)
if not isinstance(argument, primitive_type):
raise InvalidIntrinsicException(
message or "The {} argument to {} must resolve to a {} type".format(position_in_list, property_type,
primitive_type))


def verify_in_bounds(objects, index, property_type=""):
if index < 0 or index >= len(objects):
raise InvalidIntrinsicException(
"The index of {} resolved properties must be within the range".format(property_type))


def verify_number_arguments(arguments, property_type="", num=0):
if not len(arguments) == num:
raise InvalidIntrinsicException(
"The arguments to {} must have {} arguments instead of {} arguments".format(property_type, num,
len(arguments)))


def verify_all_list_intrinsic_type(arguments, verification_func, property_type="", message="", position_in_list=""):
for argument in arguments:
verification_func(argument, property_type, message, position_in_list)


class InvalidSymbolException(Exception):
pass
Empty file.
Loading