Commit graph

51 commits

Author SHA1 Message Date
Andreas Kling
70d7fb6a03 LibCpp: Make C++ AST (mostly) const-correct
I cheated and used const_cast to avoid dealing with the strange pattern
where we sometimes do a delayed reparenting of an AST node.
2023-02-21 00:54:04 +01:00
Poseydon42
3cd04f40e1 LibCpp: Parse 'using namespace' declarations
This gets us a little bit closer to a fully capable C++ parser.
2023-01-27 12:40:40 +01:00
Linus Groh
57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +01:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
sin-ack
c8585b77d2 Everywhere: Replace single-char StringView op. arguments with chars
This prevents us from needing a sv suffix, and potentially reduces the
need to run generic code for a single character (as contains,
starts_with, ends_with etc. for a char will be just a length and
equality check).

No functional changes.
2022-07-12 23:11:35 +02:00
sin-ack
3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
2022-07-12 23:11:35 +02:00
Itamar
f4cca20972 LibCpp: Parse inheritance 2022-04-17 10:09:23 +04:30
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Itamar
e9de381607 LibCpp: Don't include parameter type in FunctionType::to_string if null
The type of a function parameter can be null if we failed to parse it.
In such a case, calling to_string() on a FunctionType node used to cause
a null dereference.

This caused the language server to crash when processing
AK/StdLibExtraDetails.h
2022-03-05 15:36:03 +01:00
Itamar
7b42abccf2 LibCpp: Allow qualified names in AST Declaration nodes
Previously, the names of declarations where stored as a simple
StringView.

Because of that, we couldn't parse out-of-line function definitions,
which have qualified names.
For example, we couldn't parse the following snippet:

```
void MyClass::foo(){}
```

To fix this, we now store the name of a declaration with a
ASTNode::Name node, which represents a qualified named.
2022-02-23 00:48:44 +00:00
Ali Mohammad Pur
5f66874ea0 LibCpp: Add support for parsing function types
This makes it work with types like `Function<T(U, V)>`.
2021-08-02 01:03:59 +02:00
Ali Mohammad Pur
3319114127 LibCpp: Add support for parsing reference types 2021-08-02 01:03:59 +02:00
Ali Mohammad Pur
8fefbfd5ac LibCpp: Parse enum members with explicit values 2021-08-02 01:03:59 +02:00
Itamar
34fc6c7e1c LibCpp: Make the fields of AST node types private
Previously almost all fields were public and were directly accessed by
the Parser and CppComprehensionEngine.

This commit makes all fields of AST node types private. They are now
accessed via getters & setters.
2021-07-10 21:58:28 +02:00
Itamar
d7aa831a43 LibCpp: Differentiate between Type and NamedType
This adds a new ASTNode type called 'NamedType' which inherits from
the Type node.

Previously every Type node had a name field, but it was not logically
accurate. For example, pointer types do not have a name
(the pointed-to type may have one).
2021-06-29 00:07:19 +04:30
Andreas Kling
dc65f54c06 AK: Rename Vector::append(Vector) => Vector::extend(Vector)
Let's make it a bit more clear when we're appending the elements from
one vector to the end of another vector.
2021-06-12 13:24:45 +02:00
Itamar
7de6c1489b LibCpp: Parse basic constructors and destructors 2021-06-09 22:26:46 +02:00
Itamar
dcdb0c7035 LibCpp: Support non-field class members
Previously, we had a special ASTNode for class members,
"MemberDeclaration", which only represented fields.

This commit removes MemberDeclaration and instead uses regular
Declaration nodes for representing the members of a class.

This means that we can now also parse methods, inner-classes, and other
declarations that appear inside of a class.
2021-06-09 22:26:46 +02:00
Itamar
b5da0b71e5 LibCpp: Consider declarations inside a function's body
... in FunctionDeclaration::declarations()
2021-06-01 22:20:13 +02:00
Itamar
402483ec1f LibCpp: Generalize ASTNode::dump() to support redirecting its output
Previously, ASTNode::dump() used outln() for output, which meant it
always wrote its output to stdout.

After this commit, ASTNode::dump() receives an 'output' argument (which
is stdout by default). This enables writing the output to somewhere
else.

This will be useful for testing the LibCpp Parser with the output of
ASTNode::dump.
2021-05-19 23:19:07 +02:00
Itamar
f28d944122 LibCpp: Support 'auto' Type 2021-05-19 23:19:07 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Itamar
c6c83bd80e HackStudio+LibCpp: Include class members in Locator 2021-04-13 15:16:27 +02:00
Itamar
9e2e36724d LibCpp: Add TemplatizedName
This type represents templatized names, and replaces our previous use
of 'TemplatizedType' and 'TemplatizedFunctionCall'.

Also, we now parse function calls as secondary expressions.
2021-04-06 21:51:58 +02:00
Itamar
aa717e6a62 LibCpp: Parse C-Style parse expressions 2021-04-06 21:51:58 +02:00
Itamar
ec2c54ee2e LibCpp: Parse "arrow" operator 2021-04-06 21:51:58 +02:00
Itamar
44833f1621 LibCpp: Parse braced initialization list 2021-04-06 21:51:58 +02:00
Itamar
d482b3fd60 LibCpp: Parse empty for loops 2021-04-06 21:51:58 +02:00
Itamar
fc503b1368 LibCpp: Parse sizeof() expression 2021-04-06 21:51:58 +02:00
Itamar
575d6a8ee1 LibCpp: Parse Bitwise & Logical Or & And operators 2021-04-06 21:51:58 +02:00
Itamar
8962581c9c LibCpp: Parse C++ cast expressions
parse static_cast, reinterpret_cast, dynamic_cast & const_cast
2021-04-06 21:51:58 +02:00
Itamar
646aaa111b LibCpp: Support parsing templatized function calls 2021-04-06 21:51:58 +02:00
Itamar
fe4122bbae LibCpp: Support parsing '!=" operator 2021-04-06 21:51:58 +02:00
Itamar
3295609aea LibCpp: Add AST::Name
A Name node is basically an identifier with an optional scope,
e.g Core::File.
2021-04-06 21:51:58 +02:00
Itamar
29b6915db9 LibCpp: Parse templatized types
We can now parse things like Vector<int>
2021-04-06 21:51:58 +02:00
Itamar
9954a1837f LibCpp: Parse nullptr literal 2021-04-06 21:51:58 +02:00
Itamar
cbb49f26d9 LibCpp: Support parsing binary "==" Operator 2021-04-06 21:51:58 +02:00
Itamar
1f9f6ea9d6 LibCpp: Support parsing function qualifiers 2021-04-06 21:51:58 +02:00
Itamar
ee35fc0da3 LibCpp: Support parsing empty return statements 2021-04-06 21:51:58 +02:00
Itamar
68f420ed42 LibCpp: Fix null dereference in IfStatement::declarations() 2021-04-06 21:51:58 +02:00
Itamar
b5cab861e3 LibCpp: Parse Namespace declaration
Also, remove unused State::Context
2021-03-23 18:32:39 +01:00
Andreas Kling
ef1e5db1d0 Everywhere: Remove klog(), dbg() and purge all LogStream usage :^)
Good-bye LogStream. Long live AK::Format!
2021-03-12 17:29:37 +01:00
Itamar
a2ac86f5e1 LibCpp: Check if type is null in VariableDeclaration::dump 2021-03-06 09:40:33 +01:00
Itamar
1d3b5dabc3 LibCpp: Parse ellipsis
We can now parse the printf function declaration :^)
2021-03-02 12:50:37 +01:00
Itamar
5a7abb8363 LibCpp: Parse type qualifiers 2021-03-02 12:50:37 +01:00
Andreas Kling
5d180d1f99 Everywhere: Rename ASSERT => VERIFY
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)

Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.

We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
2021-02-23 20:56:54 +01:00
Andreas Kling
bd830c2dfe LibCpp: Fix yet another broken outln() invocation..
Fixes #5463
2021-02-21 22:13:32 +01:00
Andreas Kling
0bb2729423 LibCpp: Fix busted outln() invocations 2021-02-21 21:32:16 +01:00
Andreas Kling
68406fc0ef LibCpp: Replace dbgprintf() with outln() 2021-02-20 17:12:25 +01:00
Itamar
8ed65d7b48 LibCpp: Parse If statements 2021-02-08 23:10:38 +01:00