def eval_comp(context, comp, expected_type): """ Instantiate the given component, computing the required config. :type context: ctx.EvaluationContext :param context: Evaluation context. :type comp: ast.Component :param comp: the node to evaluate. :type expected_type: type_util.IsType :param expected_type: The expected type of this computation. :return: Returns the instantiated component. """ arguments = {} # Compute arguments for arg in comp.args: arg_name = ast.DotPath(arg.arg_name.span, arg.arg_name, []) arg_value = eval_rhs(context, arg.value, expected_type[arg_name]) arguments[arg.arg_name.inner_val()] = arg_value # Lookup component component_type = introspect.get_class_by_name(comp.type_name.val) # Get default config for the component conf = component_type.get_default_config() # Update modified params for k, val in arguments.iteritems(): conf[k] = val # Delay evaluation until we do the assign return component_type, conf
def action_dot_path(s, l, t): # First token is the name of the variable # The rest is the property path if isinstance(t[0], ast.StringLit) and len(t[1:]) == 0: return t[0] return ast.DotPath(ast.make_span(s, l, t), t[0], t[1:])