How to mark as deprecated a single enum value in Delphi - delphi

I wish to have the following:
TEnumType = (
etValue1 = 1,
etValue2 = 2 deprecated,
etValue3 = 3);
It returns:
[DCC Error] unt_CollectionImportType.pas(19): E2029 ',' or ')' expected
but identifier 'deprecated' found.
Is there a way to instruct the compiler that this value is deprecated.

type
TEnumType = (
etValue1 = 1,
etDeprecated2 = 2, // was: etValue2; Renamed so we can deprecate it by name
etValue3 = 3);
const
etValue2 = etDeprecated2 deprecated; // Declares a constant mapped to the renamed enum value.

Related

I know it is not null, but Dart doesn't know that. How do I tell it?

The code Dart is complaining about:
Map<String,int> get_frequency(String text) {
Map<String,int> retval = {};
for (int i = 0; i<text.length; ++i) {
retval[text[i]] = retval[text[i]] ?? 0;
retval[text[i]]++; //<---- this is where dart is complaining.*
}
return retval;
}
void main() {
const paragraphOfText = 'Once upon a time there was a Dart programmer who '
'had a challenging challenge to solve. Though the challenge was great, '
'a solution did come. The end.';
var data = get_frequency(paragraphOfText);
print(data);
}
Obviously the line marked with (*) can not be null, so how do I tell that to Dart? I tried the null assertion operator (!), but that didn't work.
Null Safety is enabled.
Error message:
challenge2.dart:5:20: Error: Operator '+' cannot be called on 'int?' because it is potentially null.
retval[text[i]]++;
^
challenge2.dart:5:20: Error: A value of type 'num' can't be assigned to a variable of type 'int'.
retval[text[i]]++;
^
A possible solution is to change the line
retval[text[i]]++; //<---- this is where dart is complaining.*
into
retval[text[i]] = retval[text[i]]! + 1;
Just figured it out.

how to add a ModulePassManager in llvm pass?

I'm trying to add a ModulePassManager in llvm pass, because all pass is function pass, so all I added createModuleToFunctionPassAdaptor function, but compile error, I don't know how to solve it. does anybody know how to solve this problem. I tried this:
llvm::PreservedAnalyses DBogusFlow::run(llvm::Module &M,
llvm::ModuleAnalysisManager &MAM) {
bool Changed = runOnModule(M);
auto MPM = std::make_unique<ModulePassManager>();
MPM->addPass(createModuleToFunctionPassAdaptor(createAggressiveDCEPass()));
MPM->addPass(
createModuleToFunctionPassAdaptor(createInstructionCombiningPass()));
MPM->addPass(
createModuleToFunctionPassAdaptor(createCFGSimplificationPass()));
MPM->run(M, MAM);
return (Changed ? llvm::PreservedAnalyses::none()
: llvm::PreservedAnalyses::all());
}
below is the compile error
[ 50%] Building CXX object CMakeFiles/DBogusFlow.dir/lib/DBogusFlow.cpp.o
In file included from /usr/include/llvm/IR/PassManager.h:48,
from /home/v4kst1z/Desktop/ollvm-deobfuscator/lib/../include/DBogusFlow.h:12,
from /home/v4kst1z/Desktop/ollvm-deobfuscator/lib/DBogusFlow.cpp:9:
/usr/include/llvm/IR/PassManagerInternal.h: In instantiation of ‘PreservedAnalysesT llvm::detail::PassModel<IRUnitT, PassT, PreservedAnalysesT, AnalysisManagerT, ExtraArgTs>::run(IRUnitT&, AnalysisManagerT&, ExtraArgTs ...) [with IRUnitT = llvm::Function; PassT = llvm::FunctionPass*; PreservedAnalysesT = llvm::PreservedAnalyses; AnalysisManagerT = llvm::AnalysisManager<llvm::Function>; ExtraArgTs = {}]’:
/usr/include/llvm/IR/PassManagerInternal.h:83:22: required from here
/usr/include/llvm/IR/PassManagerInternal.h:85:17: error: request for member ‘run’ in ‘((llvm::detail::PassModel<llvm::Function, llvm::FunctionPass*, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >*)this)->llvm::detail::PassModel<llvm::Function, llvm::FunctionPass*, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >::Pass’, which is of pointer type ‘llvm::FunctionPass*’ (maybe you meant to use ‘->’ ?)
85 | return Pass.run(IR, AM, ExtraArgs...);
| ~~~~~^~~
/usr/include/llvm/IR/PassManagerInternal.h: In instantiation of ‘llvm::StringRef llvm::detail::PassModel<IRUnitT, PassT, PreservedAnalysesT, AnalysisManagerT, ExtraArgTs>::name() const [with IRUnitT = llvm::Function; PassT = llvm::FunctionPass*; PreservedAnalysesT = llvm::PreservedAnalyses; AnalysisManagerT = llvm::AnalysisManager<llvm::Function>; ExtraArgTs = {}]’:
/usr/include/llvm/IR/PassManagerInternal.h:88:13: required from here
/usr/include/llvm/IR/PassManagerInternal.h:88:55: error: ‘name’ is not a member of ‘llvm::FunctionPass*’
88 | StringRef name() const override { return PassT::name(); }
| ~~~~~~~~~~~^~
make[2]: *** [CMakeFiles/DBogusFlow.dir/build.make:76: CMakeFiles/DBogusFlow.dir/lib/DBogusFlow.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:86: CMakeFiles/DBogusFlow.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

Dart: Constant evaluation error. The method '[]' can't be invoked in a constant expression

I am getting an error on constant evaluation.
please take a look at this code:
class A {
final num a;
const A(this.a);
}
class B {
final A a;
const B(this.a);
}
main() {
const a = A(12);
const b = B(a); // this works fine
// I believe everything inside a const List is considered constant,
// please correct me if that is wrong
const aL = [ A(12), A(13) ]; // [ a, A(13) ] will not work either
const b2 = B(
aL[0], // here the error is happening
);
}
Error:
lib/logic/dartTest.dart:22:14: Error: Constant evaluation error:
const b2 = B(
^
lib/logic/dartTest.dart:23:7: Context: The method '[]' can't be invoked on '<A>[A {a: 12}, A {a: 13}]' in a constant expression. - 'A' is from 'package:t_angband/logic/dartTest.dart' ('lib/logic/dartTest.dart').
aL[0],
^
lib/logic/dartTest.dart:22:9: Context: While analyzing:
const b2 = B(
^
The list contains constant Object, then why the constant evaluation is failing? Shouldn't this be an analyzer issue? Am I missing something?
Thankyou.
Constant expressions can only build data, it cannot deconstruct it. You cannot call any methods on the constant objects except a handful of operations on numbers (and String.length, which also creates a number).
So, aL[0] is simply not a valid compile-time constant expression.
A possible fix may be to make b2 not constant!

How to use H5Sselect_elements to read data

I have a HDF file which contains a simple array of compound types.
To read all elements in the array i do
hid_t hDataSet = H5Dopen(hSpecies,AGENT_DATASET_NAME, H5P_DEFAULT);
herr_t status = H5Dread(hDataSet, agent_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, *ppAgentData);
Now i want to read only a selection of those elements. I place this before the call to H5Dread:
hsize_t coords[3][1];
coords[0][0] = 1;
coords[1][0] = 3;
coords[2][0] = 6;
hid_t hDataSpace = H5Dget_space(hDataSet);
int iRes = H5Sselect_elements(hDataSpace, H5S_SELECT_SET, 3, (const hsize_t *)&coords);
I expected that i would get the first, the third and the sixth element, but actually i get the same result as without the call to H5Sselect_elements. Do i misunderstand something about the use of H5Sselect_elements? The problem is, all examples i found use this function only in combination with H5Dwrite()...
The problem was that i used 'H5S_ALL' for the 'mem_space_id' and 'file_space_id' parameters of H5Dread. The working code now looks like this:
hid_t hDataSetAgents = H5Dopen(hSpecies,AGENT_DATASET_NAME, H5P_DEFAULT);
hid_t hDataSpaceAgents = H5Dget_space(hDataSetAgents);
hsize_t coords[3];
coords[0] = 1;
coords[1] = 3;
coords[2] = 6;
int iRes = H5Sselect_elements(hDataSpaceAgents, H5S_SELECT_SET, 3, (const hsize_t *)&coords);
hsize_t d = 3;
agsub *pAgentData = new agsub[d];
hid_t hMemSpace = H5Screate_simple(1, &d, NULL);
herr_t status = H5Dread(hDataSetAgents, agsubid, hMemSpace, hDataSpaceAgents, H5P_DEFAULT, pAgentData);
The 'file_space_id' parameter tells H5Dread "where to read from" (in this case my dataspace with a selection of three elements applied to it), and the 'mem_space_id' parameter tells it "where to write to" (in this case a simple array of three elements). If you specify 'H5S_ALL' for both, the entire dataspace is read.

RTTI - why is in some cases TTypedData.CompType nil?

I have a TValue enclosing a set. TTypedData.CompType is nil. So calling TValue.ToString throws an exception, because System.TypInfo.SetToString assumes CompType to never be nil.
Why is CompType nil for some set types?
TTestEnumType = (tstEnum1 = 1, tstEnum2 = 2, tstEnum3 = 3, tstEnum4 = 4, tstEnum5 = 5, tstEnum6 = 6, tstEnum7 = 7);
TTestEnumTypeSet = set of TTestEnumType;
TTestSetOfByte = set of Byte;
Above we have defined two set types: TTestEnumTypeSet and TTestSetOfByte.
The following simple test shows that CompType is nil for TTestSetOfByte.
procedure TTestUtlRttiComparer.TestSetToString;
var
TypeData1: TTypeData;
TypeData2: TTypeData;
TypeInfo1: TTypeInfo;
TypeInfo2: TTypeInfo;
begin
TypeInfo1 := PTypeInfo(TypeInfo(TTestSetOfByte))^;
TypeInfo2 := PTypeInfo(TypeInfo(TTestEnumTypeSet))^;
CheckTrue(TypeInfo1.Kind = tkSet);
CheckTrue(TypeInfo2.Kind = tkSet);
TypeData1 := GetTypeData(#TypeInfo1)^;
TypeData2 := GetTypeData(#TypeInfo2)^;
CheckTrue(Assigned(TypeData1.CompType));
CheckTrue(Assigned(TypeData2.CompType), 'TypeData2.CompType is NULL!!!! WHY??????'); // this FAILS!!!
end;
Enumerated types with explicitly assigned ordinality do not have RTTI. This is stated in the documentation:
Enumerated constants without a specific value have RTTI:
type SomeEnum = (e1, e2, e3);
whereas enumerated constants with a specific value, such as the
following, do not have RTTI:
type SomeEnum = (e1 = 1, e2 = 2, e3 = 3);

Resources