bool CheckSpecifier::visit(EnumSpecifierAST *ast) { unsigned sourceLocation = ast->firstToken(); if (ast->name) sourceLocation = ast->name->firstToken(); Name *name = semantic()->check(ast->name, _scope); Enum *e = control()->newEnum(sourceLocation, name); e->setStartOffset(tokenAt(ast->firstToken()).offset); e->setEndOffset(tokenAt(ast->lastToken()).offset); e->setVisibility(semantic()->currentVisibility()); _scope->enterSymbol(e); _fullySpecifiedType.setType(e); for (EnumeratorAST *enumerator = ast->enumerators; enumerator; enumerator = enumerator->next) { Identifier *id = identifier(enumerator->identifier_token); if (! id) continue; NameId *enumeratorName = control()->nameId(id); Declaration *decl = control()->newDeclaration(enumerator->firstToken(), enumeratorName); e->addMember(decl); } accept(ast->next); return false; }
bool CheckSpecifier::visit(ClassSpecifierAST *ast) { unsigned sourceLocation = ast->firstToken(); if (ast->name) sourceLocation = ast->name->firstToken(); Name *className = semantic()->check(ast->name, _scope); Class *klass = control()->newClass(sourceLocation, className); klass->setStartOffset(tokenAt(ast->firstToken()).offset); klass->setEndOffset(tokenAt(ast->lastToken()).offset); ast->symbol = klass; unsigned classKey = tokenKind(ast->classkey_token); if (classKey == T_CLASS) klass->setClassKey(Class::ClassKey); else if (classKey == T_STRUCT) klass->setClassKey(Class::StructKey); else if (classKey == T_UNION) klass->setClassKey(Class::UnionKey); klass->setVisibility(semantic()->currentVisibility()); _scope->enterSymbol(klass); _fullySpecifiedType.setType(klass); for (BaseSpecifierAST *base = ast->base_clause; base; base = base->next) { Name *baseClassName = semantic()->check(base->name, _scope); BaseClass *baseClass = control()->newBaseClass(ast->firstToken(), baseClassName); base->symbol = baseClass; if (base->token_virtual) baseClass->setVirtual(true); if (base->token_access_specifier) { int accessSpecifier = tokenKind(base->token_access_specifier); int visibility = semantic()->visibilityForAccessSpecifier(accessSpecifier); baseClass->setVisibility(visibility); } klass->addBaseClass(baseClass); } int visibility = semantic()->visibilityForClassKey(classKey); int previousVisibility = semantic()->switchVisibility(visibility); int previousMethodKey = semantic()->switchMethodKey(Function::NormalMethod); for (DeclarationAST *member = ast->member_specifiers; member; member = member->next) { semantic()->check(member, klass->members()); } (void) semantic()->switchMethodKey(previousMethodKey); (void) semantic()->switchVisibility(previousVisibility); accept(ast->next); return false; }
void BreakableComment::compressWhitespace(unsigned LineIndex, unsigned TailOffset, Split Split, WhitespaceManager &Whitespaces) { StringRef Text = Content[LineIndex].substr(TailOffset); // Text is relative to the content line, but Whitespaces operates relative to // the start of the corresponding token, so compute the start of the Split // that needs to be compressed into a single space relative to the start of // its token. unsigned BreakOffsetInToken = Text.data() - tokenAt(LineIndex).TokenText.data() + Split.first; unsigned CharsToRemove = Split.second; Whitespaces.replaceWhitespaceInToken( tokenAt(LineIndex), BreakOffsetInToken, CharsToRemove, "", "", /*InPPDirective=*/false, /*Newlines=*/0, /*Spaces=*/1); }
bool Liquid::Parser::look(Token::Type type, size_t ahead) { const Token& token = tokenAt(pos_ + ahead); if (!token.isValid()) { return false; } return token.type() == type; }
bool Liquid::Parser::consumeId(const String& name) { const Token& token = tokenAt(pos_); if (!token.isValid() || token.type() != Token::Type::Id || token.value() != name) { return false; } ++pos_; return true; }
Liquid::StringRef Liquid::Parser::consume(const Token::Type* type) { const Token& token = tokenAt(pos_); if (type && token.type() != *type) { throw syntax_error(String("Expected %1 but found %2").arg(Token::typeToString(*type)).arg(Token::typeToString(token.type()))); } ++pos_; return token.value(); }
bool Liquid::Parser::consume(Token::Type type, StringRef& value) { const Token& token = tokenAt(pos_); if (!token.isValid() || token.type() != type) { return false; } ++pos_; value = token.value(); return true; }
void ASTVisitor::getTokenEndPosition(unsigned index, unsigned *line, unsigned *column) const { getPosition(tokenAt(index).end(), line, column); }
void ASTVisitor::getTokenStartPosition(unsigned index, unsigned *line, unsigned *column) const { getPosition(tokenAt(index).begin(), line, column); }