Skip to content

Commit

Permalink
Revert "Allow usage of all caps identifiers in Djinni files (#58)" (#59)
Browse files Browse the repository at this point in the history
This reverts commit 2ec96d3.

Co-authored-by: Li Feng <[email protected]>
  • Loading branch information
finalpatch and li-feng-sc authored Jan 27, 2022
1 parent 2ec96d3 commit 00ea387
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 55 deletions.
23 changes: 4 additions & 19 deletions src/source/generator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,7 @@ package object generatorTools {
if (s.isEmpty) s else ", " + s
}
def q(s: String) = '"' + s + '"'

def leadingUpper(token: String) = {
if (token.isEmpty()) {
token
} else {
val head = token.charAt(0)
val tail = token.substring(1)
// Preserve mixed case identifiers like 'XXFoo':
// Convert tail to lowercase only when it is full uppercase.
if (tail.toUpperCase == tail) {
head.toUpper + tail.toLowerCase
} else {
head.toUpper + tail
}
}
}
def firstUpper(token: String) = if (token.isEmpty()) token else token.charAt(0).toUpper + token.substring(1)

type IdentConverter = String => String

Expand All @@ -147,13 +132,13 @@ package object generatorTools {
enum: IdentConverter, const: IdentConverter)

object IdentStyle {
val camelUpper = (s: String) => s.split("[-_]").map(leadingUpper).mkString
val camelUpper = (s: String) => s.split("[-_]").map(firstUpper).mkString
val camelLower = (s: String) => {
val parts = s.split('_')
parts.head + parts.tail.map(leadingUpper).mkString
parts.head + parts.tail.map(firstUpper).mkString
}
val underLower = (s: String) => s
val underUpper = (s: String) => s.split('_').map(leadingUpper).mkString("_")
val underUpper = (s: String) => s.split('_').map(firstUpper).mkString("_")
val underCaps = (s: String) => s.toUpperCase
val prefix = (prefix: String, suffix: IdentConverter) => (s: String) => prefix + suffix(s)

Expand Down
6 changes: 0 additions & 6 deletions test-suite/djinni/constants.djinni
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,4 @@ constants_interface = interface +c {
# No support for constant binary, list, set, map

dummy();

# An upper-case constant should be parsed correctly
const UPPER_CASE_CONSTANT: string = "upper-case-constant";

# But we should preserve weirdness in casing
const XXXWeird_Case: i32 = 1;
}
3 changes: 0 additions & 3 deletions test-suite/generated-src/cpp/constants_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,4 @@ ConstantRecord const ConstantsInterface::OBJECT_CONSTANT = ConstantRecord(
ConstantsInterface::I32_CONSTANT /* some_integer */ ,
ConstantsInterface::STRING_CONSTANT /* some_string */ );

std::string const ConstantsInterface::UPPER_CASE_CONSTANT = {"upper-case-constant"};


} // namespace testsuite
6 changes: 0 additions & 6 deletions test-suite/generated-src/cpp/constants_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ class ConstantsInterface {

static ConstantRecord const OBJECT_CONSTANT;

/** An upper-case constant should be parsed correctly */
static std::string const UPPER_CASE_CONSTANT;

/** But we should preserve weirdness in casing */
static constexpr int32_t XXXWEIRD_CASE = 1;

/**
* No support for null optional constants
* No support for optional constant records
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ public abstract class ConstantsInterface {
I32_CONSTANT /* mSomeInteger */ ,
STRING_CONSTANT /* mSomeString */ );

/** An upper-case constant should be parsed correctly */
@Nonnull
public static final String UPPER_CASE_CONSTANT = "upper-case-constant";

/** But we should preserve weirdness in casing */
public static final int XXXWEIRD_CASE = 1;

/**
* No support for null optional constants
* No support for optional constant records
Expand Down
4 changes: 0 additions & 4 deletions test-suite/generated-src/objc/DBConstantsInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ extern float const DBConstantsInterfaceF32Constant;
extern double const DBConstantsInterfaceF64Constant;
extern NSString * __nonnull const DBConstantsInterfaceStringConstant;
extern NSString * __nullable const DBConstantsInterfaceOptStringConstant;
/** An upper-case constant should be parsed correctly */
extern NSString * __nonnull const DBConstantsInterfaceUpperCaseConstant;
/** But we should preserve weirdness in casing */
extern int32_t const DBConstantsInterfaceXXXWeirdCase;

/** Interface containing constants */
@interface DBConstantsInterface : NSObject
Expand Down
4 changes: 0 additions & 4 deletions test-suite/generated-src/objc/DBConstantsInterface.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,3 @@
NSString * __nonnull const DBConstantsInterfaceStringConstant = @"string-constant";

NSString * __nullable const DBConstantsInterfaceOptStringConstant = @"string-constant";

NSString * __nonnull const DBConstantsInterfaceUpperCaseConstant = @"upper-case-constant";

int32_t const DBConstantsInterfaceXXXWeirdCase = 1;
4 changes: 0 additions & 4 deletions test-suite/generated-src/ts/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,6 @@ export namespace ConstantsInterface {
someString: STRING_CONSTANT
}
;
/** An upper-case constant should be parsed correctly */
export const UPPER_CASE_CONSTANT = "upper-case-constant";
/** But we should preserve weirdness in casing */
export const XXXWEIRD_CASE = 1;
}

export interface /*record*/ AssortedPrimitives {
Expand Down
2 changes: 0 additions & 2 deletions test-suite/generated-src/wasm/NativeConstantsInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ namespace {
someString: Module.testsuite_ConstantsInterface.STRING_CONSTANT
}
;
Module.testsuite_ConstantsInterface.UPPER_CASE_CONSTANT = "upper-case-constant";
Module.testsuite_ConstantsInterface.XXXWEIRD_CASE = 1;
})
}
void NativeConstantsInterface::staticInitializeConstants() {
Expand Down

0 comments on commit 00ea387

Please sign in to comment.