Language.h revision e28824e0b988221c7eedf8e3d212527d2bdac6a7
1//===-- Language.h ----------------------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_Language_h_
11#define liblldb_Language_h_
12
13#include "lldb/lldb-private.h"
14
15namespace lldb_private {
16
17//----------------------------------------------------------------------
18/// @class Language Language.h "lldb/Core/Language.h"
19/// @brief Encapsulates the programming language for an lldb object.
20///
21/// Languages are represented by an enumeration value.
22///
23/// The enumeration values used when describing the programming language
24/// are the same values as the latest DWARF specification.
25//----------------------------------------------------------------------
26class Language
27{
28public:
29
30    //------------------------------------------------------------------
31    /// Programming language type.
32    ///
33    /// These enumerations use the same language enumerations as the
34    /// DWARF specification for ease of use and consistency.
35    //------------------------------------------------------------------
36    typedef enum
37    {
38        Unknown         = 0x0000,   ///< Unknown or invalid language value.
39        C89             = 0x0001,   ///< ISO C:1989.
40        C               = 0x0002,   ///< Non-standardized C, such as K&R.
41        Ada83           = 0x0003,   ///< ISO Ada:1983.
42        C_plus_plus     = 0x0004,   ///< ISO C++:1998.
43        Cobol74         = 0x0005,   ///< ISO Cobol:1974.
44        Cobol85         = 0x0006,   ///< ISO Cobol:1985.
45        Fortran77       = 0x0007,   ///< ISO Fortran 77.
46        Fortran90       = 0x0008,   ///< ISO Fortran 90.
47        Pascal83        = 0x0009,   ///< ISO Pascal:1983.
48        Modula2         = 0x000a,   ///< ISO Modula-2:1996.
49        Java            = 0x000b,   ///< Java.
50        C99             = 0x000c,   ///< ISO C:1999.
51        Ada95           = 0x000d,   ///< ISO Ada:1995.
52        Fortran95       = 0x000e,   ///< ISO Fortran 95.
53        PLI             = 0x000f,   ///< ANSI PL/I:1976.
54        ObjC            = 0x0010,   ///< Objective-C.
55        ObjC_plus_plus  = 0x0011,   ///< Objective-C++.
56        UPC             = 0x0012,   ///< Unified Parallel C.
57        D               = 0x0013,   ///< D.
58        Python          = 0x0014    ///< Python.
59    } Type;
60
61    //------------------------------------------------------------------
62    /// Construct with optional language enumeration.
63    //------------------------------------------------------------------
64    Language(Language::Type language = Unknown);
65
66    //------------------------------------------------------------------
67    /// Destructor.
68    ///
69    /// The destructor is virtual in case this class is subclassed.
70    //------------------------------------------------------------------
71    virtual
72    ~Language();
73
74    //------------------------------------------------------------------
75    /// Get the language value as a NULL termianted C string.
76    ///
77    /// @return
78    ///     The C string representation of the language. The returned
79    ///     string does not need to be freed as it comes from constant
80    ///     strings. NULL can be returned when the language is set to
81    ///     a value that doesn't match of of the Language::Type
82    ///     enumerations.
83    //------------------------------------------------------------------
84    const char *
85    AsCString (lldb::DescriptionLevel level = lldb::eDescriptionLevelBrief) const;
86
87    void
88    Clear();
89
90    void
91    GetDescription (Stream *s, lldb::DescriptionLevel level) const;
92
93    //------------------------------------------------------------------
94    /// Dump the language value to the stream \a s.
95    ///
96    /// @param[in] s
97    ///     The stream to which to dump the language description.
98    //------------------------------------------------------------------
99    void
100    Dump(Stream *s) const;
101
102    //------------------------------------------------------------------
103    /// Get accessor for the language.
104    ///
105    /// @return
106    ///     The enumeration value that describes the programming
107    ///     language that an object is associated with.
108    //------------------------------------------------------------------
109    Language::Type
110    GetLanguage() const;
111
112    //------------------------------------------------------------------
113    /// Set accessor for the language.
114    ///
115    /// @param[in] language
116    ///     The new enumeration value that describes the programming
117    ///     language that an object is associated with.
118    //------------------------------------------------------------------
119    void
120    SetLanguage(Language::Type language);
121
122    //------------------------------------------------------------------
123    /// Set accessor for the language.
124    ///
125    /// @param[in] language_cstr
126    ///     The language name as a C string.
127    //------------------------------------------------------------------
128    bool
129    SetLanguageFromCString(const char *language_cstr);
130
131
132protected:
133    //------------------------------------------------------------------
134    // Member variables
135    //------------------------------------------------------------------
136    Language::Type m_language; ///< The programming language enumeration value.
137                                 ///< The enumeration values are the same as the
138                                 ///< latest DWARF specification.
139};
140
141//--------------------------------------------------------------
142/// Stream the language enumeration as a string object to a
143/// Stream.
144//--------------------------------------------------------------
145Stream& operator << (Stream& s, const Language& language);
146
147} // namespace lldb_private
148
149#endif  // liblldb_Language_h_
150