Skip to content

Commit dedd62c

Browse files
committed
main: implement the setter and getter for parser specific fields defined in an optlib parser
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
1 parent 0be6da1 commit dedd62c

File tree

13 files changed

+244
-49
lines changed

13 files changed

+244
-49
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#LETTER NAME ENABLED LANGUAGE JSTYPE FIXED OP DESCRIPTION
2-
- boolfield no FIELDTEST --b no -- a field having boolean value
2+
- boolfield no FIELDTEST --b no rw a field having boolean value
33
- deffield no FIELDTEST s-- no -- a field that type is not specified
4-
- intfield no FIELDTEST -i- no -- a field having integer value
5-
- strboolfield no FIELDTEST s-b no -- a field having string value or false
6-
- strfield no FIELDTEST s-- no -- a field having string value
4+
- intfield no FIELDTEST -i- no rw a field having integer value
5+
- strboolfield no FIELDTEST s-b no rw a field having string value or false
6+
- strfield no FIELDTEST s-- no rw a field having string value
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#LETTER NAME DESCRIPTION
2-
- datatype=TYPE acceaptable datatype of the field ([str]|bool|int|str+bool)
2+
- datatype=TYPE acceaptable datatype of the field (str|bool|int|str+bool)

Tmain/list-fields-with-prefix.d/stdout-expected.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ x UCTAGSxpath no NONE s-- no -- xpath for
3131
- UCTAGShowImported no Go s-- no -- how the package is imported ("inline" for `.' or "init" for `_')
3232
- UCTAGSpackage yes Go s-- no -- the real package specified by the package name
3333
- UCTAGSpackageName yes Go s-- no -- the name for referring the package
34-
- UCTAGSimplements yes Inko s-- no -- Trait being implemented
34+
- UCTAGSimplements yes Inko s-- no rw Trait being implemented
3535
- UCTAGSassignment yes LdScript s-- no -- how a value is assigned to the symbol
3636
- UCTAGSdefiner yes Lisp s-- no -- the name of the function or macro that defines the unknown/Y-kind object
3737
- UCTAGSsectionMarker no Markdown s-- no -- character used for declaring section(#, ##, =, or -)
3838
- UCTAGSwrapping yes Moose s-- no -- how a wrapper wrapping the method (around, after, or before)
3939
- UCTAGSlangid yes NSIS s-- no -- language identifier specified in (License)LangString commands
4040
- UCTAGScategory yes ObjectiveC s-- no -- category attached to the class
4141
- UCTAGSprotocols yes ObjectiveC s-- no -- protocols that the class (or category) confirms to
42-
- UCTAGShome yes Passwd s-- no -- home directory
43-
- UCTAGSshell yes Passwd s-- no -- login shell
42+
- UCTAGShome yes Passwd s-- no rw home directory
43+
- UCTAGSshell yes Passwd s-- no rw login shell
4444
- UCTAGSdecorators no Python s-- no -- decorators on functions and classes
4545
- UCTAGSnameref yes Python s-- no -- the original name for the tag
4646
- UCTAGSassignmentop no R s-- no -- operator for assignment

Tmain/list-fields.d/stdout-expected.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ z kind no NONE s-- no r- [tags output] prepend "kind:" to k/ (or K/) field outpu
4949
- howImported no Go s-- no -- how the package is imported ("inline" for `.' or "init" for `_')
5050
- package yes Go s-- no -- the real package specified by the package name
5151
- packageName yes Go s-- no -- the name for referring the package
52-
- implements yes Inko s-- no -- Trait being implemented
52+
- implements yes Inko s-- no rw Trait being implemented
5353
- assignment yes LdScript s-- no -- how a value is assigned to the symbol
5454
- definer yes Lisp s-- no -- the name of the function or macro that defines the unknown/Y-kind object
5555
- sectionMarker no Markdown s-- no -- character used for declaring section(#, ##, =, or -)
5656
- wrapping yes Moose s-- no -- how a wrapper wrapping the method (around, after, or before)
5757
- langid yes NSIS s-- no -- language identifier specified in (License)LangString commands
5858
- category yes ObjectiveC s-- no -- category attached to the class
5959
- protocols yes ObjectiveC s-- no -- protocols that the class (or category) confirms to
60-
- home yes Passwd s-- no -- home directory
61-
- shell yes Passwd s-- no -- login shell
60+
- home yes Passwd s-- no rw home directory
61+
- shell yes Passwd s-- no rw login shell
6262
- decorators no Python s-- no -- decorators on functions and classes
6363
- nameref yes Python s-- no -- the original name for the tag
6464
- assignmentop no R s-- no -- operator for assignment

main/field.c

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ static const char* defaultRenderer (const tagEntryInfo *const tag CTAGS_ATTR_UNU
13161316
return renderEscapedString (value, tag, buffer);
13171317
}
13181318

1319-
static bool isValueAvailableGeneric (const tagEntryInfo *const e, const fieldDefinition *fdef)
1319+
extern bool isValueAvailableGeneric (const tagEntryInfo *const e, const fieldDefinition *fdef)
13201320
{
13211321
return getParserFieldValueForType(e, fdef->ftype)? true: false;
13221322
}
@@ -1925,3 +1925,82 @@ static EsObject* setFieldValueForInherits (tagEntryInfo *tag, const fieldDefinit
19251925

19261926
return es_false;
19271927
}
1928+
1929+
extern EsObject* getFieldValueGeneric (const tagEntryInfo *tag, const fieldDefinition *fdef)
1930+
{
1931+
const char *value = getParserFieldValueForType(tag, fdef->ftype);
1932+
unsigned int dt = fdef->dataType;
1933+
1934+
if (dt & FIELDTYPE_STRING)
1935+
{
1936+
if (value == NULL)
1937+
return es_nil;
1938+
return (dt & FIELDTYPE_BOOL && value[0] == '\0')
1939+
? es_false
1940+
: opt_string_new_from_cstr (value);
1941+
}
1942+
else if (dt & FIELDTYPE_INTEGER)
1943+
{
1944+
long tmp;
1945+
1946+
if (value == NULL)
1947+
return es_nil;
1948+
else if (value[0] == '\0')
1949+
tmp = 0;
1950+
else if (!strToLong (value, 10, &tmp))
1951+
tmp = 1;
1952+
1953+
return es_integer_new ((int)tmp);
1954+
}
1955+
else if (dt & FIELDTYPE_BOOL)
1956+
return value? es_true: es_nil;
1957+
else
1958+
{
1959+
AssertNotReached ();
1960+
return es_nil;
1961+
}
1962+
}
1963+
1964+
extern EsObject* setFieldValueGeneric (tagEntryInfo *tag, const fieldDefinition *fdef, const EsObject *obj)
1965+
{
1966+
unsigned int dt = fdef->dataType;
1967+
const char * val;
1968+
char buf[1 /* [+-] */ + 20 + 1 /* for \0 */];
1969+
1970+
if (dt & FIELDTYPE_STRING)
1971+
{
1972+
if (es_object_get_type (obj) == OPT_TYPE_STRING)
1973+
val = opt_string_get_cstr (obj);
1974+
else if ((dt & FIELDTYPE_BOOL) && es_object_equal (es_false, obj))
1975+
val = "";
1976+
else
1977+
return OPT_ERR_TYPECHECK;
1978+
}
1979+
else if (dt & FIELDTYPE_INTEGER)
1980+
{
1981+
int tmp = es_integer_get (obj);
1982+
/* 2^64 => "18446744073709551616" */
1983+
snprintf(buf, sizeof(buf), "%d", tmp);
1984+
val = buf;
1985+
}
1986+
else if (dt & FIELDTYPE_BOOL)
1987+
{
1988+
if (es_boolean_get (obj))
1989+
val = "";
1990+
else
1991+
{
1992+
if (doesFieldHaveValue(fdef->ftype, tag))
1993+
return OPTSCRIPT_ERR_FIELDRESET;
1994+
val = NULL;
1995+
}
1996+
}
1997+
else
1998+
{
1999+
val = "";
2000+
AssertNotReached ();
2001+
}
2002+
2003+
if (val)
2004+
attachParserField (tag, fdef->ftype, val);
2005+
return es_false;
2006+
}

0 commit comments

Comments
 (0)