In PParser, a wide range of classes are employed.
I'd like to know if there is a way to avoid this kind of 'pattern matching'
function PasElementGetVarType(const AElement: TPasElement): TPasType;
begin
try
Result := (AElement as TPasVariable).VarType
except
try
Result := (AElement as TPasArgument).ArgType;
except
try
Result := (AElement as TPasFunction).FuncType.ResultEl.ResultType;
except
Result := (AElement as TPasResultElement).ResultType;
end;
end;
end;
end;
because it makes almost impossible to debug the code (specifically, Pas2Php),
since every mismatched cast issues two exceptions, so I'm forced to disable them from the debugger UI, just to be left at the end with a truncated file and the impossibility to know where the (rather complex) program has failed.
I had a cursory look into the documentation, but the meta types documentation is rather complex, as it's ought to be for the complex Pascal types, and maybe doesn't provide an idiomatic pattern for beginners (why the section
class reference definition (TClassRefDef) is empty?)... Just to provide an hint of what I'd like to obtain, in C++, a dynamic_downcast<Derived*>(Super*) could be a solution.
TIA, Carlo