Skip to content

Commit

Permalink
operator: add an operator to query the interval table
Browse files Browse the repository at this point in the history
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
(cherry picked from commit 2256ddf)
  • Loading branch information
masatake committed Dec 11, 2023
1 parent bb2839a commit 6217cee
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 0 deletions.
72 changes: 72 additions & 0 deletions Units/optscript.r/op-intervaltab.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
--sort=no

--langdef=Foo{base=C}{shared}
--fields=+lr
--extras=+r

--kinddef-Foo=r,readhandler,read handlers
--kinddef-Foo=m,method,methods
--_roledef-Foo.m=set,set a handler
--kinddef-Foo=w,writehandler,write handlers
--kinddef-Foo=s,seekhandler,seek handlers
--kinddef-Foo=o,openhandler,open handlers
--kinddef-Foo=R,releasehandler,release handlers

# tag:int
--regex-Foo=/= ([a-z_]*_read),//{postrun}{{
\1 /readhandler _tag _commit dup
_intervaltab {
scope:
} {
pop
} ifelse
}}

# tag:tag
--regex-Foo=/\.([a-z_]+)[ \t]*=//{postrun}{{
\1 /method /set _reftag dup
_intervaltab {
exch _commit exch scope:
} {
_commit
} ifelse
}}

# matchloc
--regex-Foo=/= ([a-z_]*_write),//{postrun}{{
\1 /writehandler _tag _commit
@1 _intervaltab {
scope:
} {
pop
} ifelse
}}

--regex-Foo=/= ([a-z_]*_l?lseek),//{postrun}{{
\1 /seekhandler _tag _commit
1@ _intervaltab {
scope:
} {
pop
} ifelse
}}

# [line:int]
--regex-Foo=/= ([a-z_]*_release),//{postrun}{{
\1 /releasehandler _tag _commit
[ 1@ _matchloc2line ] _intervaltab {
scope:
} {
pop
} ifelse
}}

# [startline:int endline:int]
--regex-Foo=/= ([a-z_]*_open)(,)//{postrun}{{
\1 /openhandler _tag _commit
[ 1@ _matchloc2line @2 _matchloc2line ] _intervaltab {
scope:
} {
pop
} ifelse
}}
25 changes: 25 additions & 0 deletions Units/optscript.r/op-intervaltab.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
proc_pid_cmdline_ops input.c /^static const struct file_operations proc_pid_cmdline_ops = {$/;" v language:C typeref:typename:const struct file_operations file: roles:def
proc_lstats_operations input.c /^static const struct file_operations proc_lstats_operations = {$/;" v language:C typeref:typename:const struct file_operations file: roles:def
proc_single_file_operations input.c /^static const struct file_operations proc_single_file_operations = {$/;" v language:C typeref:typename:const struct file_operations file: roles:def
proc_pid_cmdline_read input.c /^ .read = proc_pid_cmdline_read,$/;" r language:Foo variable:proc_pid_cmdline_ops roles:def
read input.c /^ .read = proc_pid_cmdline_read,$/;" m language:Foo variable:proc_pid_cmdline_ops roles:set
llseek input.c /^ .llseek = generic_file_llseek,$/;" m language:Foo variable:proc_pid_cmdline_ops roles:set
generic_file_llseek input.c /^ .llseek = generic_file_llseek,$/;" s language:Foo variable:proc_pid_cmdline_ops roles:def
open input.c /^ .open = lstats_open,$/;" m language:Foo variable:proc_lstats_operations roles:set
lstats_open input.c /^ .open = lstats_open,$/;" o language:Foo variable:proc_lstats_operations roles:def
seq_read input.c /^ .read = seq_read,$/;" r language:Foo variable:proc_lstats_operations roles:def
read input.c /^ .read = seq_read,$/;" m language:Foo variable:proc_lstats_operations roles:set
write input.c /^ .write = lstats_write,$/;" m language:Foo variable:proc_lstats_operations roles:set
lstats_write input.c /^ .write = lstats_write,$/;" w language:Foo variable:proc_lstats_operations roles:def
llseek input.c /^ .llseek = seq_lseek,$/;" m language:Foo variable:proc_lstats_operations roles:set
seq_lseek input.c /^ .llseek = seq_lseek,$/;" s language:Foo variable:proc_lstats_operations roles:def
release input.c /^ .release = single_release,$/;" m language:Foo variable:proc_lstats_operations roles:set
single_release input.c /^ .release = single_release,$/;" R language:Foo variable:proc_lstats_operations roles:def
open input.c /^ .open = proc_single_open,$/;" m language:Foo variable:proc_single_file_operations roles:set
proc_single_open input.c /^ .open = proc_single_open,$/;" o language:Foo variable:proc_single_file_operations roles:def
seq_read input.c /^ .read = seq_read,$/;" r language:Foo variable:proc_single_file_operations roles:def
read input.c /^ .read = seq_read,$/;" m language:Foo variable:proc_single_file_operations roles:set
llseek input.c /^ .llseek = seq_lseek,$/;" m language:Foo variable:proc_single_file_operations roles:set
seq_lseek input.c /^ .llseek = seq_lseek,$/;" s language:Foo variable:proc_single_file_operations roles:def
release input.c /^ .release = single_release,$/;" m language:Foo variable:proc_single_file_operations roles:set
single_release input.c /^ .release = single_release,$/;" R language:Foo variable:proc_single_file_operations roles:def
21 changes: 21 additions & 0 deletions Units/optscript.r/op-intervaltab.d/input.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Taken from Linux (fs/proc/base.c) */

static const struct file_operations proc_pid_cmdline_ops = {
.read = proc_pid_cmdline_read,
.llseek = generic_file_llseek,
};

static const struct file_operations proc_lstats_operations = {
.open = lstats_open,
.read = seq_read,
.write = lstats_write,
.llseek = seq_lseek,
.release = single_release,
};

static const struct file_operations proc_single_file_operations = {
.open = proc_single_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
82 changes: 82 additions & 0 deletions main/lregex.c
Original file line number Diff line number Diff line change
Expand Up @@ -4229,6 +4229,81 @@ static EsObject *lrop_param (OptVM *vm, EsObject *name)
return false;
}

static EsObject *lrop_intervaltab (OptVM *vm, EsObject *name)
{
EsObject *nobj = opt_vm_ostack_top (vm);
int parent;

if (es_object_get_type (nobj) == ES_TYPE_INTEGER)
{
int index = es_integer_get(nobj);
if (index < 0 || index == CORK_NIL)
return OPT_ERR_RANGECHECK;
parent = queryIntervalTabByCorkEntry (index);
}
else if (es_object_get_type (nobj) == OPT_TYPE_TAG)
{
tagEntryInfo *e = es_pointer_get (nobj);
if (e->extensionFields._endLine)
parent = queryIntervalTabByRange(e->lineNumber,
e->extensionFields._endLine);
else
parent = queryIntervalTabByLine(e->lineNumber);
}
else if (es_object_get_type (nobj) == OPT_TYPE_MATCHLOC)
{
matchLoc *mloc = es_pointer_get (nobj);
parent = queryIntervalTabByLine(mloc->line);
}
else if (es_object_get_type (nobj) == OPT_TYPE_ARRAY)
{
unsigned long start, end;

if (opt_array_length(nobj) == 0)
return OPT_ERR_RANGECHECK;

ptrArray *a = es_pointer_get (nobj);
EsObject *nobj0 = ptrArrayItem (a, 0);
if (es_object_get_type (nobj0) != ES_TYPE_INTEGER)
return OPT_ERR_TYPECHECK;
int n = es_integer_get (nobj0);
if (n <= 0)
return OPT_ERR_RANGECHECK;

start = (unsigned long)n;
if (ptrArrayCount(a) == 1)
parent = queryIntervalTabByLine (start);
else
{
nobj0 = ptrArrayItem (a, 1);
if (es_object_get_type (nobj0) != ES_TYPE_INTEGER)
return OPT_ERR_TYPECHECK;
int n = es_integer_get (nobj0);
if (n <= 0)
return OPT_ERR_RANGECHECK;

end = (unsigned long)n;
if (end < start)
return OPT_ERR_RANGECHECK;
parent = queryIntervalTabByRange (start, end);
}
}
else
return OPT_ERR_TYPECHECK;

opt_vm_ostack_pop (vm);
if (parent == CORK_NIL)
opt_vm_ostack_push (vm, es_false);
else
{
EsObject *parent_obj = es_integer_new (parent);
opt_vm_ostack_push (vm, parent_obj);
opt_vm_ostack_push (vm, es_true);
es_object_unref (parent_obj);
}
return false;
}

static struct optscriptOperatorRegistration lropOperators [] = {
{
.name = "_matchstr",
Expand Down Expand Up @@ -4406,6 +4481,13 @@ static struct optscriptOperatorRegistration lropOperators [] = {
.arity = 2,
.help_str = "tag:int|tag:tag role:name _UNASSIGNROLE -",
},
{
.name = "_intervaltab",
.fn = lrop_intervaltab,
.arity = 1,
.help_str = "tag:int|tag:tag|matchloc|[line:int]|[startline:int endline:int] _INTERVALTAB parent:int true%"
"tag:int|tag:tag|matchloc|[startline:int endline:int] _INTERVALTAB false",
}
};

extern void initRegexOptscript (void)
Expand Down

0 comments on commit 6217cee

Please sign in to comment.