📄 pgetfcnspecinfo.m
字号:
function info = pGetFcnSpecInfo(fcnSpec)
%PGETFCNSPECINFO Returns a structure containing information on the function
% specification.
%
% Copyright 2005 The MathWorks, Inc.
% $File: $
% $Revision: $
% $Date: $
info.lhsExpr = '';
info.lhsExprRem = '';
info.lhsIOinfo = {};
info.eqExpr = '';
info.rhsExpr = '';
info.rhsExprRem = '';
info.rhsIOinfo = {};
if isempty(fcnSpec)
return
end
% Pattern to match io specifications
% something like "dataType" "[y|u|p]number" "[n]" "[m]"
ioPattern = '\s*(\w*)\s+([y|u|p])(\d+)(\s*\[\s*\d*\s*\]\s*){0,2}';
% Split the fonction specification in lhs and rhs expression
lhsExpr = '';
rhsExpr = '';
eqExpr = '';
[s, e, t] = regexpi(fcnSpec, ['\s*(',ioPattern,')?\s*(=)?(.*)']);
if all(t{1}(1,:)) && (t{1}(1,1)<=t{1}(1,2)) % <-- ML R13 !!!!!
lhsExpr = fcnSpec(t{1}(1,1):t{1}(1,2));
end
if all(t{1}(2,:)) && (t{1}(2,1)<=t{1}(2,2)) % <-- ML R13 !!!!!
eqExpr = fcnSpec(t{1}(2,1):t{1}(2,2));
end
if all(t{1}(3,:)) && (t{1}(3,1)<=t{1}(3,2)) % <-- ML R13 !!!!!
rhsExpr = regexprep(fcnSpec(t{1}(3,1):t{1}(3,2)),';','');
end
% Get lhs io specification
lhsIOinfo = iGetIOInfo(lhsExpr, ioPattern);
% Get the remainder of the lhs expression
lhsExprRem = regexprep(lhsExpr, ioPattern, '', 'ignorecase');
% Split rhs in fcn name and arglist
[s, e, t] = regexpi(rhsExpr, ['[,|\(]\s*(',ioPattern,')|(',ioPattern,')\s*[,|\)]']);
rhsIOinfo = {};
for ii=1:length(t)
argSpec = iGetIOInfo(rhsExpr(t{ii}(1,1):t{ii}(1,2)), ioPattern);
if ~isempty(argSpec)
rhsIOinfo = [rhsIOinfo; argSpec];
end
end
rhsExprRem = regexprep(rhsExpr, ioPattern, '', 'ignorecase');
% Find function name
[s, e, t] = regexpi(rhsExpr, '([a-zA-Z_]\w*)\s*\(');
fcnName = cell(1, length(t));
for ii = 1:length(t)
fcnName{ii} = rhsExpr(t{ii}(1,1):t{ii}(1,2));
end
info.lhsExpr = lhsExpr;
info.lhsExprRem = lhsExprRem;
info.lhsIOinfo = lhsIOinfo;
info.eqExpr = eqExpr;
info.rhsExpr = rhsExpr;
info.rhsExprRem = rhsExprRem;
info.rhsIOinfo = rhsIOinfo;
%--------------------------------------------------------------------------
function ioSpec = iGetIOInfo(ioTxt, ioPattern)
% Internal function
if isempty(ioTxt)
ioSpec = {};
return
end
[s, e, t] = regexpi(ioTxt, ioPattern);
% IOname --> u or y or p
% IOnum --> input/output/parameter number
% IOdtype --> uint8 int8 uint16 int16 ...
% IOdim --> [m n k]
% IOptr --> scalar by value, scalar by reference, vector/matrix by reference
% IOtxt --> original string
% IOhs --> empty (don''t know) 1(lhs) 2(rhs)
ioSpec = cell(1, 7);
ioSpec{1, 6} = ioTxt;
if all(t{1}(1,:)) % <-- ML R13 !!!!!
% remove leading and trailing blank in dataType
ioDType = regexprep(ioTxt(t{1}(1,1):t{1}(1,2)), '^\s*|\s*$','');
else
ioDType = '';
end
ioSpec{3} = ioDType; % <-- add data type checking
if all(t{1}(2,:)) % <-- ML R13 !!!!!
ioName = lower(ioTxt(t{1}(2,1):t{1}(2,2)));
else
ioName = '';
end
ioSpec{1} = ioName;
if all(t{1}(3,:)) % <-- ML R13 !!!!!
ioNum = sscanf(ioTxt(t{1}(3,1):t{1}(3,2)), '%d');
else
ioNum = -1;
end
ioSpec{2} = ioNum;
if size(t{1}, 1) < 4 || ~all(t{1}(4,:)) || (t{1}(4,2)<t{1}(4,1)) % <-- ML R13 !!!!!
ioDim = 1;
ioPtr = 0;
else
ioDims = ioTxt(t{1}(4,1):t{1}(4,2));
[ss, ee, tt] = regexpi(ioDims, '\s*\[\s*(\d*)\s*\]\s*');
ioPtr = 1;
ioDim = [];
for jj = 1:length(tt)
if isempty(tt{jj}) || tt{jj}(1,1) > tt{jj}(1,2) % test for ML 14
jjDim = -1;
else
jjDim = sscanf(ioDims(tt{jj}(1,1):tt{jj}(1,2)), '%d');
end
ioDim = [ioDim jjDim];
end
end
ioSpec{4} = ioDim;
ioSpec{5} = ioPtr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -