summaryrefslogtreecommitdiff
path: root/srcpos.h
Commit message (Collapse)AuthorAgeFilesLines
* dtc: Replace GPLv2 boilerplate/reference with SPDX tagsRob Herring2019-06-211-15/+1
| | | | | | | | Replace instances of GPLv2 or later boilerplate with SPDX tags. Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20190620211944.9378-2-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* annotations: add the annotation functionalityJulia Lawall2018-11-191-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Provide the new command-line option: --annotate (abbreviated -T) --annotate provides one or more filenames and line numbers indicating the origin of a given line. The filename is expressed relative the the filename provided on the command line. Nothing is printed for overlays, etc. -T can be repeated giving more verbose annotations. These consist of one or more tuples of: filename, starting line, starting column, ending line ending column. The full path is given for the file name. Overlays, etc are annotated with <no-file>:<no-line>. The verbose annotations may be too verbose for normal use. There are numerous changes in srcpos.c to provide the relative filenames (variables initial_path, initial_pathlen and initial_cpp, new functions set_initial_path and shorten_to_initial_path, and changes in srcfile_push and srcpos_set_line). The change in srcpos_set_line takes care of the case where cpp is used as a preprocessor. In that case the initial file name is not the one provided on the command line but the one found at the beginnning of the cpp output. shorten_to_initial_path only returns a string if it has some shortening to do. Otherwise it returns NULL and relies on the caller to use the initial string. This simplifies memory management, by making clear to the caller whether a new string is allocated. The new functions srcpos_string_comment, srcpos_string_first, and srcpos_string_last print the annotations. srcpos_string_comment is recursive to print a list of source file positions. Various changes are sprinkled throughout treesource.c to print the annotations. Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* annotations: add positionsJulia Lawall2018-11-191-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Extend the parser to record positions, in build_node, build_node_delete, and build_property. srcpos structures are added to the property and node types, and to the parameter lists of the above functions that construct these types. Nodes and properties that are created by the compiler rather than from parsing source code have NULL as the srcpos value. merge_nodes, defined in livetree.c, uses srcpos_extend to combine multiple positions, resulting in a list of positions. srcpos_extend is defined in srcpos.c. New elements are added at the end. This requires the srcpos type, define in srcpos.h, to be a list structure with a next field. This next field is initialized to NULL in srcpos.h, in the macro YYLLOC_DEFAULT invoked implicitly by the generated parser code. Another change to srcpos.c is to make srcpos_copy always do a full copy, including a copy of the file substructure. This is required because when dtc is used on the output of cpp, the successive detected file names overwrite the file name in the file structure. The next field does not need to be deep copied, because it is always NULL when srcpos_copy is called; an assert checks for this. File names are only updated in uncopied position structures. Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* srcpos: Remove srcpos_emptyDavid Gibson2018-11-141-7/+0
| | | | | | Nothing was actually using it. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Revert "annotations: add positions"David Gibson2018-11-141-3/+0
| | | | | | | | | This reverts commit baa1d2cf7894a32bf2f640ef40ebce561b2df565. Turns out this introduced memory badness. valgrind picks it up on x86, but it straight out SEGVs on x86. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* annotations: add positionsJulia Lawall2018-11-131-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | Extend the parser to record positions, in build_node, build_node_delete, and build_property. srcpos structures are added to the property and node types, and to the parameter lists of the above functions that construct these types. Nodes and properties that are created by the compiler rather than from parsing source code have NULL as the srcpos value. merge_nodes, defined in livetree.c, uses srcpos_extend to combine multiple positions, resulting in a list of positions. srcpos_extend is defined in srcpos.c. New elements are added at the end. The srcpos type, define in srcpos.h, is now a list structure with a next field. Another change to srcpos.c is to make srcpos_copy always do a full copy, including a copy of the file substructure. This is required because when dtc is used on the output of cpp, the successive detected file names overwrite the file name in the file structure. The next field does not need to be deep copied, because it is only updated in newly copied positions and the positions to which it points have also been copied. File names are only updated in uncopied position structures. Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Remove leading underscores from identifiersDavid Gibson2017-10-261-3/+3
| | | | | | | | | | | | | | In a number of places, dtc and associated tools and test code use leading _ characters on identifiers to flag them as "internal", an idiom taken from the Linux kernel. This is a bad idea in a userspace program, because identifiers with a leading _ are reserved for the C library / system. In some cases, the extra _ served no real purpose, so simply drop it. In others move to the end of the identifier, which is a convention we're free to use for our own purposes. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Clean up gcc attributesDavid Gibson2017-03-061-6/+5
| | | | | | | | We have a number of explicit __GNUC__ conditionals to tell if we want to use some gcc extensions for extra warnings. This cleans this up to use a single conditional, defining convenience macros for those attributes. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Remove unused srcpos_dump() functionDavid Gibson2016-07-131-1/+0
| | | | | | | srcpos_dump() has no current users, and I have no plans to use it. So remove it. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Make srcpos_{v,}error() more widely usefulDavid Gibson2014-01-011-4/+6
| | | | | | | Allow them to take a prefix argument giving the general type of error, which will be useful in future. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Fix typo in type of srcpos_verror() et al.David Gibson2014-01-011-2/+2
| | | | | | | The srcpos_verror() and srcpos_error() functions declare the format string as 'char const *' instead of 'const char *'. Fix it. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Remove unused srcpos_warn() functionDavid Gibson2014-01-011-2/+0
| | | | | | This function has no users, and we can replace it more generally later. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Use stdbool more widelyDavid Gibson2013-10-281-1/+2
| | | | | | | | We already use the C99 bool type from stdbool.h in a few places. However there are many other places we represent boolean values as plain ints. This patch changes that. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: cpp co-existence: add support for #line directivesStephen Warren2012-09-281-0/+2
| | | | | | | | | | | | | | Line control directives of the following formats are supported: #line LINE "FILE" # LINE "FILE" [FLAGS] This allows dtc to consume the output of pre-processors, and to provide error messages that refer to the original filename, including taking into account any #include directives that the pre-processor may have performed. Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: Add -i option to support search pathsSimon Glass2012-03-181-0/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It is often inconvenient to place device tree files in the same directory as their includes, or to specify the full path to include files. An example of this is in U-Boot where we have a .dtsi file for each SOC type, and this is included by the board .dts file. We need to either use a mechanism like: /include/ ARCH_CPU_DTS with sed or cpp to perform the replacement with the correct path, or we must specify the full path in the file: /include/ "../../arch/arm/dts/tegra20.dtsi" The first option is not desirable since it requires anyone compiling the file to first pre-process it. The second is not desirable since it introduces a path which is project-specific into a file which is supposed to be a hardware description. For example Linux and U-Boot are unlikely to put these include files in the same place. It is much more convenient to specify the search patch on the command line as is done with C pre-processors, for example. Introduce a -i option to add to the list of search paths used to find source and include files. We cannot use -I as it is already in use. Other suggestions welcome. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtc: Implement -d option to write out a dependency fileStephen Warren2012-01-131-0/+1
| | | | | | | | This will allow callers to rebuild .dtb files when any of the /include/d .dtsi files are modified, not just the top-level .dts file. Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: David Gibson <david@gibson.dropbear.id.au>
* Create new and use new print_error that uses printf style formatting.John Bonesio2010-10-201-0/+2
| | | | | | | | | | | | yyerror is meant to be called by the parser internal code, and it's interface is limited. Instead create and call a new error message routine that allows formatted strings to be used. yyerror uses the new routine so error formatting remains consistent. Signed-of-by: John Bonesio <bones@secretlab.ca> Acked-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
* dtc: Cleanup YYLTYPE and YYLLOC_DEFAULT declarationsDavid Gibson2010-01-141-45/+27
| | | | | | | | | | | | | | | | | | | | This patch makes some small cleanups to the declaration of YYLTYPE, YYLLOC_DEFAULT and related things. - We used to use undocumented magic #defines for bison, YYLTYPE_IS_DECLARED and YYLTYPE_IS_TRIVIAL. This may not be portable across bison versions. Instead define YYLTYPE as a macro in terms of struct srcpos, as the info pages suggest. - Our kernel-derived coding style discourages typedefed structures. So use 'struct srcpos' instead of 'srcpos' throughout'. - Indent the YYLLOC_DEFAULT macro according to our coding style (it was in GNU indent style, since it was taken from the example in the bison info). Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: Cleanup line number tracking, add column number trackingDavid Gibson2010-01-141-1/+2
| | | | | | | | | | | | | | | | | | Our YYLTYPE current carries around first and last line and first and last column information. However, of these, on the first line information is actually filled in properly. Furthermore, filling in the line number information from yylineno is kind of clunky: we have to copy its value to the srcfile stack and back to handle include file positioning correctly. This patch cleans this up. We turn off flex's yylineno option and instead track the line and column number ourselves from YY_USER_ACTION. The line and column number are stored directly inside the srcfile_state structure, so it's automatically a per-file quantity. We now also fill in all the yylloc from YY_USER_ACTION. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: Simpler interface to source file managementDavid Gibson2010-01-141-15/+12
| | | | | | | | | | | | | | | | | | | | | | | | This patch cleans up our handling of input files, particularly dts source files, but also (to an extent) other input files such as those used by /incbin/ and those used in -I dtb and -I fs modes. We eliminate the current clunky mechanism which combines search paths (which we don't actually use at present) with the open relative to current source file behaviour, which we do. Instead there's a single srcfile_relative_open() entry point for callers which opens a new input file relative to the current source file (which the srcpos code tracks internally). It doesn't currently do search paths, but we can add that later without messing with the callers, by drawing the search path from a global (which makes sense anyway, rather than shuffling it around the rest of the processing code). That suffices for non-dts input files. For the actual dts files, srcfile_push() and srcfile_pop() wrappers open the file while also keeping track of it as the current source file for future opens. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Enhance source position implementation.Jon Loeliger2008-10-031-2/+21
| | | | | | | | | Implemented some print and copy routines. Made empty srcpos objects that will be used later. Protected .h file from multiple #include's. Added srcpos_error() and srcpos_warn(). Signed-off-by: Jon Loeliger <jdl@freescale.com>
* dtc: Remove ugly include stack abuseDavid Gibson2008-03-231-3/+0
| | | | | | | | | | | | | | | | | | Currently, dt_from_source() uses push_input_file() to set up the initial input file for the lexer. That sounds sensible - put the outermost input file at the bottom of the stack - until you realise that what it *actually* does is pushes the current, uninitialized, lexer input state onto the stack, then sets up the new lexer input. That necessitates an extra check in pop_input_file(), rather than signalling termination in the natural way when the include stack is empty, it has to check when it pops the bogus uninitialized state off the stack. Ick. With that fixed, push_input_file(), pop_input_file() and incl_file_stack itself become local to the lexer, so make them static. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: Fix error reporting in push_input_file()David Gibson2008-03-231-1/+1
| | | | | | | | | | | | | | Error reporting in push_input_file() is a mess. One error results in a message and exit(1), others result in a message and return 0 - which is turned into an exit(1) at one callsite. The other callsite doesn't check errors, but probably should. One of the error conditions gives a message, but can only be the result of an internal programming error, not a user error. So. Clean that up by making push_input_file() a void function, using die() to report errors and quit. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Remove const from dtc_file::dir.Scott Wood2008-01-111-1/+1
| | | | Signed-off-by: Scott Wood <scottwood@freescale.com>
* Look for include files in the directory of the including file.Scott Wood2008-01-041-8/+20
| | | | | | | | | | | Looking in the diretory dtc is invoked from is not very useful behavior. As part of the code reorganization to implement this, I removed the uniquifying of name storage -- it seemed a rather dubious optimization given likely usage, and some aspects of it would have been mildly awkward to integrate with the new code. Signed-off-by: Scott Wood <scottwood@freescale.com>
* Add yyerrorf() for formatted error messages.Scott Wood2008-01-041-0/+1
| | | | Signed-off-by: Scott Wood <scottwood@freescale.com>
* dtc: move declaration of yyerrorMilton Miller2007-07-071-0/+1
| | | | | | | yyerror() is used by both dtc-parser.y and dtc-lexer.l, so move the declaration to srcpos.h. Signed-off-by: Milton Miller <miltonm@bga.com>
* DTC: Incorporate some review suggestions.Jon Loeliger2007-03-281-2/+5
| | | | | | | | | | | - Change include syntax to: /include/ "filename" - Move private functions directly into dtc-lexer.l - Define YYID for some older parser templates Also fix a #include ordering problem around YYLTPE. Signed-off-by; Jon Loeliger <jdl@freescale.com> Acked-by: Haiying Wang <Haiying.Wang@freescale.com>
* DTC: Add support for a C-like #include "file" mechanism.Jon Loeliger2007-03-261-0/+71
Keeps track of open files in a stack, and assigns a filenum to source positions for each lexical token. Modified error reporting to show source file as well. No policy on file directory basis has been decided. Still handles stdin. Tested on all arch/powerpc/boot/dts DTS files Signed-off-by: Jon Loeliger <jdl@freescale.com>