Merge branch 'a12_2_a13'

This commit is contained in:
Basile Burg 2015-02-24 18:39:27 +01:00
commit 145b28cf54
8 changed files with 235 additions and 130 deletions

205
ceast/ceast.d Normal file
View File

@ -0,0 +1,205 @@
module runnable;
import std.path, std.file;
import std.stdio;
import std.d.lexer;
import std.d.ast;
import std.d.parser;
interface I{}
class A
{
class AA
{
class AA1{}
class AA2{}
}
class BB
{
class BB1{}
class BB2{}
}
}
enum SymbolType
{
_alias,
_class, // X
_enum, // X
_function, // X
_interface, // X
_import,
_mixin,
_struct, // X
_template, // X
_union, // X
_variable
}
struct Symbol
{
uint line;
uint col;
string name;
SymbolType type;
Symbol * [] subs;
}
void main(string[] args)
{
if (args.length < 2) return;
auto fname = args[1];
if (!fname.exists) return;
// load and parse the file
auto config = LexerConfig(fname, StringBehavior.source, WhitespaceBehavior.include);
auto source = cast(ubyte[]) read(fname, size_t.max);
auto scache = StringCache(StringCache.defaultBucketCount);
auto ast = parseModule(getTokensForParser(source, config, &scache), fname);
// visit each root member
auto slb = new SymbolListBuilder;
foreach(Declaration decl; ast.declarations)
{
slb.resetRoot;
slb.visit(decl);
}
int level = -1;
void print(Symbol * s)
{
foreach(i; 0..level) write(".");
level++;
write(s.name, '\r');
foreach(ss; s.subs)
print(ss);
level--;
}
print(&slb.root);
writeln();
}
class SymbolListBuilder : ASTVisitor
{
Symbol root;
Symbol * parent;
alias visit = ASTVisitor.visit;
this(){resetRoot;}
void resetRoot(){parent = &root;}
/// returns a new symbol if the declarator is based on a Token named "name".
Symbol * addDeclaration(DT)(DT adt)
{
static if
(
is(DT == const(ClassDeclaration)) ||
is(DT == const(Declarator)) ||
is(DT == const(EnumDeclaration)) ||
is(DT == const(FunctionDeclaration)) ||
is(DT == const(InterfaceDeclaration)) ||
is(DT == const(StructDeclaration)) ||
is(DT == const(TemplateDeclaration)) ||
is(DT == const(UnionDeclaration))
)
{
auto result = new Symbol;
result.name = adt.name.text;
result.line = adt.name.line;
result.col = adt.name.column;
parent.subs ~= result;
return result;
}
assert(0, "addDeclaration no implemented for " ~ DT.stringof);
}
/// visitor implementation if the declarator is based on a Token named "name".
void namedVisitorImpl(DT, SymbolType st, bool dig = true)(const(DT) dt)
{
auto newSymbol = addDeclaration(dt);
newSymbol.type = st;
//
auto previousParent = parent;
parent = newSymbol;
static if (dig) dt.accept(this);
parent = previousParent;
}
final override void visit(const AliasDeclaration aliasDeclaration)
{
// IdentifierList
}
final override void visit(const ClassDeclaration decl)
{
namedVisitorImpl!(ClassDeclaration, SymbolType._class)(decl);
}
final override void visit(const EnumDeclaration decl)
{
namedVisitorImpl!(EnumDeclaration, SymbolType._class)(decl);
}
final override void visit(const FunctionDeclaration decl)
{
namedVisitorImpl!(FunctionDeclaration, SymbolType._function)(decl);
}
final override void visit(const InterfaceDeclaration decl)
{
namedVisitorImpl!(InterfaceDeclaration, SymbolType._interface)(decl);
}
final override void visit(const ImportDeclaration decl)
{
// singlesImp[]
// singleImport.identifierchain.join
import std.array;
foreach(const(SingleImport) si; decl.singleImports)
writeln( si.identifierChain.identifiers[0].text );
}
final override void visit(const MixinDeclaration decl)
{
// identifier
}
final override void visit(const StructDeclaration decl)
{
namedVisitorImpl!(StructDeclaration, SymbolType._struct)(decl);
}
final override void visit(const TemplateDeclaration decl)
{
namedVisitorImpl!(TemplateDeclaration, SymbolType._function)(decl);
}
final override void visit(const UnionDeclaration decl)
{
namedVisitorImpl!(UnionDeclaration, SymbolType._function)(decl);
}
final override void visit(const VariableDeclaration decl)
{
foreach(elem; decl.declarators)
namedVisitorImpl!(Declarator, SymbolType._variable, false)(elem);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 313 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 509 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 888 B

View File

@ -518,8 +518,10 @@ begin
// block comments 1
if fCurrRange.rangeKinds = [] then if readDelim(reader, fTokStop, '/*') then
begin
if readDelim(reader, fTokStop, '*') then fTokKind := tkDDocs
else fTokKind := tkCommt;
fTokKind := tkCommt;
if readDelim(reader, fTokStop, '*') then
if readDelim(reader, fTokStop, '/') then exit
else fTokKind := tkDDocs;
if readUntil(reader, fTokStop, '*/') then
exit;
if fTokKind = tkDDocs then
@ -527,8 +529,7 @@ begin
else
fCurrRange.rangeKinds += [rkBlockCom1];
readLine(reader, fTokStop);
if fkComments1 in fFoldKinds then
StartCodeFoldBlock(nil);
StartCodeFoldBlock(nil, fkComments1 in fFoldKinds);
exit;
end else readerReset;
if (rkBlockCom1 in fCurrRange.rangeKinds) or (rkBlockDoc1 in fCurrRange.rangeKinds) then
@ -538,8 +539,7 @@ begin
if readUntil(reader, fTokStop, '*/') then
begin
fCurrRange.rangeKinds -= [rkBlockDoc1, rkBlockCom1];
if fkComments1 in fFoldKinds then
EndCodeFoldBlock;
EndCodeFoldBlock(fkComments1 in fFoldKinds );
exit;
end;
readLine(reader, fTokStop);
@ -549,19 +549,18 @@ begin
// block comments 2
if fCurrRange.rangeKinds = [] then if readDelim(reader, fTokStop, '/+') then
begin
fTokKind := tkCommt;
if readDelim(reader, fTokStop, '+') then
if readDelim(reader, fTokStop, '/') then exit
else fTokKind := tkDDocs;
if readUntil(reader, fTokStop, '+/') then exit;
inc(fCurrRange.nestedCommentsCount);
if readDelim(reader, fTokStop, '+') then fTokKind := tkDDocs
else fTokKind := tkCommt;
if readUntil(reader, fTokStop, '+/') then
begin
dec(fCurrRange.nestedCommentsCount);
exit;
end;
if fTokKind = tkDDocs then fCurrRange.rangeKinds += [rkBlockDoc2]
else fCurrRange.rangeKinds += [rkBlockCom2];
if fTokKind = tkDDocs then
fCurrRange.rangeKinds += [rkBlockDoc2]
else
fCurrRange.rangeKinds += [rkBlockCom2];
readLine(reader, fTokStop);
if fkComments2 in fFoldKinds then
StartCodeFoldBlock(nil);
StartCodeFoldBlock(nil, fkComments2 in fFoldKinds);
exit;
end else readerReset;
if (rkBlockCom2 in fCurrRange.rangeKinds) or (rkBlockDoc2 in fCurrRange.rangeKinds) then
@ -577,8 +576,7 @@ begin
if fCurrRange.nestedCommentsCount <> 0 then
exit;
fCurrRange.rangeKinds -= [rkBlockDoc2, rkBlockCom2];
if fkComments2 in fFoldKinds then
EndCodeFoldBlock;
EndCodeFoldBlock(fkComments2 in fFoldKinds);
exit;
end;
readLine(reader, fTokStop);
@ -618,8 +616,7 @@ begin
end;
end;
fCurrRange.rangeKinds += [rkString1];
if fkStrings in fFoldKinds then
StartCodeFoldBlock(nil);
StartCodeFoldBlock(nil, fkStrings in fFoldKinds);
exit;
end else _postString1: readerReset;
if rkString1 in fCurrRange.rangeKinds then
@ -640,8 +637,7 @@ begin
fCurrRange.rangeKinds -= [rkString1];
readDelim(reader, fTokStop, stringPostfixes);
fCurrRange.rString := false;
if fkStrings in fFoldKinds then
EndCodeFoldBlock();
EndCodeFoldBlock(fkStrings in fFoldKinds);
exit;
end
else break;
@ -661,8 +657,7 @@ begin
end;
fCurrRange.rangeKinds += [rkString2];
readLine(reader, fTokStop);
if fkStrings in fFoldKinds then
StartCodeFoldBlock(nil);
StartCodeFoldBlock(nil, fkStrings in fFoldKinds);
exit;
end else readerReset;
if rkString2 in fCurrRange.rangeKinds then
@ -671,8 +666,7 @@ begin
if readUntil(reader, fTokStop, '`') then
begin
fCurrRange.rangeKinds -= [rkString2];
if fkStrings in fFoldKinds then
EndCodeFoldBlock();
EndCodeFoldBlock(fkStrings in fFoldKinds);
readDelim(reader, fTokStop, stringPostfixes);
exit;
end;
@ -686,8 +680,7 @@ begin
fTokKind := tkIdent;
inc(fCurrRange.tokenStringBracketsCount);
fCurrRange.rangeKinds += [rkTokString];
if (fkBrackets in fFoldKinds) then
StartCodeFoldBlock(nil);
StartCodeFoldBlock(nil, fkBrackets in fFoldKinds);
exit;
end else readerReset;
@ -712,21 +705,6 @@ begin
exit;
end else readerReset;
// hex litterals
{if readDelim(reader, fTokStop, '0x') then
begin
readWhile(reader, fTokStop, hexaChars);
if not tryReadDelim(reader, fTokStop, 'Lu') then
if not tryReadDelim(reader, fTokStop, 'LU') then
if not tryReadDelim(reader, fTokStop, 'uL') then
if not tryReadDelim(reader, fTokStop, 'UL') then
if not tryReadDelim(reader, fTokStop, 'L') then
if not tryReadDelim(reader, fTokStop, 'u') then
tryReadDelim(reader, fTokStop, 'U');
fTokKind := tkNumbr;
exit;
end else readerReset;}
// numbers 1
if (isNumber(reader^)) then
begin
@ -740,11 +718,10 @@ begin
begin
fTokKind := tkSymbl;
case reader^ of
'{': if (fkBrackets in fFoldKinds) then StartCodeFoldBlock(nil);
'{': StartCodeFoldBlock(nil,fkBrackets in fFoldKinds);
'}':
begin
if (fkBrackets in fFoldKinds) then
EndCodeFoldBlock;
EndCodeFoldBlock(fkBrackets in fFoldKinds);
if (reader^ = '}') and (rkAsm in fCurrRange.rangeKinds) then
fCurrRange.rangeKinds -= [rkAsm]; ;
if (rkTokString in fCurrRange.rangeKinds) then

View File

@ -44,13 +44,6 @@ begin
DragThresholdTrackBar.OnChange := @doChanged;
SplitterWidthTrackBar.OnChange := @doChanged;
//
FlattenHeaders.OnChange := @doChanged;
FilledHeaders.OnChange := @doChanged;
HideHeaderCaptionForFloatingCheckBox.OnChange := @doChanged;
ScaleOnResizeCheckBox.OnChange := @doChanged;
ShowHeaderCaptionCheckBox.OnChange := @doChanged;
ShowHeaderCheckBox.OnChange := @doChanged;
//
HeaderStyleComboBox.OnChange:= @doChanged;
//
EntitiesConnector.addObserver(self);
@ -109,7 +102,11 @@ begin
' ('+IntToStr(HeaderAlignLeftTrackBar.Position) +')';
SplitterWidthLabel.Caption:=adrsSplitterWidth +
' ('+IntToStr(SplitterWidthTrackBar.Position) +')';
ShowHeaderCheckBox.Visible:=adofShow_ShowHeader in Flags;
FlattenHeaders.Enabled := adofShow_ShowHeader in Flags;
FilledHeaders.Enabled := adofShow_ShowHeader in Flags;
ShowHeaderCaptionCheckBox.Enabled := adofShow_ShowHeader in Flags;
HideHeaderCaptionForFloatingCheckBox.Enabled := adofShow_ShowHeader in Flags;
//
SaveToMaster;
end;

View File

@ -1316,80 +1316,6 @@ LazarusResources.Add('keyboard_pencil','PNG',[
+#140#227'2'#217#189'['#210'K'#229'8v'#158#165#236#7#170'&'#25#255'u'#127#254
+#8'0'#0#204#231'b U<'#159'Q'#0#0#0#0'IEND'#174'B`'#130
]);
LazarusResources.Add('link','PNG',[
#137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#16#0#0#0#16#8#6#0#0#0#31#243#255'a'
+#0#0#0#25'tEXtSoftware'#0'Adobe ImageReadyq'#201'e<'#0#0#0#219'IDATx'#218#236
+#147'='#11#131'@'#12#134#147'z'#139#160#127#207'I\'#156#236#164#139#142#226
+#168'88Huq'#17''''#127#156#224#7#8#130#156#189#208#131#182'h;'#184#149'f'#184
+#4#158'7'#31#228#238#144's'#14'g'#236#2''''#237#7#10'0q'#212'u}'#187';'#231
+#141#21#150'e]'#191'q,'#203#146#160'i'#154#176#174'+'#17'EQ'#160'i'#26#18'='
+#196#135#28#211'4'#229#182'mCUU'#4'5M'#3'UUw'#199#157#231#25#166'i'#162'X'
+#230#176'a'#24#160#235':'#16'>'#138'"'#140#227#152'?w'#147'&'#186#230'y'#14
+'A'#16'`'#24#134'\'#230#176#190#239#169#170#240#174#235#242'eY'#192#243#188
+#253#133'1F'#26#17#203#28'1A'#145'e'#153#227#251'>'#232#186'N'#194'q'#28'!I'
+#146#151#29#28'q'#20'O'#217'0'#140#221'-'#183'mK'#183#240#137#227#255'/'#192
+'&'#192#0'd'#173#130';*'#219#202#230#0#0#0#0'IEND'#174'B`'#130
]);
LazarusResources.Add('link_break','PNG',[
#137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#16#0#0#0#16#8#6#0#0#0#31#243#255'a'
+#0#0#0#25'tEXtSoftware'#0'Adobe ImageReadyq'#201'e<'#0#0#1#159'IDATx'#218'|S'
+'=K'#3'A'#16#221'|`'#170#211#24'L'#254#132#141'U~'#128'`'#165'XD'#184'J'#175
+#137#10'w('#4#14#210#134'TB'#4'9,r'#9'zM'#16#145#128#141#4#180#17',l-'#5#127
+#131'J4'#151#131#152'B'#214'7'#155#156#172'k'#238#6'^ff'#223#220#203#236#238
+','#227#156#179'('#244#10#218'~'#28'OH'#178#169']'#23#230'S'#192#3#176#18#174
+'}q'#214#150#248'"pOuL'#178'_'#129#173'W'#255'{'#196#147''''#192#237'E>+D'#16
+#11#14'y'#17'q'#15'8'#166':Y Am'#200'v'#182#180#184#9#231#0#203'So'#3'/'#192
+#238#222#251#199#29'Sm'#214#190'Ns'#217#156#146'/D'#157#129#232#160#211#233
+'4'#161'e*'#218#174'a'#24'V'#28''''#162'V'#171#213#4'x'#16#4'|0'#24#8'PLk$'
+#30#197#209'w'#196#167#177'`'#150#203'e*Tw'#231#210#15'x'#23#220#159#14#168
+#222#243'<Z'#179#210#190#239#179'~'#191#207#200#215#235#245#132#170'b'#219'6'
+#181'j'#133'y'#173'V'#227'a=Y'#26'm'#209#191'0'#242#149'JE'#190#18#215'q'#28
+#11'k'#255#206' '#172#23#2'P'#162'B'#179'Z'#173'2M'#211#196'b&'#147'a'#200'E'
+#139#224#205'F'#163#193#198#227#177#224#134#195'!'#163'<'#220#162#184#5']'
+#215'g'#158't'#183#219#181#226#184#200'9'#192#27#152'S'#242'|'#236#28#200#134
+'Y_'#133';'#159'N'#226#14'p'#9'<'#3#135#24#227#27#245#144#147'r'#130#153'_'
+#195#188'_'#1#6#138'G'#240'm'#248#0#190'D1'#248#245'H'#1#188#129#212#136''''
+#142#128#210#246#219#231#227#228'1Mn'#21#249#19#226#13#224#128#234'd'#129#31
+#1#6#0'aG}'#171'6'#210#147','#0#0#0#0'IEND'#174'B`'#130
]);
LazarusResources.Add('link_edit','PNG',[
#137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#16#0#0#0#16#8#6#0#0#0#31#243#255'a'
+#0#0#0#25'tEXtSoftware'#0'Adobe ImageReadyq'#201'e<'#0#0#3#26'IDATx'#218'tSk'
+'H'#147'Q'#24'~'#190#207'ML*'#11#18'+D"'#10'3'#132#138'}?'#164'{'#127#162#155
+#253'h'#20#130#150#154#152'J'#146#149'n'#22#152#174'"/'#133'E'#133'SkVPj'#23
+#167'e'#22#210#159#138'R\sl'#179'$'#164#203'*'#203'K'#173#173#230#182#218#229
+#219#233#156'Uc'#9'}'#240'r8'#223#251'>'#207'y'#158#247#188#135#211#233#251
+#241#191#143#227'8H$'#18'X,'#22#181#201'd. '#129#0#252#162#136#164'E'#139#26
+#204#3#3#5'<'#207'C'#242#183#152#16#18#4'L&'#224'y'#174'U'#167#211#167')'#21
+#197#24#25#25#133#205'nC{'#199#237'|J'#194#242#5'!'#2#198#22#17#17#17'\'#195
+#8#234#155#155'['#210'*'#202#203'p'#162#178#6'D'#244'V'#219#29#206'C'#169#169
+#169#184#223#213#149'O'#235#127#19#176#147#24#184#173'M'#27#148#204'1'#18#170
+'H'#20#197#252'R'#165#2#149#213'''Qu'#226#152'@K?'#212#214#214#206#244'x<y>'
+#209#15#194','#254#235'W'#202'$'#131'i`'#201#0']GG'#199#224#243'zQP'#184#175
+#223#229'trz'#163')/6>'#30'.'#175#27#18'"'#5#199#154#200#192'R'#169#20#29#29
+'w'#168#18#30'"mV'#128'6'#139'* '#30#10'>^q'#4#153#217'9'#136#138#158#130#245
+#155'6b'#213#135#4#136'\'#0'^'#135#157#11'Y'#248#219'H'#22'L~'#128#146'P'#2
+#28'W'#149'#cW62'#179#178#224't'#186#240#230#237'+'#172'K^'#142#177#225'qD}'
+#247#17#158'yg'#4'4'#212#129#128'H'#252'~?a'''#179#181#226'H'#25'vf'#237#193
+#167#177'/'#208'vv'#227#181'e'#24#185'9{pe'#168#5#246#143'6'#248#172#227#192
+'-m;'#204#207'_'#180'*'#148#135#136#245#171#141#12#14#190'$'#138#210#195#196
+#237'v'#147'm;'#210#169#28#200'X'#152'UK'#200#196#219'N'#162#170'9G'#186#31
+'>&'#251#202'J'#131'9'#238#206#221#174#182#158#158'^yI'#241'~'#168#235'/'#128
+#2#177'n'#237#26'h'#154'.cx'#228'3'#174'nqp'#14#143#132#8#155'b'#128#247#175
+'0'#20#185#27#141'}>'#156#169':*'#24#247'6'#25'x'#221'3'#189'\'#169'(A'#157
+#186#17#170#242'2'#193#225#152'@'#211#165'+H'#167#190#23'$'#11'pyx"l'#158'I/'
+'p'#20'p'#184#240#236#129'6'#8'.V'#149#27'h'#247#192#179'n'#179#9#251#233'v'
+#214'4_'#187'fhP'#159#23'f'#207#141#135'}'#194#7'E'#236'=,'#219'0'#13'x7L'
+#193'_'#161'1-'#196#174':'#163#160#172#168'2'#132#6#208'K'#175#201'j'#179'B'
+#18#25'EM'#145#146#194#162#131#253#137'I'#201#200#156'q'#22'K'#11#179#129'i'
+#171#129'o'#227#208#24#231'#'#247#252'S'#225#230#1#193#128#176#137#231'e2'
+#153#246'z'#235#13#164#164#164' zj'#204#169#149'+W'#161#175#183#7'7'#204'q'
+#232'~'#228#162'*c'#254#128#159#8'-'#197#203#13#147#158'K'#144'+'#225#162#230
+#242'i'#157#174'O'#206'~'#248#253'"f'#197#205#233#140'v'#14'm'#141#244'9'#177
+'}q'#20#18#139#218#133#230#131'+'#12'<G'#232#244'y'#161#159'.'#135#136#31#200
+#248'2/$&'#129'Fl'#24#177#149#198#172#176#189#225#127'O'#254#151#0#3#0'w'#203
+'w'#181#149#171'TX'#0#0#0#0'IEND'#174'B`'#130
]);
LazarusResources.Add('package_add','PNG',[
#137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#16#0#0#0#16#8#6#0#0#0#31#243#255'a'
+#0#0#0#4'gAMA'#0#0#175#200'7'#5#138#233#0#0#0#25'tEXtSoftware'#0'Adobe Image'

View File

@ -8,7 +8,7 @@ uses
Classes, SysUtils, FileUtil, ListFilterEdit, Forms, Controls,
strutils, Graphics, Dialogs, ExtCtrls, Menus, Buttons, ComCtrls,
ce_widget, process, ce_common, ce_interfaces, ce_synmemo,
ce_project, ce_symstring, ce_writableComponent, ce_observer, EditBtn;
ce_project, ce_symstring, ce_writableComponent, ce_observer;
type