function propVal = get_impl(a,propName)
% GET(A,PROPNAME) MATLAB Code Generation Library function that gets the value of the 
% embedded.fi (A) property specified by PROPNAME      

% This is a dummy function that returns a best guess for ambiguous types

% Copyright 2006-2014 The MathWorks, Inc.
%#codegen
coder.extrinsic('coder_sysobj_get');
coder.extrinsic('eml_getprop_helper');

if isa(a, 'function_handle')
    % Error if incorrect number of inputs
    eml_invariant(nargin == 2,'fixed:coder:incorrectNumberOfInputsGet');
    propVal = a('get',propName);
elseif coder.const(isa(a,'matlab.system.SystemImpl'))
    eml_transient;
    coder.inline('always');
    comp = eml_sea_get_obj(a);
    if nargin == 2
        [propVal,err] = coder.const(@coder_sysobj_get,comp,propName);
    else
        [propVal,err] = coder.const(@coder_sysobj_get,comp);
    end
    if ~isempty(err)
        eml_assert(0,err);
    end  
else
    % Error if incorrect number of inputs
    eml_invariant(nargin == 2,'fixed:coder:incorrectNumberOfInputsGet');
    if eml_ambiguous_types
        % eml_ambiguous_types is true only during Simulink size propagation,
        % at which point the type of input "a" is unknown.
        % so EML assume "a" is double during SL size propagation
        % Workaround for MATLAB function block not participating size propagation:
        % explicitly set input type or set output size        
        if eml_is_const(size(a))
            a1 = coder.const(zeros(size(a)));
        else
            % a has varD
            a1 = coder.const(0);
        end
        
        %retVal could be double scalar, logical scalar, string, 
        %       or double array with same size as input "a"
        % Note for string, the size of retVal may also be wrong
        % The propVal is just a guess
        [propVal,~] = coder.const(@eml_getprop_helper,a1, propName);
    
        %ignore the internal error during size propagation because those will come 
        % up later once the type is known, a more meaningful error message can be given then
    else
        eml_invariant(0,'fixed:coder:invalidUseGet');
        %propVal = feval('get',a,propName);
    end
end
%------------------------------------------------------------------------------
