How to get the details of DeclRefExpr from VarDecl in clang? - clang

My ast node looks like this:
|-VarDecl 0x158f5190 <line:7:1, col:14> col:6 used ptr1 'int *' cinit
| |-UnaryOperator 0x158f62c0 <col:13, col:14> 'int *' prefix '&' cannot overflow
| | `-DeclRefExpr 0x158f62a0 col:14 'int' lvalue Var 0x158f50f0 'foo' 'int'
How can I get the address and name of 'foo' from VarDecl?
I have used DeclContext::decl_iterator to iterate through all the nodes and I can dump the entire VarDecl. I am interested in extracting information from DeclRefExpr with VarDecl.

Related

Small Shift/Reduce conflict in CUP

I'm having a minor problem in trying to figure out how to resolve a conflict in my CUP parser project. I understand why the error is occurring, VariableDeclStar's first terminal can be ID, as well as Type, which brings up the conflict, however I cannot figure out how to resolve the conflict in a way that would preserve Type and Variable as separate states. Any help or tips would be appreciated.
VariableDecl ::= Variable SEMICOLON {::};
Variable ::= Type ID {::};
Type ::= INT {::}
| DOUBLE {::}
| BOOLEAN {::}
| STRING {::}
| Type LEFTBRACKET RIGHTBRACKET {::}
| ID {::};
VariableDeclStar::= VariableDecl VariableDeclStar {::}
| {::};
https://i.gyazo.com/0ac3fbf4ebc2d3968f1c2a78c292bc0d.png

How to use message headers in RabbitMQ's Erlang client?

I'm trying to send a message with metadata through the Erlang client, and I can't understand how should I set custom application headers in the message's basic properties record. I've tried all these options with no success:
#'P_basic'{headers = [{<<"key">>, <<"value">>}]}
#'P_basic'{headers = [{"key", <<"value">>}]}
#'P_basic'{headers = [{key, <<"value">>}]}
It seems that headers use some special data structure, an AMQP table - but I couldn't find any documentation or examples on this matter.
What is a correct way to send a message with headers?
Update: A stack trace (actually, it's not relevant - the cause of that error is the silently closed channel) and the source code.
Do you get any errors trying to send messages with headers?
Did you try to use string type for both key and value?
#'P_basic'{headers = [{"key", "value"}]}
Update: I investigated the source code of the package rabbit_common and I found out something about headers' type. There is a type headers() in rabbit_basic.erl:
-type(headers() :: rabbit_framing:amqp_table() | 'undefined').
And there are definition of the types in module rabbit_framing_amqp:
-type(amqp_field_type() ::
'longstr' | 'signedint' | 'decimal' | 'timestamp' |
'table' | 'byte' | 'double' | 'float' | 'long' |
'short' | 'bool' | 'binary' | 'void' | 'array').
-type(amqp_property_type() ::
'shortstr' | 'longstr' | 'octet' | 'shortint' | 'longint' |
'longlongint' | 'timestamp' | 'bit' | 'table').
-type(amqp_table() :: [{binary(), amqp_field_type(), amqp_value()}]).
-type(amqp_array() :: [{amqp_field_type(), amqp_value()}]).
-type(amqp_value() :: binary() | % longstr
integer() | % signedint
{non_neg_integer(), non_neg_integer()} | % decimal
amqp_table() |
amqp_array() |
byte() | % byte
float() | % double
integer() | % long
integer() | % short
boolean() | % bool
binary() | % binary
'undefined' | % void
non_neg_integer() % timestamp
).
So the header is a tuple of three items (not two), which are binary, type of value, value. So you have to define each header the way like that:
BooleanHeader = {<<"my-boolean">>, bool, true}.
StringHeader = {<<"my-string">>, longstr, <<"value">>}.
IntHeader = {<<"my-int">>, long, 1000}.

implicit declaration in parsing rule warning antlrworks 2

I always get implicit declaration in parsing rule warning, when coding all examples from antlr v4 inside antlrworks 2. for my simple rule like :
type
: 'Integer'
| 'Character'
| 'Real'
| 'String'
| 'Short'
| 'Long'
| 'Double'
| 'Signed'
| 'Unsigned'
| 'Boolean'
| structTag
| enumTag
| declarator
;
Can anybody give me solution that warning, at last solution for example above.
thank
The warning is to inform you that you will have no way in code to know if your type is an identifier, character, real, etc., because you have not assigned named token types to the corresponding tokens. You can resolve this warning by creating named lexer rules for each of your tokens:
INTEGER : 'Integer';
CHARACTER : 'Character';
You do not have to change the type rule after adding these new definitions, but after adding the definitions you will be able to check if a token type is INTEGER or CHARACTER as part of your parser result handling code.

SML datatypes struggle

I have the following grammar that I need to translate into SML datatypes:
Integer ranges over SML integer constants.
Boolean ::= 'true' | 'false'
Operator ::= 'ADD' | 'IF' | 'LESS_THAN'
Arguments ::= ( ',' Expression ) *
Expression ::= 'INT' '(' Integer ')'
| 'BOOL' '(' Boolean ')'
| 'OPERATION' '(' Operator ',' '[' Expression ( ',' Expression ) * ']' ')'
I have managed the following:
datatype BOOL = true | false;
datatype OPERATOR = ADD | IF | LESS_THAN;
datatype INT = INT of int;
However I am struggling with datatypes Arguments and Expression. Any help would be appreciated.
for ARGUMENTS, you can use a sequence of EXPRESSIONs, so something like a list of EXPRESSION would work fine (the parentheses need to be parsed, but you don't need to store them in your type, since they are always there).
for EXPRESSION, you need to combine the approach you've used in OPERATOR (where you have alternatives) with what you've done in INT (where you have of ...). in otherwords it's going to be of the form A of B | C of D | ....
also, you don't really need INT of int - you could just use an simple int (ie an integer) for INT - and i suspect ML has a boolean type that could use instead of defining a datatype for BOOL (in other words, you probably don't need to define a datatype at all for either of those - just use what is already present in the language).
ps it's also normal to add the "homework" tag for homework.
[edit for OPERATOR you have multiple types, but that's ok - just stick them in a tuple, like (A,B) whose type is written a * b. for the sequence of expressions, use a list, like for ARGUMENTS.]

Antlr non-LL(*) decision

I'm having some trouble creating part of my ANTLR grammar for my programming language.
I'm getting the error when the second part of the type declaration occurs:
public type
: ID ('.' ID)* ('?')? -> ^(R__Type ID ID* ('?')?)
| '(' type (',' type)* ')' ('?')? -> ^(R__Type type* ('?')?)
;
I'm trying to either match:
A line like System.String (works fine)
A tuple such as (System.String, System.Int32)
The error occurs slightly higher up the tree, and states:
[fatal] rule statement has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2. Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
What am I doing wrong?
Right, I managed to fix this a little earlier up the tree, by editing the rule that deals with variable declarations:
'my' ID (':' type '=' constant | ':' type | '=' constant) -> ^(R__VarDecl ID type? constant?)
So that it works like:
'my' ID
(
':' type ('=' constant)?
| '=' constant
) -> ^(R__VarDecl ID type? constant?)
I got the idea from the example of syntactic predicates here:
https://wincent.com/wiki/ANTLR_predicates
Luckily I didn't need a predicate in the end!

Resources