Untitled diff
111 lines
%%{
%{
%(license)s
// Copyright (c) 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "%(class_name)s.h"
#include "{{class_name}}.h"
#include "core/css/HashTools.h"
#include "core/css/HashTools.h"
#include <string.h>
#include <string.h>
#include "platform/wtf/ASCIICType.h"
#include "platform/wtf/ASCIICType.h"
#include "platform/wtf/text/AtomicString.h"
#include "platform/wtf/text/AtomicString.h"
#include "platform/wtf/text/WTFString.h"
#include "platform/wtf/text/WTFString.h"
#ifdef _MSC_VER
#ifdef _MSC_VER
// Disable the warnings from casting a 64-bit pointer to 32-bit long
// Disable the warnings from casting a 64-bit pointer to 32-bit long
// warning C4302: 'type cast': truncation from 'char (*)[28]' to 'long'
// warning C4302: 'type cast': truncation from 'char (*)[28]' to 'long'
// warning C4311: 'type cast': pointer truncation from 'char (*)[18]' to 'long'
// warning C4311: 'type cast': pointer truncation from 'char (*)[18]' to 'long'
#pragma warning(disable : 4302 4311)
#pragma warning(disable : 4302 4311)
#endif
#endif
#if defined(__clang__)
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic push
// TODO(thakis): Remove once we use a gperf that no longer produces "register".
// TODO(thakis): Remove once we use a gperf that no longer produces "register".
#pragma clang diagnostic ignored "-Wdeprecated-register"
#pragma clang diagnostic ignored "-Wdeprecated-register"
#endif
#endif
namespace blink {
namespace blink {
static const char propertyNameStringsPool[] = {
static const char propertyNameStringsPool[] = {
%(property_name_strings)s
{% for name in property_names %}
"{{name}}\0"
{% endfor %}
};
};
static const unsigned short propertyNameStringsOffsets[] = {
static const unsigned short propertyNameStringsOffsets[] = {
%(property_name_offsets)s
{% for offset in property_offsets %}
{{offset}},
{% endfor %}
};
};
%%}
%}
%%struct-type
%struct-type
struct Property;
struct Property;
%%omit-struct-type
%omit-struct-type
%%language=C++
%language=C++
%%readonly-tables
%readonly-tables
%%global-table
%global-table
%%compare-strncmp
%compare-strncmp
%%define class-name %(class_name)sHash
%define class-name {{class_name}}Hash
%%define lookup-function-name findPropertyImpl
%define lookup-function-name findPropertyImpl
%%define hash-function-name property_hash_function
%define hash-function-name property_hash_function
%%define slot-name name_offset
%define slot-name name_offset
%%define word-array-name property_word_list
%define word-array-name property_word_list
%%enum
%enum
%%%%
%%
%(property_to_enum_map)s
{{property_to_enum_map}}
%%%%
%%
#if defined(__clang__)
#if defined(__clang__)
#pragma clang diagnostic pop
#pragma clang diagnostic pop
#endif
#endif
const Property* FindProperty(const char* str, unsigned int len) {
const Property* FindProperty(const char* str, unsigned int len) {
return %(class_name)sHash::findPropertyImpl(str, len);
return {{class_name}}Hash::findPropertyImpl(str, len);
}
}
const char* getPropertyName(CSSPropertyID id) {
const char* getPropertyName(CSSPropertyID id) {
DCHECK(isCSSPropertyIDWithName(id));
DCHECK(isCSSPropertyIDWithName(id));
int index = id - firstCSSProperty;
int index = id - firstCSSProperty;
return propertyNameStringsPool + propertyNameStringsOffsets[index];
return propertyNameStringsPool + propertyNameStringsOffsets[index];
}
}
const AtomicString& getPropertyNameAtomicString(CSSPropertyID id) {
const AtomicString& getPropertyNameAtomicString(CSSPropertyID id) {
DCHECK(isCSSPropertyIDWithName(id));
DCHECK(isCSSPropertyIDWithName(id));
int index = id - firstCSSProperty;
int index = id - firstCSSProperty;
static AtomicString* propertyStrings =
static AtomicString* propertyStrings =
new AtomicString[lastUnresolvedCSSProperty]; // Leaked.
new AtomicString[lastUnresolvedCSSProperty]; // Leaked.
AtomicString& propertyString = propertyStrings[index];
AtomicString& propertyString = propertyStrings[index];
if (propertyString.IsNull()) {
if (propertyString.IsNull()) {
propertyString = AtomicString(propertyNameStringsPool +
propertyString = AtomicString(propertyNameStringsPool +
propertyNameStringsOffsets[index]);
propertyNameStringsOffsets[index]);
}
}
return propertyString;
return propertyString;
}
}
String getPropertyNameString(CSSPropertyID id) {
String getPropertyNameString(CSSPropertyID id) {
// We share the StringImpl with the AtomicStrings.
// We share the StringImpl with the AtomicStrings.
return getPropertyNameAtomicString(id).GetString();
return getPropertyNameAtomicString(id).GetString();
}
}
String getJSPropertyName(CSSPropertyID id) {
String getJSPropertyName(CSSPropertyID id) {
char result[maxCSSPropertyNameLength + 1];
char result[maxCSSPropertyNameLength + 1];
const char* cssPropertyName = getPropertyName(id);
const char* cssPropertyName = getPropertyName(id);
const char* propertyNamePointer = cssPropertyName;
const char* propertyNamePointer = cssPropertyName;
if (!propertyNamePointer)
if (!propertyNamePointer)
return g_empty_string;
return g_empty_string;
char* resultPointer = result;
char* resultPointer = result;
while (char character = *propertyNamePointer++) {
while (char character = *propertyNamePointer++) {
if (character == '-') {
if (character == '-') {
char nextCharacter = *propertyNamePointer++;
char nextCharacter = *propertyNamePointer++;
if (!nextCharacter)
if (!nextCharacter)
break;
break;
character = (propertyNamePointer - 2 != cssPropertyName)
character = (propertyNamePointer - 2 != cssPropertyName)
? ToASCIIUpper(nextCharacter) : nextCharacter;
? ToASCIIUpper(nextCharacter) : nextCharacter;
}
}
*resultPointer++ = character;
*resultPointer++ = character;
}
}
*resultPointer = '\\0';
*resultPointer = '\0';
return String(result);
return String(result);
}
}
CSSPropertyID cssPropertyID(const String& string)
CSSPropertyID cssPropertyID(const String& string)
{
{
return resolveCSSPropertyID(unresolvedCSSPropertyID(string));
return resolveCSSPropertyID(unresolvedCSSPropertyID(string));
}
}
} // namespace blink
} // namespace blink