function val = hdlslResolve(prop, block)
% This function takes a property name and a block (name/pointer)
% and resolves the value of the property in the model and base
% workspace scope.

% Copyright 2008-2023 The MathWorks, Inc.

prop_val = get_param(block, prop);
if isempty(prop_val) || ~ischar(prop_val)
val = prop_val;
return
end

if all(ishandle(block))
slbh = block;
blockpath = getfullname(block);
else
slbh = [];
blockpath = block;
end

try
val = slResolve(prop_val, blockpath);
catch me
if strcmp(me.identifier, 'Simulink:Data:SlResolveNotResolved')
% To address the contents of bus expansion subsystems, we must
% carry out the resolution within the context of the
% original non-synthetic block.
if isempty(slbh)
blkObj = get_param(block, 'object');
else
blkObj = get_param(slbh, 'object');
end
val = prop_val; % most resolution we get so return val exists on function
blkType = get_param(blkObj.Parent, 'type');
if ~strcmpi(blkType, 'block_diagram')
expSS = slInternal('busDiagnostics', 'handleToExpandedSubsystem', get_param(blkObj.Parent, 'Handle'));
if all(ishandle(expSS)) && ...
slhdlcoder.SimulinkFrontEnd.isBusExpansionSubsystem(expSS)
try
prop_val = get_param(blkObj.Parent, prop);
if isempty(prop_val) || ~ischar(prop_val)
val = prop_val;
return
end
val = slResolve(prop_val, blkObj.Parent);
catch
end
end
end
else
me.rethrow;
end
end
end

% LocalWords: slbh