how to get the complete source code location corresponding to the ASTnode in clang - syntax

i am using clang plugin to develop a tool which can insert a 'printf' statemente behind every statement to trace the project.for example:
int main(){
int a=1000;
if(a==1000){
a=999;}
}
insert a 'printf' statemente
int main(){
int a=1000;
printf("int a=1000;");
if(a==1000){
a=999;
printf("a=999;");}
}
i use the structure of the 'printFunctionName' in the clang'example to realize.
i need to get the complete source code location corresponding to the ASTnode so that i can insert the 'printf' statement in the right location.however i found i can't use the Stmt->getSourceRange() function to get the complete location range for some Specific type statement.for example,BinaryOperator,UnaryOperator.
a=1000;
| | | |-BinaryOperator 0x565356502960 <line:13:3, col:5> 'int' '='
| | | | |-DeclRefExpr 0x565356502918 <col:3> 'int' lvalue Var 0x565356502880 'a' 'int'
| | | | `-IntegerLiteral 0x565356502940 <col:5> 'int' 1000
In fact, these characters occupy 5 columns in the source code file, but only 3 columns are recognized.
a++;
-UnaryOperator 0x5653565029b0 <line:14:9, col:10> 'int' postfix '++'
| | | | `-DeclRefExpr 0x565356502988 <col:9> 'int' lvalue Var 0x565356502880 'a' 'int'
this is three chars for 3 column.but clang think it is 2 column.
do you have some idea to solve this problem?and coud you please give me some advices to better recognize the location for a complete sentence end with ';'?thank you!
and this is my code:
SourceRange range=declStmt->getSourceRange();
TheRewriter.ReplaceText(declStmt->getSourceRange(),str+";"+"\nprintf(\""+str+"\\n\")");

Related

Hive - rlike not returning results meeting multiple conditions

I'm looking to return encounters later than 12-17-2020 for each patient involving any of the antibiotics. I'm expecting many results, as querying by one antibiotic at a time shows me. But when I string them together in rlike, it only returns results for one patient for the first antibiotic, amikacin. Is there something wrong in the syntax?
CREATE TABLE tsri.antibiotics AS
SELECT * FROM observation_fact_meds
WHERE start_date > "2020-12-17"
AND encounter_num in (select distinct encounter_num from visit_dimension where patient_num in ('000000', '000001', '000002', '000003', '000004', '000006', '000007') and INOUT_CD in ('Inpatient'))
AND DESCRIPTION rlike ('amikacin| amoxicillin| amoxicillin-clavulanate| Amphotericin B| ampicillin| ampicillin-sulbactam | azithromycin| aztreonam| bacitracin| cefazolin | efepime | cefiderocol| cefotaxime | cefoxitin| ceftaroline| ceftazidime | ceftazidime-avibactam| ceftriaxone | cefuroxime | cephalexin| ciprofloxacin| clarithromycin| clindamycin | Cloxacillin| Cotrimoxazole | dapsone| erythromycin| gentamicin| imipenem| imipenem-cilastatin| isoniazid| lefamulin| levofloxacin| linezolid| meropenem| metronidazole| Nafcillin| Nystatin| penicillin| pentamidine| piperacillin-tazobactam| Piperacillin | rifampin | sulfamethoxazole-trimethoprim | TNF Antimicrobial Med| tobramycin| vancomycin')
Remove the space before pattern - pls put exact string you are looking for a string seperate them only by pipe.
DESCRIPTION rlike ('amikacin|amoxicillin|...

Multiple let statements on the same line in F#

module Digits
type Digit = Unison | Semitone | Tone | MinorThird | MajorThird | PerfectFourth | AugmentedFourth | PerfectFifth | MinorSixth | MajorSixth | MinorSeventh | MajorSeventh type 'd GeneralizedDigit = SmallDigit of 'd | Octave type 't Number = EmptyNumber | CountedNumber of 't * 't Number
let swapOctave: Digit GeneralizedDigit -> Digit GeneralizedDigit = fun x -> match x with SmallDigit Unison -> Octave | Octave -> SmallDigit Unison | g -> g
let limitLength: 'r Number -> Digit = fun a -> match a with EmptyNumber -> Unison | CountedNumber(_,EmptyNumber) -> Semitone | CountedNumber(_,CountedNumber(_,EmptyNumber)) -> Tone | CountedNumber(_,CountedNumber(_,CountedNumber(_,EmptyNumber))) -> MinorThird | _ -> MajorSeventh
In F# I can put multiple type definitions on the same line without semicolons without any problems, but when I remove the newline between the let statements I get the error FS0010. I know that in Haskell statements can be separated by a single semicolon but in F# neither a single semicolon nor a double semicolon will work. How do I have multiple let statements on the same line?
You can do this with the let .. in syntax like so:
let f () = let a = 1 in let b = 2 in a + b
f () // gives 3 as a result
But I would really recommend against doing multiple single-line definitions like this. It's hard for people to read.
If you want multiple let bindings to bound values to variables, then you also can use the "tuple syntax".
let x,y,z = 1, "Hi", 3.0
As explained by Phillip, the let .. in .. construct allows you to define a local variable as part of a one-line expression.
However, your example seems to be trying to define multiple top-level definitions in a module, which is something you cannot achieve with let .. in ...
As far as I can tell, you can actually do this by separating the definitions with two semicolons, i.e. ;;. If I save the following as test.fs and load it using #load, I get no errors:
module Digits
type Digit = Unison | Semitone | Tone | MinorThird | MajorThird | PerfectFourth | AugmentedFourth | PerfectFifth | MinorSixth | MajorSixth | MinorSeventh | MajorSeventh type 'd GeneralizedDigit = SmallDigit of 'd | Octave type 't Number = EmptyNumber | CountedNumber of 't * 't Number
let swapOctave: Digit GeneralizedDigit -> Digit GeneralizedDigit = fun x -> match x with SmallDigit Unison -> Octave | Octave -> SmallDigit Unison | g -> g;; let limitLength: 'r Number -> Digit = fun a -> match a with EmptyNumber -> Unison | CountedNumber(_,EmptyNumber) -> Semitone | CountedNumber(_,CountedNumber(_,EmptyNumber)) -> Tone | CountedNumber(_,CountedNumber(_,CountedNumber(_,EmptyNumber))) -> MinorThird | _ -> MajorSeventh
I tested this in F# 5.0. It may be the case that this has changed in F# 6 which removed deprecated features like #light "off". The removal of ;; is not discussed in the post, but it may have been a related change. If that is the case, you may report it as a regression - but it is likely support for ;; should also be removed!
As mentioned by Phillip, I do not see any reason for actually trying to do this.

SAS PROC FORMAT - Define 'Other' Range for Numeric Variable

I've created a format that assigns a State label to a pre-defined range of Start-End numeric postcodes.
i.e.
Start | End | State
2600 | 2618 | ACT
2900 | 2949 | ACT
4000 | 4899 | QLD
I want to add a piece of code to the format file that assigns it a label "Error" when the postcode falls outside of my range.
In a previous thread, someone suggested using the HLO solution but I have tried implementing it with mixed success.
rsubmit;
data Fmt_State;
set State end=eof;
retain type 'n';
fmtname = 'category';
start = pcode_fr;
end = pcode_to;
label = State;
* For the first observation, assign the ‘LOW’ keyword;
if _n_ eq 1 then HLO='L';
if eof then do;
*** For the last observation, assign the ‘HIGH’ keyword and output;
HLO='H';
output;
*Define an 'Other' range that is outside the bounds of LOW and HIGH;
HLO='O';
label = "Error";
output;
end;
else output;
run;
endrsubmit;
Oddly, only the Middling ranges BETWEEN Low-High that are correctly labelled Error and the ranges outside Low-High that are incorrectly labelled. (I would expect the opposite to be true but still not working the way I want)
For clarity this is what's happening from my same ruleset:
Pcode | ShouldReturn (Reason) | ActuallyReturns
2615 | ACT | ACT
2000 | Error (TooLow) | ACT
2700 | Error (Undefined range) | Error
5000 | Error (Too High) | QLD
I just want anything undefined to be called Error despite it being too low or too high. Please help!
Your logic is incomplete. You want to add three new records.
START END HLO LABEL
. 2600 L Error (Too Low)
4899 . H Error (Too High)
- - O Error (Undefined range)
So you want logic like this:
if _n_=1 then do;
start=.;
end=from;
hlo='L';
label='Error (Too Low)';
output;
end;
start=from;
end=to;
label=state;
hlo=' ';
output;
if eof then do;
end=.;
start = to;
hlo='H';
label='Error (Too High)';
output;
hlo='O';
label='Error (Undefined Range)';
output;
end;

DOORS Compound Filter Dilemma

DOORS Version: 9.5.2.1
I'll try to break this down as simple as I can. First, I'll start with the data. Assume I have a module, Module, in DOORS. Module is comprised of:
Tree Structure
Assume that Object Text for headings and sub-headings are blank, and assume Object Text for the remaining Level 3 objects is the same as the name of the object itself. For example, Object Heading is blank for Object_1.1.0-1, but its Object Text is "Object_1.1.0-1".
- Module
- 1 Heading1 // Object Heading: "Heading1" ; Object Number: 1
| - 1.1 Sub-Heading1.1 // Object Heading: "Sub-Heading1.1" ; Object Number: 1.1
| | + Object_1.1.0-1 // Object Heading: "" ; Object Number: 1.1.0-1
| | + Object_1.1.0-2 // Object Heading: "" ; Object Number: 1.1.0-2
| | | .
| | | .
| | | .
| | + Object_1.1.0-A // Object Heading: "" ; Object Number: 1.1.0-A
| |
| - 1.2 Sub-Heading1.2 // Object Heading: "Sub-Heading1.2" ; Object Number: 1.2
| + Object_1.2.0-1 // Object Heading: "" ; Object Number: 1.2.0-1
| + Object_1.2.0-2 // Object Heading: "" ; Object Number: 1.2.0-2
| | .
| | .
| | .
| + Object_1.2.0-B // Object Heading: "" ; Object Number: 1.2.0-B
|
- 2 Heading2 // Object Heading: "Heading2" ; Object Number: 2
- 2.1 Sub-Heading2.1 // Object Heading: "Sub-Heading2.1" ; Object Number: 2.1
| + Object_2.1.0-1 // Object Heading: "" ; Object Number: 2.1.0-1
| + Object_2.1.0-2 // Object Heading: "" ; Object Number: 2.1.0-2
| | .
| | .
| | .
| + Object_2.1.0-C // Object Heading: "" ; Object Number: 2.1.0-C
|
- 2.2 Sub-Heading2.1 // Object Heading: "Sub-Heading2.1" ; Object Number 2.2
+ Object_2.2.0-1 // Object Heading: "" ; Object Number: 2.2.0-1
+ Object_2.2.0-2 // Object Heading: "" ; Object Number: 2.2.0-2
| .
| .
| .
+ Object_2.2.0-D // Object Heading: "" ; Object Number: 2.2.0-D
And so on and so forth . . .
Attributes
*Object Heading and Text*, Version, Data
Object Heading and Text seems to be a DOORS thing, so I won't explain that here. Data here is generic (and, in reality, represents more than one attribute). Some data is applicable to some versions while other data is applicable to other versions. The data for different versions may intersect while some data for other versions are mutually exclusive. Version is a single string that delimits the different versions by new lines, "\n". So, let's assume that Version is:
v1\nv2\nv3 . . . v\nvX
or, in a more readable format:
v1
v2
v3
.
.
.
vX
What's more, Version for one object may be (comma-separated here for readability) v1, v2, v3, . . ., vX while for another it might be v1, v3 and for another perhaps just v2. Any combination of available versions, really.
The Problem
What I'm attempting to do seems to me like it should be easy. A no-brainer. Just to pick an example, let's say I want to apply a filter whereby I view only Sub-Heading1.2 and its children, and that only for Version v3. I've tried many variations on the theme, but I can only seem to accomplish one or the other. Either I successfully isolate data for a single section or a single version, but I cannot get both. When I apply a filter for a single section, say Sub-Heading1.2 and its children, and then AND that with "includes v3"; I will get that section, but it refuses to show only that section only for v3.
In any programming language, a and b and c evaluates to true IF AND ONLY IF a and b and c. What I'm seeing in DOORS seems to me to be more like (a and b) or c.
With a DOORS database described as above, how can I view only the objects in a given range (or an object and its descendants) only for a given version? I know DXL exists as a potential solution, but a GUI solution is preferable.
Your issue is Include Descendants. This options specifically ignores the filter. What it is really saying is, "Show me everything that matches my filter, and all of their descendants".
Using your example above, what you want for a filter is:
Object Number >= 1.2
and
Object Number < 2 (or maybe 1.3 depending on how you want it)
and
Version includes v3
This will give you what you are looking for. Be sure NOT to Include Descendants as this will negate the second rule in the filter.
Good luck!

Xtext grammar QualifiedName ambiguity

I have the following problem. Part of my grammar looks like this
RExpr
: SetOp
;
SetOp returns RExpr
: PrimaryExpr (({Union.left=current} '+'|{Difference.left=current} '-'|{Intersection.left=current} '&') right = PrimaryExpr)*
;
PrimaryExpr returns RExpr
: '(' RExpr ')'
| (this = 'this.')? slot = [Slot | QualifiedName]
| (this = 'this' | ensName = [Ensemble | QualifiedName])
| 'All'
;
When generating Xtext artifacts ANTLR says that due to some ambiguity it disables an option(3). The ambiguity is because of QualifiedName slot and ensemble share. How do I refactor this kind of cases? I guess syntactic predicate wont help here since it'll force only one(Slot/Ensemble) to be resolved only.
Thanks.
Xtext can't choose between your two references slot and ensemble.
You can merge these references into one reference by adding this rule to your grammar:
SlotOrEnsemble:
Slot | Ensemble
;
Then your primaryExpr rule will be something like:
PrimaryExpr returns RExpr
: '(' RExpr ')'
| ((this = 'this.')? ref= [SlotOrEnsemble | QualifiedName])
| this = 'this'
| 'All'
;

Resources