MIDL changes case of identifier when compiling IDL file - midl

I've got a snippet of IDL that looks like this:
[ object, uuid(...), pointer_default(unique) ]
interface IVirtualMachine { /* ... */ }
[ object, uuid(...), pointer_default(unique) ]
interface IVirtualServer : IUnknown
{
HRESULT FindVirtualMachine(
[in] BSTR configurationName,
[out,retval] IVirtualMachine **virtualMachine);
};
[ uuid(...), version(1.0) ]
library VirtualServerLib
{
[ uuid(...) ]
coclass VirtualServer
{
[default] interface IVirtualServer;
};
[ uuid(...) ]
coclass VirtualMachine
{
[default] interface IVirtualMachine;
};
};
...when I compile it with MIDL and then look in the generated type library, VirtualMachine (upper-case V) has been turned into virtualMachine (lower-case V).
If I call my coclass XirtualMachine, for example, it's all good.
What the hell?

This is a terrible bug/feature of MIDL. It doesn't allow the same identifier to appear with different casing, so it replaces all subsequent instances of a word with the casing from the first time it was seen.
See the KB220137

OK. Worked it out. It was this line here:
[out,retval] IVirtualMachine **virtualMachine);
If I change it to:
[out,retval] IVirtualMachine **ppVirtualMachine);
...then it works fine. Something screwy in MIDL, I guess. Maybe it's trying to do VB-like case correction.

Related

Do all solidity functions in an imported interface get compiled into the smart contract bytecode, even if they aren't used?

I'm trying to keep a contract as small as possible. I know that if you import a solidity library, only the functions actually utilized in that library get compiled into the contract, increasing it's size.
I'm not sure if that goes for importing interfaces.
For example:
interface IDoThings {
function transfer(address from, address to, uint256 amount) external;
function setValue(uint256 newVal) external;
function owner() external view returns (address);
}
contract DoingThings {
function getOwnerOfAnotherContract(address target) public view returns (address) {
return IDoThings(target).owner();
}
}
When this get's compiled down, will the function selectors for transfer & setValue also be included in the contract's bytecode, or will only the owner function selector be included?
interface is like typescript types, they are used in compilation time and in the javascript bundle you do not see any type definitions.
If you compile your code at https://remix.ethereum.org/
this is what you will get
[
{
"inputs": [
{
"internalType": "address",
"name": "target",
"type": "address"
}
],
"name": "getOwnerOfAnotherContract",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
}
]
there is nothing about interface or its function signatures
They do not.
Solidity v0.8 without bytecode optimizer:
with the unused interface declarations: 554 bytes
without: 554 bytes

Rescript Record: Key as Array

In Rescript, one can define a Record in this format:
type record1 = {
a : String
}
but NOT:
type record2 = {
[a] : String
}
I am looking to write a record that compiles to JS like:
{
[Op.or]: [12,13]
}
The use case above comes from Sequelize, and the reference is here.
My current solution:
%raw(`{[Op.or]:[12,13]}`)
It's not entirely clear how you intend to interface with the Op construct, whether you can bind to it or not, but here's an example that does, and along with Js.Dict.t effectively produces the same output:
module Op = {
#val external or: string = "Op.or"
}
Js.Dict.fromList(list{
(Op.or, [12, 23])
})
It does not directly compile to the JS you want, however, which might be a problem if you rely on something that actually parses the source code. But short of that, I believe this should do what you ask for.

How can I select a part of TM_DIRECTORY variable?

I want to select a part of the TM_DIRECTORY variable on VScode snippet. I mean I want to select Tests\Setup of the d:\Projects\Hakhsin\hakhsin\tests\Setup in code-snippet file. Look at this:
// On snippet file
"PHP Class": {
"scope": "",
"prefix": ["phpClass"],
"body": [
"<?php\n\nnamespace ${TM_DIRECTORY/(?<=(?:[\w:\\]hakhsin\\)).+(?=\\)//};\n\nclass ${TM_FILENAME_BASE} {\n\t$2\n}"
],
"description": "New PHP Class"
},
And I want to get this result:
namespace Tests\Setup;
class StorageFactory {
}
But I get this result:
<?php
namespace d:\Projects\Hakhsin\hakhsin\tests\Setup;
class StorageFactory {
}
It doesn't appear you can use variables inside of other variables in a snippet transform.
You can try this code which is more "dynamic" than yours but not perfect:
"${TM_DIRECTORY/([^\\\\]*\\\\){4}(.*)/${2:/capitalize}/}",
The {4} in that is if you have 4 segments in the directory structure before the part you want, like d:\Projects\Hakhsin\hakhsin\tests\Setup The segments are d:\, Projects\, Hakhsin\ and hakhsin\. If that number of segments is known and stable than the snippet I showed works well.
I doubt the number of those segments would vary within a project but might very well between projects - you would just have to change the {x} item for each project if so.
I solved it but it is not dynamic.
namespace ${TM_DIRECTORY/(.*hakhsin\\\\)(.*)/${2:/capitalize}/};
Is there a better way? anything like this:
namespace ${TM_DIRECTORY/(.*${WORKSPACE_NAME}\\\\)(.*)/${2:/capitalize}/};
This is the result:
<?php
namespace Tests\Setup;
class StorageFactory {
}

Add tasks to tasks.json for users of a vscode extension

I am writing a vscode extention for a specification language. I would like to provide the users of the plugin with a specific task. The task could be made available using tasks.json.
Is there a way to add tasks to the tasks.json of a user that uses that extension?
The documentation didn't help me here either. When you provide tasks through the extension there is the TaskProvider API. The example doesn't go into much detail about how these tasks are created though, compared to the classical tasks.json approach.
In your package.json you need to define the types of tasks this extension contributes. This has nothing to do with the type in tasks.json. It's rather a freeform string. If you need custom problem matchers you also need to define theme here.
"contributes": {
"taskDefinitions": [
{
"type": "mytask"
}
],
"problemMatchers": [
{
"name": "mywarnings",
"base": "$gcc",
"fileLocation": [
"relative",
"/"
]
}
]
},
In extension.ts you need to provide the tasks. Say we have an array of vscode.Task in tasks you can do:
vscode.tasks.registerTaskProvider('mytask', {
provideTasks: () => {
return tasks;
},
resolveTask(_task: vscode.Task): vscode.Task | undefined {
// as far as I can see from the documentation this just needs to return undefined.
return undefined;
}
});
If you want to create a shell task you need the following:
new vscode.Task (
{type: 'shell'}, // this is the same type as in tasks.json
ws, // The workspace folder
'name', // how you name the task
'MyTask', // Shows up as MyTask: name
new vscode.ShellExecution(command),
["mywarnings"] // list of problem matchers (can use $gcc or other pre-built matchers, or the ones defined in package.json)
);
I hope this helps. The bigges issue I see is the overloading of various names (like type), and that the format in tasks.json is completely different to the way tasks are built with TaskProvider API.

Provide check in RHS for existence of a field inside pojo in drools

I am new to drools.
I want to check in RHS that if a field is present in POJO or not.
{
"category": [
{
"nlp": [
{
"mainCategory": "Politics"
}
],
"crawler": [
{
"isNLP": true,
"mainCategory": "Politics"
}
]
}
]
}
This is list of the pojo that are generated
EsRootDoc.java
Crawler.java
Nlp.java
EsRootDoc is the main class which have methods and fields.`when
$RHSmap1:EsRootDoc()
and
$map1:EsRootDoc($categorylist1:category)
$category2:Category($nlplist2:nlp) from $categorylist1
$nlp2:Nlp(mainCategory=="politics") from $nlplist2
then
$RHSmap1.setEvent("fight");
end`
This is giving me following error
[Error: unable to resolve method using strict-mode: com.orkash.EnrichmentService.EnrichmentController.tempJsonToClass.EsRootDoc.setEvent(java.lang.String)]
[Near : {... $RHSmap1.setEvent("fight"); ....}]
I need to provide a check in RHS :- that if EsRootDoc has a field event or not
There is nothing in Drools (as far as I know) that allows you to do what you are looking for. The RHS of a rule is - almost- pure Java. The basic rule then is: if it can't be done in Java, it can't be done in the RHS of a rule in Drools.
The good news is that what you are trying to do can be achieved in Java using reflection. My recommendation would be for you to create a helper class that uses reflection to set the value of an attribute in an object if that attribute exists. Your rules then would look like this:
rule 'Some Rule'
when
$RHSmap1:EsRootDoc()
$map1:EsRootDoc($categorylist1:category)
$category2:Category($nlplist2:nlp) from $categorylist1
$nlp2:Nlp(mainCategory=="politics") from $nlplist2
then
Helper.setAttribute($RHSmap1, "event", "fight");
end
Hope it helps,