📄 upascalconsts.pas
字号:
faOverload, //is overloaded
faVirtual, //is virtual (or dynamic)
faAbstract, //is abstract
faOverride, //overrides an inherited function
faExternal, //is external implemented
faMessage, //has a message id
faInvalidAttribute); //an invalid attribute (at the moment unused)
//attributes of functions
TFunctionAttributes = set of TFunctionAttribute;
//the different attributes that can be defined for a property
TPropertyAttribute = (
paAdd, //set-like access to the property with include
paDefault, //the default value for the property
paDispID, //the id for a call by dispatch
paImplements, //this property implements an implemented interface
paIndex, //index for indexed access-functions
paNoDefault, //the property has no default value
paRead, //the read field for the property
paReadOnly, //property can only be read
paRemove, //set-like access to the property with exclude
paStored, //constant or identifier, if it should be stored
paWrite, //the write field for the property
paWriteOnly); //property can only be written
//the words for the different attributes defined by ~[link
//TPropertyAttribute] in alphabetic order
const PropertyWords: array[TPropertyAttribute] of String =
('add', 'default', 'dispid', 'implements', 'index',
'nodefault', 'read', 'readonly', 'remove', 'stored',
'write', 'writeonly');
//the attributes only valid in dispatch interfaces
OnlyDispInterfacePropertyWords = [paDispID, paReadOnly, paWriteOnly];
//the attributes without a following value
NoValuePropertyWords = [paNoDefault, paReadOnly, paWriteOnly];
//the different kinds of members of classes
//~see UExtIdents.MemberKindClasses for the internal classes
type TMemberKind = (
mkField, //fields
mkProperty, //properties
mkMethod); //method
//a set of different kinds of members of classes
TMemberKinds = set of TMemberKind;
//the pascal dialect to be parsed
TPascalDialect = (
//Delphi code
pdDelphi,
//FreePascal code in Delphi-mode
pdFreePascal);
//the compiler options usable for conditional compiling
type TCompilerOptions = array['A'..'Z'] of Boolean;
//the default values for the compiler-switches
//~[preformatted
//default: ABCDEFGHIJKLMNOPQRSTUVWXYZ
// +-++--++++-+-+++-----+-++-
// ?? ? ? ? ]
const DefaultCompilerOptions: TCompilerOptions =
(True, False, True, True, False, False, True, True, True, True,
False, True, False, True, True, True, False, False, False, False,
False, True, False, True, True, False);
//+- : A, C, B, D, X, G, I, L, H, Z, P, O, Q, R, Y, U, W, T, M, V, J, Y, Z, Z, Z
//ONFF: ALIGN, ASSERTIONS, BOOLEVAL, DEBUGINFO, EXTENDEDSYNTAX, IMPORTEDDATA, IOCHECKS, LOCALSYMBOLS, LONGSTRINGS, MINENUMSIZE, OPENSTRINGS, OPTIMIZATION, OVERFLOWCHECKS, RANGECHECKS, REFERENCEINFO, SAFEDIVIDE, STACKFRAMES, TYPEDADDRESS, TYPEINFO, VARSTRINGCHECKS, WRITEABLECONST, YD, Z1, Z2, Z3
//alphabetical list of long names of the compiler switches
//mapped to the short names by ~[link ShortCompilerOptions]
LongCompilerOptions: array[0..28] of String =
('a1', 'a2', 'a4', 'a8', 'align',
'assertions', 'booleval', 'debuginfo', 'extendedsyntax', 'importeddata',
'iochecks', 'localsymbols', 'longstrings', 'minenumsize', 'openstrings',
'optimization', 'overflowchecks', 'rangechecks', 'referenceinfo', 'safedivide',
'stackframes', 'typedaddress', 'typeinfo', 'varstringchecks', 'writeableconst',
'yd', 'z1', 'z2', 'z3');
//maps the alphabetical list of long names of the compiler switches
//~[link LongCompilerOptions] to the shorter switches
ShortCompilerOptions: array[low(LongCompilerOptions)..
high(LongCompilerOptions)] of Char =
('A', 'A', 'A', 'A', 'A',
'C', 'B', 'D', 'X', 'G',
'I', 'L', 'H', 'Z', 'P',
'O', 'Q', 'R', 'Y', 'U',
'W', 'T', 'M', 'V', 'J',
'Y', 'Z', 'Z', 'Z');
{ * * * *** * * * *** TPosition *** * * * *** * * * }
type
{Defines a position in a pascal file.}
TPosition = record
Row: Integer; //the row in the file (0-based)
Column: Integer; //the column in the file (1-based)
end;
//pointer to a position in a pascal file
PPosition = ^TPosition;
//an undefined position (Row < 0)
const UndefPosition: TPosition = (Row: -1; Column: 1);
//returns a position-object with that position
function MakePosition(Row, Column: Integer): TPosition;
//Checks whether the word is in the list.
function IsWordIn(Word: String; const List: array of String;
out Index: Integer): Boolean;
//Checks whether the string is a valid name for a pascal identifier or file.
function IsValidIdentifierName(const Name: String): Boolean;
implementation
uses SysUtils;
{Returns a position with the position set to the specified position.
~param Row, Column the position to be set
~result the specified position }
function MakePosition(Row, Column: Integer): TPosition;
begin
Result.Row := Row;
Result.Column := Column;
end;
{Checks whether the word is in the list.
~param Word the word to search in the list; it is only searched if it begins
with a letter; for the comparison it is converted to lower case
~param List the alphabetically sorted lower case list of words in which Word
should be searched; only identifiers starting with a letter should
be used, like reserved words
~param Index the index of Word in the list; if not found it is set to -1
~result if the word is in list }
function IsWordIn(Word: String; const List: array of String;
out Index: Integer): Boolean;
var l, h, m :Integer; //low-, high-, middle-indices
cmp :Integer; //result of string-compare
begin
//is word an identifier (that means also possibly a reserved word)?
Result := (Word <> '') and (Word[1] in ['A'..'Z', 'a'..'z']);
if Result then
begin
Word := LowerCase(Word); //convert to lower case
l := Low(List); //search whole list
h := High(List);
repeat
m := (h + l) div 2; //get the index in the middle
//compare word with the item in the middle
cmp := CompareStr(Word, List[m]);
Result := cmp = 0; //word has been found?
if not Result then
if cmp > 0 then //else restrict search to the other half
l := m + 1
else
h := m - 1;
until Result or (l > h); //until word has been found or not
if Result then
Index := m
else
Index := -1;
end
else
Index := -1;
end;
{Checks whether the string is a valid name for a pascal identifier or file.
~param Name the name to check
~result if the string is a valid pascal name }
function IsValidIdentifierName(const Name: String): Boolean;
var i :Integer; //runner through the string
begin
Result := (Name <> '') and (Name[1] in StartIdentifierChars); //valid start?
if Result then
begin
i := 2; //following characters also valid?
while (i <= length(Name)) and (Name[i] in IdentifierChars) do
inc(i);
Result := i > length(Name); //return if all characters are valid
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -