Open zxytim opened 11 years ago
int main()
[const]
a: int(5)
line 2:5 mismatched input '[' expecting DEDENT
line 4:1 missing EndOfFile at 'DEDENT'
I see...The main problem is that "const" is a part of type_name not attribute when define variables.
import "iostream"
using namespace std
// define const variable out of class
a, b: const int(10)
// hint: const is not a valid attribute for variable definition
[public]
class Test
// const modifier on type name
const int test(x: const int) = 1
// const attribute means const function, not return type is const
// output: const int get() const;
[const]
const int get() = 1
int main()
// Attribute can be only use out of function body
a: const int(5)
but in SugarCpp-Ftp:
[static, const]
CMD_BUF_LNE := 256
which compiles to
static const decltype(256) CMD_BUF_LNE = 256;
a more test shows that (without static attribute for clearity):
class FtpServer
[const]
CMD_BUF_LNE : int = 256
compiles to
#pragma once
class FtpServer {
const int CMD_BUF_LNE = 256;
};
here it clearly shows that the attribute [const]
in class can be used as part of variable type, but it is not permitted inside a function like:
int main()
[const]
a: int = 5
The two behaviors are not consistent in my view.
The attribute syntax was borrowed from C#, which means extra information that compiler can recognize. Attribute can only be used to modify these things: function/class/enum/variable definition in global scope or class scope/field in class scope. Allow using attribute in function body may reduce the readability of the code. How about keep const attribute in class scope but forbid using it in function body?(currently both forbidden) Since syntax has changed SugarCpp-Ftp maybe have to update.
Are you meant this?