?

Log in

No account? Create an account
Yay for "strong-typing" - brad's life — LiveJournal [entries|archive|friends|userinfo]
Brad Fitzpatrick

[ website | bradfitz.com ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Yay for "strong-typing" [Dec. 2nd, 2000|11:20 pm]
Brad Fitzpatrick

Type *type = ste->type();
if (type->isArray()) {
  ArrayType *atype = (ArrayType *) type;
  Type *child_type;
  child_type = atype->childType();
  while (child_type->isArray()) {
    ArrayType *a_child_type = (ArrayType*) child_type;
	child_type = a_child_type->childType();
  }
  return child_type;
}
hahah.
LinkReply

Comments:
[User Picture]From: patrick
2000-12-02 11:21 pm (UTC)
that's some repetative code you got there.
(Reply) (Thread)
[User Picture]From: shortypoke
2000-12-02 11:27 pm (UTC)
dude, i don't even know WHAT'S going on there..
(Reply) (Thread)
[User Picture]From: visions
2000-12-03 12:43 am (UTC)
its simply taking a "node" and checking its type, if it is an array, it checks the type of the "child" of the "node" and then continues to do this down the tree...

finally, it returns the last found type (ie the type of the last child that is not an array).

i assume the data structure is a simple linked list type approach... a one-branch tree or something similar.

(Reply) (Parent) (Thread)
[User Picture]From: visions
2000-12-03 12:44 am (UTC)
err, the last child that does not have a child that is an array rather.
(Reply) (Parent) (Thread)
[User Picture]From: bradfitz
2000-12-03 12:45 am (UTC)

Re:

got first part right

the data structure is not a list though
(Reply) (Parent) (Thread)
[User Picture]From: visions
2000-12-03 12:47 am (UTC)
hmm

root
\
child1
/
child2


i pictured something like that... a maximum of one branch on each node.. hence a one-branch tree or equivalently.. a linked list.
(Reply) (Parent) (Thread)
[User Picture]From: bradfitz
2000-12-03 12:50 am (UTC)

i guess.

from what code you can see, i guess you could infer that, but there's a ton more.... the entire syntax and type information is stored in this one data structure.

this wasn't the point of the post, though. :-)
(Reply) (Parent) (Thread)
[User Picture]From: visions
2000-12-03 12:52 am (UTC)

Re: i guess.

so it is similar to the data-structure that i used for the dynamic menu stuff that was recieved from the server, prior to the menu being created?
(Reply) (Parent) (Thread)
[User Picture]From: bradfitz
2000-12-03 12:53 am (UTC)

Re: i guess.

you used pointers too!?!?!?

:-)
(Reply) (Parent) (Thread)
[User Picture]From: visions
2000-12-03 12:59 am (UTC)

Re: i guess.

hahha. no, but i stored the "nodes" elemental information in the structure and then later parse it according to that elemental information.

the same idea as what you are doing... just for a different purpose.

as an aside, i assume that is c/c++... and part of your compiler project?
(Reply) (Parent) (Thread)
[User Picture]From: bradfitz
2000-12-03 01:03 am (UTC)

Re: i guess.

At first glance it could be one of three languages.

There's two clues in there that indicated precisely what language it is.

Trivia: can you find them? :-)
(Reply) (Parent) (Thread)
[User Picture]From: visions
2000-12-03 01:13 am (UTC)

Re: i guess.

pointers are present and use an * as the indirection character.. so that gives you c, c++ and it leaves out perl and java...

it is obviously not lisp, scheme, apl, ml, etc etc... and is not any functional language.

there isnt any dynamic delcaration, so you cant differentiate between c or c++ easily... however, you do declare variables in the body of the code (block scope) instead of the top (functional scope)... so that rules out c.

my guess is obviously c++.

did i get them all?
(Reply) (Parent) (Thread)
[User Picture]From: bradfitz
2000-12-03 01:15 am (UTC)

Re: i guess.

Yup.

Your medal will be FedEx'ed tomorrow morning. :)
(Reply) (Parent) (Thread)
[User Picture]From: visions
2000-12-03 01:18 am (UTC)

Re: i guess.

woohoo. can i have a tracking number? :)

i failed to mention another one that points out that it is c/c++ when combined with pointers.. and that is the use of an "->" (arrow) for automatic dereferencing.

combine that with * for indirection... and you have c, c++, and nothing else that i can think of.
(Reply) (Parent) (Thread)
[User Picture]From: shortypoke
2000-12-03 11:30 am (UTC)

Re:

i'll throw up all over the node
(Reply) (Parent) (Thread)
[User Picture]From: nighthawk
2000-12-02 11:35 pm (UTC)

Dude

That's what we call "spaghetti code".
(Reply) (Thread)
[User Picture]From: bradfitz
2000-12-03 12:05 am (UTC)

Re: Dude

heh.

yea'.

gets the job done, though. :-)
(Reply) (Parent) (Thread)
[User Picture]From: revjim
2000-12-03 02:06 am (UTC)
Wait wait... let me guess.

You stopped doing crack, and this is the result?
(Reply) (Thread)
[User Picture]From: mart
2000-12-03 04:20 am (UTC)

Strong typing you say?

That's not strong typing: This is strong typing.

(either that, or its a terribly bad joke)
(Reply) (Thread)
[User Picture]From: bradfitz
2000-12-03 04:22 am (UTC)

Re: Strong typing you say?

hahah
(Reply) (Parent) (Thread)