Fix parsing of the ::class constant
ClosedPublic

Authored by visscher on Feb 18 2016, 8:28 PM.

Details

Summary

This updates the grammer to recognize the '::class' constant as valid php. This was added in php 5.5 and results in the full qualified class name.

Diff Detail

Lint
Lint Skipped
Unit
Unit Tests Skipped
visscher updated this revision to Diff 2393.Feb 18 2016, 8:28 PM
visscher retitled this revision from to Fix parsing of the ::class constant.
visscher updated this object.
visscher edited the test plan for this revision. (Show Details)
visscher added a reviewer: KDevelop.
mwolff added a subscriber: mwolff.Feb 18 2016, 11:40 PM

can you please also add a unit test for this?

I only found tests for the lexer, where should i add the test?

I'd put it into the expression parser tests (duchain/tests/expressionparser.cpp). I imagine it would then build the test snippet from the PHP documentation:

<?php
namespace NS {
    class ClassName {
    }
}

And then verify that ClassName::class in the NS context, and NS\ClassName::class and \NS\Classname::class all evaluate to a string type.

Sounds good?

visscher updated this revision to Diff 2397.Feb 19 2016, 3:04 PM
visscher set the repository for this revision to R52 KDevelop: PHP Support.

Added unittests

Restricted Application added a subscriber: kdevelop-devel. · View Herald TranscriptFeb 19 2016, 3:04 PM
mwolff requested changes to this revision.Feb 19 2016, 5:09 PM
mwolff added a reviewer: mwolff.

One performance related change, otherwise excellent work! Are you interested in doing more PHP related changes? I'd really welcome mentoring you more in that area - that plugin needs someone who looks after it! If you have any questions, don't hesitate to ask us on our mailing list.

Cheers, and thanks again!

duchain/expressionvisitor.cpp
419 ↗(On Diff #2397)

make it:

if (!stringForNode(node->classConstant).compare(QLatin1String("class"), Qt::CaseInsensitive))

this is much faster as it removes two runtime memory allocations.

This revision now requires changes to proceed.Feb 19 2016, 5:09 PM
visscher updated this revision to Diff 2399.Feb 19 2016, 9:03 PM
visscher edited edge metadata.
visscher removed R52 KDevelop: PHP Support as the repository for this revision.

fixed runtime allocation

Are you interested in doing more PHP related changes? I'd really welcome mentoring you more in that area - that plugin needs someone who looks after it!

I am, but i don't know if i have the time. This bugged me a lot, but i think it is time well spend.

This revision was automatically updated to reflect the committed changes.