One embodiment of the present invention provides a system for associating metadata
attributes with program elements. During operation, the system receives source
code containing syntactic elements that specify metadata attributes for program
elements, wherein the metadata attributes do not affect program execution. The
system then parses the source code to obtain the metadata attributes. Next, the
system associates the metadata attributes with corresponding program elements and
determines values associated with the metadata attributes. Finally, the system
incorporates the metadata attributes, including identifiers for the associated
values and the associated program elements, into object code for the program, thereby
allowing the metadata attributes to be accessed from the object code. Another embodiment
of the present invention provides a system for accessing metadata attributes for
program elements from object code through an application programming interface (API).