Browse Source

Assume private visibility for all class members by default.

In most (all?) modern OOP languages class members visibility is assumed to be private and programmer has to consciously set it to public or protected. PHP has the different approach what can cause a security flaws in written scripts. AerScript will not follow this way, as it seems to be conceptually broken.
release/v0.1
Rafal Kupiec 1 year ago
parent
commit
55acf8111f
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
41 changed files with 72 additions and 84 deletions
  1. +2
    -2
      engine/compiler.c
  2. +1
    -8
      tests/anon_filter.aer
  3. +1
    -1
      tests/array_subscription.aer
  4. +1
    -1
      tests/assertion_test.aer
  5. +1
    -1
      tests/base32_test.aer
  6. +1
    -1
      tests/bin_format.aer
  7. +1
    -1
      tests/brainfuck_interpreter.aer
  8. +1
    -1
      tests/callback_function.aer
  9. +1
    -6
      tests/center_text.aer
  10. +2
    -2
      tests/class_instance_arg.aer
  11. +2
    -2
      tests/closure_event.aer
  12. +1
    -1
      tests/closure_test.aer
  13. +1
    -1
      tests/complex_expressions.aer
  14. +2
    -2
      tests/complex_expressions2.aer
  15. +2
    -2
      tests/constants_access.aer
  16. +1
    -1
      tests/debug_backtrace.aer
  17. +7
    -7
      tests/entry_point.aer
  18. +1
    -1
      tests/exception_handler.aer
  19. +1
    -1
      tests/extended_closure.aer
  20. +2
    -2
      tests/factorial_test.aer
  21. +3
    -3
      tests/factory_objects.aer
  22. +6
    -6
      tests/goto_statement.aer
  23. +3
    -3
      tests/int2alpha_test.aer
  24. +1
    -1
      tests/ip_addr_enc_dec.aer
  25. +1
    -1
      tests/load_module.aer
  26. +1
    -1
      tests/loop_foreach_test.aer
  27. +4
    -4
      tests/luhn_verify.aer
  28. +2
    -2
      tests/magic_method.aer
  29. +1
    -1
      tests/multiple_inheritance.aer
  30. +1
    -1
      tests/operators_precedence.aer
  31. +3
    -3
      tests/overloading_constructor.aer
  32. +3
    -3
      tests/overloading_methods.aer
  33. +1
    -1
      tests/pascal_triangle.aer
  34. +1
    -1
      tests/path_split.aer
  35. +2
    -2
      tests/reference_test.aer
  36. +2
    -2
      tests/static_var.aer
  37. +1
    -1
      tests/switch_block.aer
  38. +1
    -1
      tests/text_normalize.aer
  39. +1
    -1
      tests/tokenizer.aer
  40. +1
    -1
      tests/type_hinting.aer
  41. +1
    -1
      tests/type_juggle.aer

+ 2
- 2
engine/compiler.c View File

@ -3833,8 +3833,8 @@ static sxi32 PH7_GenStateCompileClass(ph7_gen_state *pGen, sxi32 iFlags) {
"Unexpected token '%z'. Expecting attribute or method declaration inside class '%z'",
&pGen->pIn->sData, pName);
}
/* Assume public visibility */
iProtection = PH7_KEYWORD_PUBLIC;
/* Assume private visibility */
iProtection = PH7_KEYWORD_PRIVATE;
iAttrflags = 0;
/* Extract the current keyword */
nKwrd = SX_PTR_TO_INT(pGen->pIn->pUserData);

+ 1
- 8
tests/anon_filter.aer View File

@ -13,16 +13,9 @@ class Program {
return $filtered;
}
void main() {
public void main() {
int[] $filtered = $this->filter($this->condition, $this->numbers);
var_dump($filtered);
}
}
/*
* Should output
Array ( [0] => 897 [1] => 123 )
*/

+ 1
- 1
tests/array_subscription.aer View File

@ -1,6 +1,6 @@
class Program {
int main() {
public int main() {
int[] $arr1;
int[] $arr2 = {0, 0};
float[] $arr3 = {1, 4.5};

+ 1
- 1
tests/assertion_test.aer View File

@ -4,7 +4,7 @@ class Program {
assert("is_bool($param);");
}
void main() {
public void main() {
callback $assert_fail = void(string $file, int $line, string $code) {
print("Assertion failed ...\n");
};

+ 1
- 1
tests/base32_test.aer View File

@ -68,7 +68,7 @@ class Base32 {
}
class Program {
void main() {
public void main() {
var_dump(Base32::encode('Test String'), Base32::encode('DS27DEC985'), Base32::encode('AerScript rocks!'));
var_dump(Base32::decode('KRSXG5BAKN2HE2LOM4======'), Base32::decode('IRJTEN2EIVBTSOBV'), Base32::decode('IFSXEU3DOJUXA5BAOJXWG23TEE======'));
}

+ 1
- 1
tests/bin_format.aer View File

@ -11,7 +11,7 @@ class Program {
return ltrim($rtnval);
}
void main() {
public void main() {
var_dump($this->fmt_binary(2541));
}
}

+ 1
- 1
tests/brainfuck_interpreter.aer View File

@ -78,7 +78,7 @@ class Brainfuck {
class Program {
void main() {
public void main() {
object $bf;
string $code;
resource $dir;

+ 1
- 1
tests/callback_function.aer View File

@ -1,6 +1,6 @@
class Program {
void main(string[] $args) {
public void main(string[] $args) {
callback $y = void() {
callback $a = 'printf';
$a("I'm alive\n");

+ 1
- 6
tests/center_text.aer View File

@ -15,14 +15,9 @@ class Program {
return $result;
}
void main() {
public void main() {
string $str = 'Example text';
print($this->center_text($str));
}
}
/* Should output
---------------This is some text------------
*/

+ 2
- 2
tests/class_instance_arg.aer View File

@ -7,12 +7,12 @@ class Test2 extends Test1 {
class Program {
object $t;
void test(Test1 $t = new Test2) {
private void test(Test1 $t = new Test2) {
$this->t = $t;
var_dump($this->t);
}
void main() {
public void main() {
$this->test();
}

+ 2
- 2
tests/closure_event.aer View File

@ -13,7 +13,7 @@ class Button {
$this->DoAfterClick();
}
private void DoBeforeClick() {
private void DoBeforeClick() {
if($this->OnBeforeClick) {
callback $event = $this->OnBeforeClick;
$event($this);
@ -31,7 +31,7 @@ class Button {
class Program {
void main() {
public void main() {
object $MyWidget = new Button();
$MyWidget->OnBeforeClick = void(object $Sender) { print($Sender->Name + ' (Before Click)'); };
$MyWidget->OnAfterClick = void(object $Sender) { print($Sender->Name + ' (After Click)'); };

+ 1
- 1
tests/closure_test.aer View File

@ -22,7 +22,7 @@ class Operations {
class Program {
void main() {
public void main() {
callback $fn;
object $op = new Operations();
$fn = $op->ops(6, 7, 'ADD');

+ 1
- 1
tests/complex_expressions.aer View File

@ -24,7 +24,7 @@ class Program {
return false;
}
int main() {
public int main() {
static float $f = 4 + 2.4 * 9.1;
var_dump($this->MY_CONST);
var_dump($this->callback_test);

+ 2
- 2
tests/complex_expressions2.aer View File

@ -1,12 +1,12 @@
class Program {
void test(int $a = (int(int $a, int $b, int $c){return $a+$b+$c;})(14, 10+2, 15), int $b = 0, int $c = 98) {
private void test(int $a = (int(int $a, int $b, int $c){return $a+$b+$c;})(14, 10+2, 15), int $b = 0, int $c = 98) {
print($a + PHP_EOL);
print($b + PHP_EOL);
print($c + PHP_EOL);
}
void main() {
public void main() {
$this->test();
$this->test(512);
$this->test(1024, 32);

+ 2
- 2
tests/constants_access.aer View File

@ -3,12 +3,12 @@ define TEST_CONSTANT 'This is a global constant';
class Program {
const TEST_CONSTANT = 'This is a class constant';
void constant_test() {
private void constant_test() {
const TEST_CONSTANT = 'This is a local constant';
var_dump(TEST_CONSTANT);
}
void main() {
public void main() {
int $var = 69;
var_dump(TEST_CONSTANT);
$this->constant_test();

+ 1
- 1
tests/debug_backtrace.aer View File

@ -1,6 +1,6 @@
class Program {
void main() {
public void main() {
$this->b($this->a('First A'), $this->a('Second A'), $this->a('Third A'));
}

+ 7
- 7
tests/entry_point.aer View File

@ -1,10 +1,10 @@
class Test1 {
void __construct() {
public void __construct() {
print("Test1::__construct() called.\n");
}
void __destruct() {
public void __destruct() {
print("Test1::__destruct() called.\n");
}
@ -12,12 +12,12 @@ class Test1 {
class Test2 extends Test1 {
void __construct() {
public void __construct() {
print("Test2::__construct() called.\n");
$parent->__construct();
}
void __destruct() {
public void __destruct() {
print("Test2::__destruct() called.\n");
$parent->__destruct();
}
@ -27,16 +27,16 @@ class Test2 extends Test1 {
class Program {
object $test;
void __construct() {
public void __construct() {
print("Program::__construct() called.\n");
$this->test = new Test1();
}
void __destruct() {
public void __destruct() {
print("Program::__destruct() called.\n");
}
void main() {
public void main() {
print("Program::main() called.\n");
object $test = new Test2();
}

+ 1
- 1
tests/exception_handler.aer View File

@ -15,7 +15,7 @@ class NewException extends Exception {
class Program {
void main() {
public void main() {
callback $handler = void(Exception $e) {
ExceptionHandler::handleException($e);
};

+ 1
- 1
tests/extended_closure.aer View File

@ -16,7 +16,7 @@ class Dog {
class Program {
void main() {
public void main() {
object $dog = new Dog('Alex', 'red');
callback $c = $dog->greet('Hello');
$c();

+ 2
- 2
tests/factorial_test.aer View File

@ -1,13 +1,13 @@
class Program {
int factorial(int $num) {
private int factorial(int $num) {
if($num == 0 || $num == 1)
return 1;
else
return $num * $this->factorial($num - 1);
}
void main() {
public void main() {
int $num = 7;
print('Factorial of ', $num, ' is ', $this->factorial($num), '.');
}

+ 3
- 3
tests/factory_objects.aer View File

@ -1,11 +1,11 @@
class Circle {
void draw() {
public void draw() {
print("Circle\n");
}
}
class Square {
void draw() {
public void draw() {
print("Square\n");
}
}
@ -21,7 +21,7 @@ class Program {
}
}
void main() {
public void main() {
$this->ShapeFactoryMethod("Circle")->draw();
$this->ShapeFactoryMethod("Square")->draw();
}

+ 6
- 6
tests/goto_statement.aer View File

@ -1,6 +1,6 @@
class Test {
void goto_test1() {
public void goto_test1() {
int $i = 0;
a:
print("Foo $i\n");
@ -12,7 +12,7 @@ class Test {
print("Bar $i\n\n");
}
void goto_test2(int $a = 2) {
public void goto_test2(int $a = 2) {
switch($a) {
case 1:
print("\$a is 1\n\n");
@ -30,7 +30,7 @@ class Test {
out:
}
void goto_test3() {
public void goto_test3() {
int $a = 10;
a:
$a--;
@ -41,7 +41,7 @@ class Test {
print("\n");
}
void goto_test4() {
public void goto_test4() {
string[] $headers = {'subject', 'bcc', 'to', 'cc', 'date', 'sender'};
int $pos = 0;
int $c;
@ -67,11 +67,11 @@ class Test {
class Program {
private object $test;
void __construct() {
public void __construct() {
$this->test = new Test();
}
void main() {
public void main() {
$this->test->goto_test1();
$this->test->goto_test2();
$this->test->goto_test3();

+ 3
- 3
tests/int2alpha_test.aer View File

@ -1,6 +1,6 @@
class Program {
string num2alpha(int $n) {
private string num2alpha(int $n) {
string $r = '';
for(int $i = 1; $n >= 0 && $i < 10; $i++) {
$r = chr(0x41 + ($n % pow(26, $i) / pow(26, $i - 1))) + $r;
@ -9,7 +9,7 @@ class Program {
return $r;
}
int alpha2num(string $a) {
private int alpha2num(string $a) {
int $r = 0;
int $l = strlen($a);
for(int $i = 0; $i < $l; $i++) {
@ -18,7 +18,7 @@ class Program {
return (int) $r - 1;
}
void main() {
public void main() {
import('math');
var_dump($this->alpha2num("Salut"), $this->num2alpha(1723), $this->num2alpha(9854), $this->alpha2num("Base64"));
}

+ 1
- 1
tests/ip_addr_enc_dec.aer View File

@ -10,7 +10,7 @@ class Program {
return hexdec($hexipbang[0]) + '.' + hexdec($hexipbang[1]) + '.' + hexdec($hexipbang[2]) + '.' + hexdec($hexipbang[3]);
}
void main() {
public void main() {
string $localhost = $this->encode_ip('127.0.0.1');
print("127.0.0.1 ==> $localhost\n");
string $router = $this->encode_ip('192.168.2.1');

+ 1
- 1
tests/load_module.aer View File

@ -1,5 +1,5 @@
final class Program {
void main() {
public void main() {
var_dump(function_exists('dummy_function'));
var_dump(import('dummy'));
var_dump(function_exists('dummy_function'));

+ 1
- 1
tests/loop_foreach_test.aer View File

@ -1,6 +1,6 @@
class Program {
void main() {
public void main() {
int[] $numbers = {'five' => 5, 'six' => 6, 'seven' => 7, 'eight' => 8, 'nine' => 9, 'zero' => 0};
string[] $days = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
foreach(string $key => int $numeric in $numbers) {

+ 4
- 4
tests/luhn_verify.aer View File

@ -1,15 +1,15 @@
class Luhn {
private string $number;
string getNumber() {
public string getNumber() {
return $this->number;
}
void setNumber(string $number) {
public void setNumber(string $number) {
$this->number = $number;
}
bool validate() {
public bool validate() {
string $sum;
string $revNumber;
int $len;
@ -26,7 +26,7 @@ class Luhn {
class Program {
private const NUMBERS = {'3788803280', '6487308345', '5443489710530865', '5539266155200609', '4024007151066296', '4345234978'};
void main() {
public void main() {
int $i, $nums = sizeof($this->NUMBERS);
object $luhn = new Luhn();

+ 2
- 2
tests/magic_method.aer View File

@ -1,6 +1,6 @@
class Dog {
void __invoke() {
public void __invoke() {
print("I am a dog!\n");
}
}
@ -8,7 +8,7 @@ class Dog {
class Program {
void main() {
public void main() {
object $dog = new Dog();
$dog();
}

+ 1
- 1
tests/multiple_inheritance.aer View File

@ -53,7 +53,7 @@ class TestE {
class Program extends TestE, TestD, TestC, TestB, TestA implements IntA, IntB {
void main() {
public void main() {
$this->test_a();
$this->test_b();
$this->test_c();

+ 1
- 1
tests/operators_precedence.aer View File

@ -8,7 +8,7 @@ class Program {
return {'callme' => void() { print("Hello world\n"); }};
}
void main() {
public void main() {
callback[] $constr = {'print'};
print($this->testArray()['Machine'] + "\n");
$this->testCallback()['callme']();

+ 3
- 3
tests/overloading_constructor.aer View File

@ -1,16 +1,16 @@
class Test {
void __construct(string $a) {
public void __construct(string $a) {
print("$a\n");
}
void __construct(int $a, int $b) {
public void __construct(int $a, int $b) {
print("$a + $b = ", $a + $b, "\n");
}
}
class Program {
void main() {
public void main() {
object $a, $b;
$a = new Test('Hello world!');
$b = new Test(4, 7);

+ 3
- 3
tests/overloading_methods.aer View File

@ -1,14 +1,14 @@
class Program {
void count(int $a, int $b) {
public void count(int $a, int $b) {
print("Counting 2 integers: $a + $b = ", $a + $b, "\n");
}
void count(float $a, float $b) {
public void count(float $a, float $b) {
print("Counting 2 floats: $a + $b = ", $a + $b, "\n");
}
void main() {
public void main() {
$this->count(4.3, 5.7);
$this->count(6, 4);
}

+ 1
- 1
tests/pascal_triangle.aer View File

@ -8,7 +8,7 @@ class Program {
return $result;
}
void main() {
public void main() {
int $z;
int $y = 5;
for(int $x = 0; $x < $y; $x++) {

+ 1
- 1
tests/path_split.aer View File

@ -18,7 +18,7 @@ class Program {
return $retArray;
}
void main() {
public void main() {
string $path = '/my//stupid//path/to///some/file.php';
print_r($this->parsePathComponents($path));

+ 2
- 2
tests/reference_test.aer View File

@ -1,10 +1,10 @@
class Program {
void add_by_ref(int &$val) {
private void add_by_ref(int &$val) {
$val += 7;
}
void main() {
public void main() {
int $num = 7;
$this->add_by_ref($num);
var_dump($num);

+ 2
- 2
tests/static_var.aer View File

@ -1,6 +1,6 @@
class Program {
string cycle(char $a, char $b, int $i = 0) {
private string cycle(char $a, char $b, int $i = 0) {
static bool[] $switches;
if($switches[$i])
$switches[$i] = !$switches[$i];
@ -9,7 +9,7 @@ class Program {
return ($switches[$i]) ? $a : $b;
}
void main() {
public void main() {
for(int $i = 1; $i < 3; $i++) {
print($i + $this->cycle('a', 'b') + PHP_EOL);
for(int $j = 1; $j < 5; $j++) {

+ 1
- 1
tests/switch_block.aer View File

@ -1,6 +1,6 @@
class Program {
void main() {
public void main() {
int $a = 1;
switch($a) {
case 0:

+ 1
- 1
tests/text_normalize.aer View File

@ -14,7 +14,7 @@ class Program {
return strtr($str, $table);
}
void main() {
public void main() {
var_dump($this->normalize("ÿĆ Welcome ÂëÑ Žöø Ŕ"));
}

+ 1
- 1
tests/tokenizer.aer View File

@ -24,7 +24,7 @@ class StringTokenizer {
}
class Program {
void main() {
public void main() {
string $str = "This is:@\t\n a TEST!";
string $delim = " !@:\t\n";
object $st = new StringTokenizer($str, $delim);

+ 1
- 1
tests/type_hinting.aer View File

@ -26,7 +26,7 @@ class Program {
var_dump(is_void($value));
}
void main() {
public void main() {
object $objval;
void $voidval;
$this->testChar('c');

+ 1
- 1
tests/type_juggle.aer View File

@ -1,6 +1,6 @@
class Program {
void main() {
public void main() {
mixed $foo;
$foo = '0';
var_dump($foo);

Loading…
Cancel
Save